Browse Source

cleanup

rlbr-dev
Larry Xue 5 years ago
parent
commit
be8852dd7f
  1. 0
      LICENSE
  2. 3
      README.md
  3. 2
      c2logic/__init__.py
  4. 2
      c2logic/__main__.py
  5. 5
      c2logic/compiler.py
  6. 2
      c2logic/instructions.py
  7. 2
      examples/control_flow.c
  8. 2
      examples/dead_code.c
  9. 2
      examples/drawing.c
  10. 2
      examples/dump_mem.c
  11. 2
      examples/factorial.c
  12. 2
      examples/funcs.c
  13. 2
      examples/funcs2.c
  14. 2
      examples/goto.c
  15. 2
      examples/nested_loops.c
  16. 3
      include/io.h
  17. 2
      mypy.ini
  18. 2
      requirements.txt
  19. 2
      setup.py

0
LICENSE

3
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

2
c2logic/__init__.py

@ -1 +1 @@
from .compiler import Compiler
from .compiler import Compiler

2
c2logic/__main__.py

@ -1,2 +1,2 @@
from .compiler import main
main()
main()

5
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()

2
c2logic/instructions.py

@ -195,4 +195,4 @@ class RawAsm(Instruction):
self.code = code
def __str__(self):
return self.code
return self.code

2
examples/control_flow.c

@ -33,4 +33,4 @@ void main(void) {
}
print("\n");
printflush(message1);
}
}

2
examples/dead_code.c

@ -22,4 +22,4 @@ void d(void) {
}
void main(void) {
d();
}
}

2
examples/drawing.c

@ -6,4 +6,4 @@ void main(void) {
drawcolor(0, 128, 128);
drawpoly(40, 40, 3, 10, 180);
drawflush(display1);
}
}

2
examples/dump_mem.c

@ -11,4 +11,4 @@ void main(void) {
print("\n");
}
printflush(message1);
}
}

2
examples/factorial.c

@ -17,4 +17,4 @@ void main(void) {
print("\n");
}
printflush(message1);
}
}

2
examples/funcs.c

@ -12,4 +12,4 @@ void main(void) {
printflush(message1);
enable(conveyor1, x < 10);
shoot(swarmer1, 0, 0, 1);
}
}

2
examples/funcs2.c

@ -8,4 +8,4 @@ void main(void) {
print("\n");
printd(max(x, y) < 10);
printflush(message1);
}
}

2
examples/goto.c

@ -13,4 +13,4 @@ d:
e:
print("end");
printflush(message1);
}
}

2
examples/nested_loops.c

@ -11,4 +11,4 @@ void main(void) {
a(i);
}
printflush(message1);
}
}

3
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
#endif

2
mypy.ini

@ -1,3 +1,3 @@
[mypy]
ignore_missing_imports=True
check_untyped_defs=True
check_untyped_defs=True

2
requirements.txt

@ -1 +1 @@
pycparser~=2.20
pycparser~=2.20

2
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"]
)
)
Loading…
Cancel
Save