diff --git a/LICENSE b/LICENSE index 91e2258..302677a 100755 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 SuperStormer +Copyright (c) 2020 SuperStormer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 74f8239..74c2427 100644 --- a/README.md +++ b/README.md @@ -2,17 +2,25 @@ Compiles C code to Mindustry logic. Still in beta, so compiled output may not be fully optimized. +# Installation + +`pip install git+https://github.com/SuperStormer/c2logic` + # Usage -`python3 -m c2logic filename -O optimization_level` +Run the command line tool using: + +`c2logic filename -O optimization_level` where `filename` is a string and `optimization_level` is an integer. +When developing your script, you can include `c2logic/builtins.h` located in the python include directory(location depends on system, mine is at `~/.local/include/python3.8/`) + See [examples](./examples) for API sample usage. # Documentation -See `include/mindustry.h` for API definitions. +See `include/builtins.h` for API definitions. # Unsupported Features diff --git a/compile_flags.txt b/compile_flags.txt index 8667f37..f8412a6 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -1,4 +1,5 @@ --I ./include +-I/home/larry/.local/include/python3.8/ -Wall -Wextra --Wno-main-return-type \ No newline at end of file +-Wno-main-return-type +-Wno-incompatible-library-redeclaration \ No newline at end of file diff --git a/examples/control_flow.c b/examples/control_flow.c index 3c90892..f445af0 100644 --- a/examples/control_flow.c +++ b/examples/control_flow.c @@ -1,4 +1,4 @@ -#include "../include/mindustry.h" +#include "c2logic/builtins.h" /*expected output: 5678 0246 diff --git a/examples/func_calls.c b/examples/func_calls.c new file mode 100644 index 0000000..f06e5cb --- /dev/null +++ b/examples/func_calls.c @@ -0,0 +1,15 @@ +#include "c2logic/builtins.h" +extern struct MindustryObject message1; +double factorial(int x) { + int ret = 1; + for (int i = 2; i <= x; i++) { + ret *= x; + } + return ret; +} +void main(void) { + printd(factorial(4)); + print("\n"); + printd(factorial(5)); + printflush(message1); +} \ No newline at end of file diff --git a/examples/funcs.c b/examples/funcs.c index 43c3193..9064964 100644 --- a/examples/funcs.c +++ b/examples/funcs.c @@ -1,4 +1,4 @@ -#include "../include/mindustry.h" +#include "c2logic/builtins.h" extern struct MindustryObject message1; extern struct MindustryObject swarmer1; extern struct MindustryObject conveyor1; diff --git a/examples/funcs2.c b/examples/funcs2.c index c1f5f60..12103bd 100644 --- a/examples/funcs2.c +++ b/examples/funcs2.c @@ -1,4 +1,4 @@ -#include "../include/mindustry.h" +#include "c2logic/builtins.h" extern struct MindustryObject message1; void main(void) { double x = rand(20), y = rand(20); diff --git a/include/mindustry.h b/include/builtins.h similarity index 100% rename from include/mindustry.h rename to include/builtins.h diff --git a/setup.py b/setup.py index cd3d3c3..1bf2075 100755 --- a/setup.py +++ b/setup.py @@ -12,6 +12,7 @@ setuptools.setup( author="SuperStormer", url="https://github.com/SuperStormer/c2logic", project_urls={"Source Code": "https://github.com/SuperStormer/c2logic"}, - entry_points={"console_scripts": ["c2logic=c2logic:main"]}, + headers=["include/builtins.h"], + entry_points={"console_scripts": ["c2logic=c2logic.compiler:main"]}, install_requires=["pycparser~=2.20"] ) \ No newline at end of file