Browse Source

added installation

rlbr-dev
Larry Xue 5 years ago
parent
commit
e526c13013
  1. 2
      LICENSE
  2. 12
      README.md
  3. 5
      compile_flags.txt
  4. 2
      examples/control_flow.c
  5. 15
      examples/func_calls.c
  6. 2
      examples/funcs.c
  7. 2
      examples/funcs2.c
  8. 0
      include/builtins.h
  9. 3
      setup.py

2
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

12
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

5
compile_flags.txt

@ -1,4 +1,5 @@
-I ./include
-I/home/larry/.local/include/python3.8/
-Wall
-Wextra
-Wno-main-return-type
-Wno-main-return-type
-Wno-incompatible-library-redeclaration

2
examples/control_flow.c

@ -1,4 +1,4 @@
#include "../include/mindustry.h"
#include "c2logic/builtins.h"
/*expected output:
5678
0246

15
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);
}

2
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;

2
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);

include/mindustry.h → include/builtins.h

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