diff --git a/LICENSE b/LICENSE old mode 100755 new mode 100644 diff --git a/README.md b/README.md index 4d0cae6..1b18c2a 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ See [include/builtins.h](./include/builtins.h) for API definitions and [examples # Supported Features - all Mindustry instructions as of BE 9420 -- all C control flow structures except goto and switch +- all C control flow structures except switch - functions - local/global variables @@ -55,4 +55,3 @@ See [include/builtins.h](./include/builtins.h) for API definitions and [examples - typedefs - use macros - pointers - don't use them - switch - use if-else chains -- goto - don't use it diff --git a/c2logic/__init__.py b/c2logic/__init__.py index 4808a32..b25367d 100644 --- a/c2logic/__init__.py +++ b/c2logic/__init__.py @@ -1 +1 @@ -from .compiler import Compiler \ No newline at end of file +from .compiler import Compiler diff --git a/c2logic/__main__.py b/c2logic/__main__.py index 406d0bd..6861988 100644 --- a/c2logic/__main__.py +++ b/c2logic/__main__.py @@ -1,2 +1,2 @@ from .compiler import main -main() \ No newline at end of file +main() diff --git a/c2logic/compiler.py b/c2logic/compiler.py index aa8ffd5..51a699d 100644 --- a/c2logic/compiler.py +++ b/c2logic/compiler.py @@ -271,6 +271,7 @@ class Compiler(c_ast.NodeVisitor): self.push(Set("__rax", "null")) self.push_ret() self.functions[func_name] = self.curr_function + self.curr_function = None def visit_Decl(self, node): if isinstance(node.type, TypeDecl): # variable declaration @@ -416,8 +417,8 @@ class Compiler(c_ast.NodeVisitor): def visit_Return(self, node): if node.expr is None: - self.push(Set("__rax","null")) - else: + self.push(Set("__rax", "null")) + else: self.visit(node.expr) self.push_ret() diff --git a/c2logic/instructions.py b/c2logic/instructions.py index 7a39531..92ef5d0 100644 --- a/c2logic/instructions.py +++ b/c2logic/instructions.py @@ -195,4 +195,4 @@ class RawAsm(Instruction): self.code = code def __str__(self): - return self.code \ No newline at end of file + return self.code diff --git a/examples/control_flow.c b/examples/control_flow.c index f445af0..a37dddb 100644 --- a/examples/control_flow.c +++ b/examples/control_flow.c @@ -33,4 +33,4 @@ void main(void) { } print("\n"); printflush(message1); -} \ No newline at end of file +} diff --git a/examples/dead_code.c b/examples/dead_code.c index d755364..2d6a6ff 100644 --- a/examples/dead_code.c +++ b/examples/dead_code.c @@ -22,4 +22,4 @@ void d(void) { } void main(void) { d(); -} \ No newline at end of file +} diff --git a/examples/drawing.c b/examples/drawing.c index 0a1c59e..1fcbfa1 100644 --- a/examples/drawing.c +++ b/examples/drawing.c @@ -6,4 +6,4 @@ void main(void) { drawcolor(0, 128, 128); drawpoly(40, 40, 3, 10, 180); drawflush(display1); -} \ No newline at end of file +} diff --git a/examples/dump_mem.c b/examples/dump_mem.c index b121bd2..fdb7116 100644 --- a/examples/dump_mem.c +++ b/examples/dump_mem.c @@ -11,4 +11,4 @@ void main(void) { print("\n"); } printflush(message1); -} \ No newline at end of file +} diff --git a/examples/factorial.c b/examples/factorial.c index 3fd91b2..0b3c8ae 100644 --- a/examples/factorial.c +++ b/examples/factorial.c @@ -17,4 +17,4 @@ void main(void) { print("\n"); } printflush(message1); -} \ No newline at end of file +} diff --git a/examples/funcs.c b/examples/funcs.c index 9064964..7ecb553 100644 --- a/examples/funcs.c +++ b/examples/funcs.c @@ -12,4 +12,4 @@ void main(void) { printflush(message1); enable(conveyor1, x < 10); shoot(swarmer1, 0, 0, 1); -} \ No newline at end of file +} diff --git a/examples/funcs2.c b/examples/funcs2.c index bc07a4f..45e9807 100644 --- a/examples/funcs2.c +++ b/examples/funcs2.c @@ -8,4 +8,4 @@ void main(void) { print("\n"); printd(max(x, y) < 10); printflush(message1); -} \ No newline at end of file +} diff --git a/examples/goto.c b/examples/goto.c index 4830248..980902b 100644 --- a/examples/goto.c +++ b/examples/goto.c @@ -13,4 +13,4 @@ d: e: print("end"); printflush(message1); -} \ No newline at end of file +} diff --git a/examples/nested_loops.c b/examples/nested_loops.c index 31cf6df..9f30b9a 100644 --- a/examples/nested_loops.c +++ b/examples/nested_loops.c @@ -11,4 +11,4 @@ void main(void) { a(i); } printflush(message1); -} \ No newline at end of file +} diff --git a/include/io.h b/include/io.h index 1caa69d..dc7eee9 100644 --- a/include/io.h +++ b/include/io.h @@ -1,5 +1,6 @@ #ifndef IO_H #define IO_H +#include "c2logic/builtins.h" void println(char* s) { print(s); print("\n"); @@ -8,4 +9,4 @@ void printdln(double s) { printd(s); print("\n"); } -#endif \ No newline at end of file +#endif diff --git a/mypy.ini b/mypy.ini old mode 100755 new mode 100644 index 5015e0c..e5497f3 --- a/mypy.ini +++ b/mypy.ini @@ -1,3 +1,3 @@ [mypy] ignore_missing_imports=True -check_untyped_defs=True \ No newline at end of file +check_untyped_defs=True diff --git a/requirements.txt b/requirements.txt index 93a0b18..fee286c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -pycparser~=2.20 \ No newline at end of file +pycparser~=2.20 diff --git a/setup.py b/setup.py index 1bf2075..38776e0 100755 --- a/setup.py +++ b/setup.py @@ -15,4 +15,4 @@ setuptools.setup( headers=["include/builtins.h"], entry_points={"console_scripts": ["c2logic=c2logic.compiler:main"]}, install_requires=["pycparser~=2.20"] -) \ No newline at end of file +)