diff options
author | Adam NAILI | 2018-06-05 14:56:02 +0200 |
---|---|---|
committer | Adam NAILI | 2018-06-05 14:56:02 +0200 |
commit | 0255cca32a78847d2de0134740b991a77f5ad555 (patch) | |
tree | ba2bb6bfa74fa63ef75ab31db2b3cdb8b2e0123d | |
parent | 53e859913d6eb7141dbd1ed48f28c336f1322534 (diff) | |
download | tpc-compiler-0255cca32a78847d2de0134740b991a77f5ad555.tar.gz |
Return test
-rw-r--r-- | res/test_read.tpc | 1 | ||||
-rw-r--r-- | res/test_return.tpc | 13 | ||||
-rw-r--r-- | src/generator.c | 2 | ||||
-rw-r--r-- | src/tpc.y | 2 |
4 files changed, 16 insertions, 2 deletions
diff --git a/res/test_read.tpc b/res/test_read.tpc index 0109e4d..6ad3632 100644 --- a/res/test_read.tpc +++ b/res/test_read.tpc | |||
@@ -9,4 +9,5 @@ entier main(void) { | |||
9 | caractere r1; | 9 | caractere r1; |
10 | readc(r1); | 10 | readc(r1); |
11 | print(r1); | 11 | print(r1); |
12 | return 0; | ||
12 | } | 13 | } |
diff --git a/res/test_return.tpc b/res/test_return.tpc new file mode 100644 index 0000000..241a1ba --- /dev/null +++ b/res/test_return.tpc | |||
@@ -0,0 +1,13 @@ | |||
1 | /* test-table-symboles.tpc */ | ||
2 | |||
3 | /* Test file for simplified translator of a declaration of variables in C */ | ||
4 | entier r1,b,s,c,r2 ; | ||
5 | caractere letter, digit, punct; | ||
6 | |||
7 | entier test(void){ | ||
8 | } | ||
9 | |||
10 | entier main(void) { | ||
11 | print(test()); | ||
12 | return 0; | ||
13 | } | ||
diff --git a/src/generator.c b/src/generator.c index d5df545..1181ac7 100644 --- a/src/generator.c +++ b/src/generator.c | |||
@@ -97,7 +97,7 @@ Type gen_function_declaration(const char name[], int return_type, int nb_param) | |||
97 | } | 97 | } |
98 | 98 | ||
99 | void gen_function_end_declaration() { | 99 | void gen_function_end_declaration() { |
100 | fprintf(output, "mov rsp, rbp\npop rbp\nret\n"); | 100 | fprintf(output, "mov rsp, rbp\npop rbp\nret\n"); |
101 | } | 101 | } |
102 | 102 | ||
103 | void gen_function_return(Type expect, Type actual) { | 103 | void gen_function_return(Type expect, Type actual) { |
@@ -164,7 +164,7 @@ F: | |||
164 | | LValue { $$ = gen_value($<ident>1, scope); } | 164 | | LValue { $$ = gen_value($<ident>1, scope); } |
165 | | NUM { $$ = gen_num($1, scope); } | 165 | | NUM { $$ = gen_num($1, scope); } |
166 | | CARACTERE { $$ = gen_char($1, scope); } | 166 | | CARACTERE { $$ = gen_char($1, scope); } |
167 | | IDENT '(' Arguments ')' { return_type = fun_lookup($<ident>1,$<num>3);$$ = gen_function_call($<ident>1,$<num>3); } | 167 | | IDENT '(' Arguments ')' { $$ = gen_function_call($<ident>1,$<num>3); } |
168 | ; | 168 | ; |
169 | LValue: | 169 | LValue: |
170 | IDENT { gen_check($<ident>1, scope); } | 170 | IDENT { gen_check($<ident>1, scope); } |