You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.6 KiB

5 years ago
  1. # c2logic
  2. Compiles C code to Mindustry logic. Still in beta, so compiled output may not be fully optimized.
  3. # Installation
  4. `pip install git+https://github.com/SuperStormer/c2logic`
  5. # Documentation
  6. Run the command line tool using:
  7. `c2logic filename -O optimization_level`
  8. where `filename` is a string and `optimization_level` is an optional integer.
  9. Optimization Level:
  10. 0. completely unoptimized.
  11. 1. the default
  12. - modify variables without using a temporary
  13. 2. turns on some potentially unsafe optimizations
  14. - augmented assignment and pre/postincrement/decrement don't modify `__rax`
  15. - returning from main becomes equivalent to `end`
  16. Locals are rewritten as `_<varname>_<func_name>`. Globals are unchanged.
  17. Special Variables:
  18. - `__rax`: similar to x86 rax
  19. - `__rbx`: stores left hand side of binary ops to avoid clobbering by the right side
  20. - `__retaddr__<func_name>`: stores return address of func call
  21. 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/`).
  22. See [include/builtins.h](./include/builtins.h) for API definitions and [examples](./examples) for API sample usage.
  23. # Supported Features
  24. - all Mindustry instructions as of BE
  25. - all control flow structures except goto
  26. - functions
  27. - local/global variables
  28. # Unsupported Features
  29. - structs - split it into multiple variables
  30. - enums - use an int plus macros
  31. - block scoped variables - just use locals
  32. - typedefs - use macros
  33. - pointers - don't use them
  34. - goto - don't use it