From 267f44e5377cb3b1e50b72e0cc59bb384fa31d0b Mon Sep 17 00:00:00 2001 From: maksim Date: Mon, 1 Aug 2022 14:50:22 +0500 Subject: [PATCH] update readme --- project/scripts/readme.md | 14 ++- readme.md | 206 ++++++++++++++++++++------------------ 2 files changed, 116 insertions(+), 104 deletions(-) diff --git a/project/scripts/readme.md b/project/scripts/readme.md index f77e21e4..f04faef0 100644 --- a/project/scripts/readme.md +++ b/project/scripts/readme.md @@ -8,19 +8,19 @@ All scripts are run from the `project/scripts` folder 1. Start testing ```bash - # By default, the path "path_to_tests" and the "config" configuration in settings.yml will be taken, you can set other values in settings.yml + # By default, the path "path_to_tests" in settings.yml will be taken, you can set other values in settings.yml $ python3 test.py # You can specify a different path at startup - $ python3 test.py ../tests/nkchuykin + $ python3 test.py -p ../tests/nkchuykin # You can specify a different path and configuration at startup - $ python3 test.py ../tests/nkchuykin without_struct + $ python3 test.py -p ../tests/nkchuykin -s test ```
@@ -30,14 +30,12 @@ All scripts are run from the `project/scripts` folder Tests are placed in the tests directory. Each test, a C file, is in a separate subdirectory. The program file name is the same as the directory name and has the .c extension. During testing, additional data with test information is created in these test directories. - The scripts/data/config directory contains files used for custom testing. Each file contains a list of lines, one of which must contain the path to the file. If you put a! Sign at the beginning of a line, then there should not be a single line from this list in the path to the file. -
  1. Transpilation and assembly of all C-files found in this directory ```bash - $ python3 transpile_c2eo.py ../tests/nchuikin + $ python3 transpile.py -p ../tests/nchuikin ``` 1. Clear all the entire catalog, leaving only C-files (without -o at the end) @@ -50,7 +48,7 @@ All scripts are run from the `project/scripts` folder # You can specify a different path and configuration at startup - $ python3 clean_before_transpilation.py ../tests/nkchuykin + $ python3 clean_before_transpilation.py -p ../tests/nkchuykin ``` 1. Build EO project `../../ result` @@ -69,7 +67,7 @@ All scripts are run from the `project/scripts` folder # You can specify a different path at startup - $ python3 build_c2eo.py ../my_dir/bin + $ python3 build_c2eo.py -p ../my_dir/bin ``` 1. Single-threaded launch of c2eo without formatting the output to the console for all c files diff --git a/readme.md b/readme.md index 6c4e252f..2a40a264 100644 --- a/readme.md +++ b/readme.md @@ -100,23 +100,41 @@ $ ./c2eo .eo # ./c2eo ../some_dir/example.c example.eo ``` -Ok, it works, but you're not going to manually broadcast each file and check if everything is OK. To do this, there are a couple of scripts that will simplify your life: +### Checking before creating PR -```bash -# Transpile and run all c files in folder, then compare their results and show statistics -$ python3 test.py ../tests/main +Your PR will pass the following checks, so before creating PR run these locally to make sure everything is ok: -# Single-threaded launch of c2eo without formatting the output to the console for all c files -$ python3 c2eo-all ../tests/main +1. [clang-format-14](https://pypi.org/project/clang-format/) +```bash +$ clang-format project/src/transpiler/*.(cpp|h) -i +``` -# Show code lines statistics in this dir -$ python3 code_lines.py ../tests/main +2. [cpplint](https://github.com/cpplint/cpplint) +```bash +$ cpplint --filter=-runtime/references,-runtime/string,-build/c++11 project/src/transpiler/** +``` +3. [clang-tidy](https://packages.ubuntu.com/en/bionic/clang-tidy) +```bash +$ cd project/srcipts +$ python3 clang_tidy.py +``` +4. [gcc.c-torture](https://github.com/polystat/c2eo/releases/download/0.1.16/gcc.c-torture.tar.gz) +```bash +$ cd project/srcipts +$ python3 transpile.py /gcc.c-torture -s gcc -n +``` -# Transpile all c files and run EO compiler -$ python3 compile.py ../tests/main +5. [c-testcuite](https://github.com/polystat/c2eo/releases/download/0.1.16/c-testcuite.tar.gz) +```bash +$ cd project/srcipts +$ python3 compile.py -p /c-testcuite -s testcuite ``` -The main tests are in the folder `/project/tests/main`, if they pass, then everything is ok. [Here](./project/scripts/readme.md) you can find more information about scripts. +6. test +```bash +$ cd project/srcipts +$ python3 test.py -s test +``` ## How to release @@ -280,6 +298,7 @@ C is a _system-level procedural_ programming language with direct access to the :heavy_check_mark: [Implemented](#implemented): - [basic data types: double, int, bool](#direct-memory-access-for-basic-data-types) +- [const](#const) - [arrays](#arrays) - [structures](#structures) - [unions](#unions) @@ -294,16 +313,15 @@ C is a _system-level procedural_ programming language with direct access to the - [for](#for) - [break](#break) - [continue](#continue) +- [switch case default](#switch-case-default) - [operators](#operators) :hammer: In progress: - [bit operators (inconsistent implementation in the EO)](#bit-operators) -- [char, unsigned + short + int, float (not supported by EO)](#basic-types) +- [char, float (not supported by EO)](#basic-types) +- [enums](#enums) :x: [Not implemented](#not-implemented): -- [switch case default](#switch-case-default) -- [const](#const) -- [enums](#enums) - [goto and labels](#goto-and-labels) - [calling functions with variable number of arguments](#calling-functions-with-variable-number-of-arguments) - [pointers on function](#pointers-on-function) @@ -325,6 +343,26 @@ ram > global global.write 0 (3.14.as-bytes) ``` +### Const + +We transform const like ordinary variable. + +```c +const int a = 3; +if (a == 10) { + ... +} +``` + +```java +a.write-as-int32 3 // only once +if + a.read-as-int32.eq 10 + seq + ... + True +``` + ### Arrays If we have fixed-size arrays we can work like with one-dimension array and calculate bias from start for any element and dimensions. In this example, we use a special object [address](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/system/address.eo), which makes it more convenient to read and write information from memory from a certain position. @@ -718,74 +756,6 @@ goto TRUE ``` -### Operators - -The table of all C operators and similar objects in the EO. - -С|EO --|- -+|[add](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/add.eo) --|[sub](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/sub.eo) -*|[mul](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/mul.eo) -/|[div](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/div.eo) -=|[write](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/write.eo) -%|[mod](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/mod.eo) -==|[eq](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/eq.eo) -!=|[neq](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/neq.eo) -<|[less](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/less.eo) -<=|[leq](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/leq.eo) -\>|[greater](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/greater.eo) -\>=|[geq](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/geq.eo) -&&|[and](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/and.eo) -\|\||[or](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/or.eo) -!|[not](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/not.eo) --x|[neg](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/neg.eo) -++x|[pre-inc-\](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/pre-inc-int64.eo) -x++|[post-inc-\](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/post-inc-int64.eo) ---x|[pre-dec-\](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/pre-dec-int64.eo) -x--|[post-dec-\](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/post-dec-int64.eo) -(double)|[as-float64](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/as-float64.eo) -(long long int)|[as-int64](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/as-int64.eo) - -```c -x += 10; -``` - -For assignment operations, we generate the following constructs - -```java -x.write (x.add 10) -``` - -### In progress - -### Basic types - -Some types are not yet implemented due to problems with working with bytes in the EO. - -```c -char a = '1'; -short int b = 2; -long int c = 3; -float d = 4.0; -unsigned int e = 5; -``` - -### Bit operators - -Some operators are not yet implemented due to problems with working with bytes in the EO. - -C|EO --|- -&|[bit-and](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/bit-and.eo) -\||[bit-or](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/bit-or.eo) -^|[bit-xor](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/bit-xor.eo) -~|[bit-not](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/bit-not.eo) -<<|[shift-right](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/shift-right.eo) -\>>|[shift-left](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/shift-left.eo) - -### Not implemented - ### Switch case default We can convert such simple switch statement to [goto](https://github.com/objectionary/eo/blob/master/eo-runtime/src/main/eo/org/eolang/gray/goto.eo) object. @@ -859,25 +829,54 @@ switch (x): { TRUE ``` -### Const +### Operators -We will replace all calls to the constant with its value. +The table of all C operators and similar objects in the EO. + +С|EO +-|- ++|[add](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/add.eo) +-|[sub](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/sub.eo) +*|[mul](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/mul.eo) +/|[div](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/div.eo) +=|[write](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/write.eo) +%|[mod](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/mod.eo) +==|[eq](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/eq.eo) +!=|[neq](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/neq.eo) +<|[less](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/less.eo) +<=|[leq](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/leq.eo) +\>|[greater](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/greater.eo) +\>=|[geq](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/geq.eo) +&&|[and](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/and.eo) +\|\||[or](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/or.eo) +!|[not](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/not.eo) +-x|[neg](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/neg.eo) +++x|[pre-inc-\](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/pre-inc-int64.eo) +x++|[post-inc-\](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/post-inc-int64.eo) +--x|[pre-dec-\](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/pre-dec-int64.eo) +x--|[post-dec-\](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/post-dec-int64.eo) +(double)|[as-float64](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/as-float64.eo) +(long long int)|[as-int64](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/as-int64.eo) ```c -const int a = 3; -if (a == 10) { - ... -} +x += 10; ``` +For assignment operations, we generate the following constructs + ```java -if - 3.eq 10 - seq - ... - True - seq - True +x.write (x.add 10) +``` + +### In progress + +### Basic types + +Some types are not yet implemented due to problems with working with bytes in the EO. + +```c +char a = '1'; +float d = 4.0; ``` ### Enums @@ -901,6 +900,21 @@ if True ``` +### Bit operators + +Some operators are not yet implemented due to problems with working with bytes in the EO. + +C|EO +-|- +&|[bit-and](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/bit-and.eo) +\||[bit-or](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/bit-or.eo) +^|[bit-xor](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/bit-xor.eo) +~|[bit-not](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/bit-not.eo) +<<|[shift-right](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/shift-right.eo) +\>>|[shift-left](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/shift-left.eo) + +### Not implemented + ### Goto and labels Current [goto](https://github.com/objectionary/eo/blob/master/eo-runtime/src/main/eo/org/eolang/gray/goto.eo) object can replace continue and break, but goto in C can jump anywhere in function body.