Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
IngeniariusSoftware committed Aug 1, 2022
1 parent 995b860 commit 267f44e
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 104 deletions.
14 changes: 6 additions & 8 deletions project/scripts/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

<details>
Expand All @@ -30,14 +30,12 @@ All scripts are run from the `project/scripts` folder

Tests are placed in the <code> tests </code> 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 <code> scripts/data/config </code> 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.
</details>
&nbsp;

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)
Expand All @@ -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`
Expand All @@ -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
Expand Down
206 changes: 110 additions & 96 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,41 @@ $ ./c2eo <path-to-c-file-name> <eo-file-name>.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 <your_path_to_the_folder>/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 <your_path_to_the_folder>/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

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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.
Expand Down Expand Up @@ -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-\<type>](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/pre-inc-int64.eo)
x++|[post-inc-\<type>](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/post-inc-int64.eo)
--x|[pre-dec-\<type>](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/pre-dec-int64.eo)
x--|[post-dec-\<type>](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.
Expand Down Expand Up @@ -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-\<type>](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/pre-inc-int64.eo)
x++|[post-inc-\<type>](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/post-inc-int64.eo)
--x|[pre-dec-\<type>](https://github.com/polystat/c2eo/tree/master/result/eo/c2eo/coperators/pre-dec-int64.eo)
x--|[post-dec-\<type>](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
Expand All @@ -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.
Expand Down

0 comments on commit 267f44e

Please sign in to comment.