From 51bc3410b983d7be7a943aaea658b40c4b7b9d19 Mon Sep 17 00:00:00 2001 From: Larry Xue Date: Tue, 25 Aug 2020 15:27:16 -0400 Subject: [PATCH] fixed windows include path --- README.md | 3 ++- c2logic/compiler.py | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 87393f9..d0869e7 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,8 @@ Special Variables: - `__rbx`: stores left hand side of binary ops to avoid clobbering by the right side - `__retaddr__`: stores return address of func call -When writing your code, you must include `c2logic/builtins.h`, which is located in the python include directory (location depends on system, mine is at `~/.local/include/python3.8/`). A quick way to find this is `python3 -c 'import sysconfig, os; print(sysconfig.get_path("include",f"{os.name}_user"))'`. +When writing your code, you must include `c2logic/builtins.h`, which is located in the python include directory (location depends on system, mine is at `~/.local/include/python3.8/`). +A quick way to find this is `python3 -c "from c2logic.compiler import get_include_path; print(get_include_path())"` (use `python` if you are using windows). See [include/builtins.h](./include/builtins.h) for API definitions and [examples](./examples) for API sample usage. diff --git a/c2logic/compiler.py b/c2logic/compiler.py index 7bfa9c6..a7bdb87 100644 --- a/c2logic/compiler.py +++ b/c2logic/compiler.py @@ -58,7 +58,7 @@ class Compiler(c_ast.NodeVisitor): ast = parse_file( filename, use_cpp=True, - cpp_args=["-I", sysconfig.get_path("include", f"{os.name}_user")] + cpp_args=["-I", get_include_path()] ) self.visit(ast) @@ -431,6 +431,14 @@ class Compiler(c_ast.NodeVisitor): else: raise NotImplementedError(node) +def get_include_path(): + if os.name == "posix": + return sysconfig.get_path("include", "posix_user") + elif os.name == "nt": + return sysconfig.get_path("include", "nt") + else: + raise ValueError(f"Unknown os {os.name}") + def main(): import argparse parser = argparse.ArgumentParser()