Improve and correct IO UI and add tests

This commit is contained in:
Benjamin Loison 2023-01-03 19:43:24 +01:00
parent ff9da14379
commit 5cabb042fc
11 changed files with 64 additions and 14 deletions

5
TODO
View File

@ -1,8 +1,5 @@
# Parseur # Parseur
- tests divers et variés - ajustement des automates
- support pour un point-virgule optionel en fin de nœud
- ajout des flottants (= réels)
- ajout de pre, ->, fby, automates
# ... # ...

View File

@ -362,7 +362,7 @@ let cp_main_fn fmt (prog, sts) =
else Format.fprintf fmt "%s%a") else Format.fprintf fmt "%s%a")
(match h with (match h with
| IVar _ -> "%d" | IVar _ -> "%d"
| BVar _ -> "%c" | BVar _ -> "%hd"
| RVar _ -> "%lf") | RVar _ -> "%lf")
cp_scanf_str (true, t) cp_scanf_str (true, t)
in in
@ -389,7 +389,7 @@ let cp_main_fn fmt (prog, sts) =
else Format.fprintf fmt "%s%a") else Format.fprintf fmt "%s%a")
(match h with (match h with
| IVar _ -> "%d" | IVar _ -> "%d"
| BVar _ -> "%c" | BVar _ -> "%hd"
| RVar _ -> "%f") | RVar _ -> "%f")
cp_printf_str (true, t) cp_printf_str (true, t)
in in
@ -424,13 +424,15 @@ let cp_main_fn fmt (prog, sts) =
| Some node -> | Some node ->
Format.fprintf fmt "int main (int argc, char **argv)\n\ Format.fprintf fmt "int main (int argc, char **argv)\n\
{\n%a\n\ {\n%a\n\
\tchar _buffer[1024];\n\ \t#define BUFFER_SIZE 1024\n\
\tchar _buffer[BUFFER_SIZE];\n\
\tt_state_main state;\n\ \tt_state_main state;\n\
\tstate.is_init = true;\n\ \tstate.is_init = true;\n\
\tstate.is_reset = false;\n\ \tstate.is_reset = false;\n\
\twhile(true) {\n\ \twhile(true) {\n\
\t\tfor(int idx = 0; idx < 1024; idx++) {\n\ \t\tprintf(\"input: \");\n\
\t\t\tif(idx == 1023 || (_buffer[idx] = getchar()) == '\\n') {\n\ \t\tfor(unsigned short idx = 0; idx < BUFFER_SIZE; idx++) {\n\
\t\t\tif(idx == (BUFFER_SIZE - 1) || (_buffer[idx] = getchar()) == '\\n') {\n\
\t\t\t\t_buffer[idx] = '\\0';\n\ \t\t\t\t_buffer[idx] = '\\0';\n\
\t\t\t\tbreak;\n\ \t\t\t\tbreak;\n\
\t\t\t}\n\ \t\t\t}\n\
@ -438,7 +440,9 @@ let cp_main_fn fmt (prog, sts) =
\t\tif(!strcmp(_buffer, \"exit\")) { break; }\n\ \t\tif(!strcmp(_buffer, \"exit\")) { break; }\n\
\t\tsscanf(_buffer, %a);\n%a\ \t\tsscanf(_buffer, %a);\n%a\
\t\tfn_main(&state, %a);\n\ \t\tfn_main(&state, %a);\n\
\t\tprintf(\"output: \");\n\
\t\tprintf(%a);\n\ \t\tprintf(%a);\n\
\t\tprintf(\"\\n\");\n\
\t}\n\ \t}\n\
%a\treturn EXIT_SUCCESS;\n\ %a\treturn EXIT_SUCCESS;\n\
}\n" }\n"

4
tests/arrow.node Normal file
View File

@ -0,0 +1,4 @@
node main (i: int) returns (o: int);
let
o = 1 -> 2 -> 3;
tel

16
tests/counting.node Normal file
View File

@ -0,0 +1,16 @@
-- count the number of top between two tick
node counting (tick:bool; top:bool)
returns (o: int);
var v, o1: int;
let o = if tick then v else 0 -> (pre o) + v;
v = if top then 1 else 0
tel;
node main (i: int)
returns (o: int);
let
-- 0 means no `tick` and no `top`
-- 1 means `tick`
-- 2 means `top`
o = counting(i = 1, i = 2)
tel;

View File

@ -1,4 +1,4 @@
node n2 (i: int) returns (o: bool); node main (i: int) returns (o: bool);
let let
o = pre (true and pre( i = pre(pre(i)))); o = pre (true and pre( i = pre(pre(i))));
tel tel

15
tests/reset.node Normal file
View File

@ -0,0 +1,15 @@
-- counter of `top`s until `reset` condition holds
node counting (tick: bool) returns (o: int);
var v: int;
let
o = v -> (pre o) + v;
v = if tick then 1 else 0
tel
node main (i: int) returns (o: int);
let
-- 0 means no `top` and no `reset`
-- 1 means `top`
-- 2 means `reset`
o = reset counting(i = 1) every (i = 2);
tel

14
tests/when_merge.node Normal file
View File

@ -0,0 +1,14 @@
node test (i: int) returns (o: int);
var x, y: int;
let
x = (1 / i) when (i <> 0);
y = 0 when (not (i <> 0));
o = merge (i <> 0) x y;
tel
node main (i: int) returns (o: int);
var garbage: int;
let
garbage = test(0);
o = test(1);
tel