diff options
-rw-r--r-- | res/test_return.tpc | 5 | ||||
-rw-r--r-- | src/generator.c | 7 | ||||
-rw-r--r-- | src/symbol_table.c | 2 |
3 files changed, 7 insertions, 7 deletions
diff --git a/res/test_return.tpc b/res/test_return.tpc index 241a1ba..f450203 100644 --- a/res/test_return.tpc +++ b/res/test_return.tpc | |||
@@ -4,10 +4,11 @@ | |||
4 | entier r1,b,s,c,r2 ; | 4 | entier r1,b,s,c,r2 ; |
5 | caractere letter, digit, punct; | 5 | caractere letter, digit, punct; |
6 | 6 | ||
7 | entier test(void){ | 7 | caractere test(void){ |
8 | } | 8 | } |
9 | 9 | ||
10 | entier main(void) { | 10 | entier main(void) { |
11 | print(test()); | 11 | letter = test(); |
12 | print(letter); | ||
12 | return 0; | 13 | return 0; |
13 | } | 14 | } |
diff --git a/src/generator.c b/src/generator.c index bf187e0..37581e0 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 rax,-1\nmov 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) { |
@@ -105,9 +105,8 @@ void gen_function_return(Type expect, Type actual) { | |||
105 | fprintf(stderr, "Return type mismatch at line %d.", lineno); | 105 | fprintf(stderr, "Return type mismatch at line %d.", lineno); |
106 | exit(1); | 106 | exit(1); |
107 | } | 107 | } |
108 | |||
109 | if (actual != VOID_T) fprintf(output, "pop rax\n"); | 108 | if (actual != VOID_T) fprintf(output, "pop rax\n"); |
110 | gen_function_end_declaration(); | 109 | fprintf(output, "mov rsp, rbp\npop rbp\nret\n"); |
111 | } | 110 | } |
112 | 111 | ||
113 | Type gen_function_call(const char name[], int nb_param) { | 112 | Type gen_function_call(const char name[], int nb_param) { |
@@ -183,7 +182,7 @@ void gen_print(int type) { | |||
183 | case CHAR: | 182 | case CHAR: |
184 | fprintf(output, "call printc\n"); | 183 | fprintf(output, "call printc\n"); |
185 | break; | 184 | break; |
186 | default: fprintf(stderr, "Error print, supposed to have type CHAR or INT"); | 185 | default: fprintf(stderr, "Error print, supposed to have type CHAR or INT\n"); |
187 | } | 186 | } |
188 | 187 | ||
189 | } | 188 | } |
diff --git a/src/symbol_table.c b/src/symbol_table.c index 9d9617c..64399bd 100644 --- a/src/symbol_table.c +++ b/src/symbol_table.c | |||
@@ -213,6 +213,6 @@ static char *string_of_type(int type) { | |||
213 | void check_expected_type(int type_to_check, int type_expected) { | 213 | void check_expected_type(int type_to_check, int type_expected) { |
214 | if (type_to_check != type_expected) | 214 | if (type_to_check != type_expected) |
215 | fprintf(stderr, "Expected type : %s -> Got type : %s (near line %d)\n", | 215 | fprintf(stderr, "Expected type : %s -> Got type : %s (near line %d)\n", |
216 | string_of_type(type_to_check), string_of_type(type_to_check), | 216 | string_of_type(type_expected), string_of_type(type_to_check), |
217 | lineno); | 217 | lineno); |
218 | } | 218 | } |