diff options
author | Carlos Maniero <carlosmaniero@gmail.com> | 2023-04-20 13:42:10 -0300 |
---|---|---|
committer | Johnny Richard <johnny@johnnyrichard.com> | 2023-04-20 18:57:43 +0200 |
commit | 219dfdfdc98529ce173f894b79d88919a65c2808 (patch) | |
tree | 8792c686d05b107875d43f570ed6666f91dda19e /test | |
parent | 58da5195ef7d517f851ebfabfe79cfa27c0b2dde (diff) |
parser: Create the literal node type
Since we want to extend our code to support multiple kind of expression
it does not make sense that the return statement always return a number.
For now on, return statement has an ast_node_t as argument, meaning that
it could be anything. The literal_node_t was also implemented in order
to keep the application behavior.
Following the C's calling convention the literal values are stored at
%eax and the return takes this argument to do anything it is needed.
Signed-off-by: Carlos Maniero <carlosmaniero@gmail.com>
Reviewed-by: Johnny Richard <johnny@johnnyrichard.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parser_test.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/test/parser_test.c b/test/parser_test.c index d1b8881..573296f 100644 --- a/test/parser_test.c +++ b/test/parser_test.c @@ -71,7 +71,11 @@ test_parse_function(const MunitParameter params[], ast_node_t *ast_return = ast_function->data.function.body; assert_int(AST_RETURN_STMT, ==, ast_return->kind); - assert_int(42, ==, ast_return->data.return_stmt.number); + + ast_node_t *ast_literal = ast_return->data.return_stmt.argument; + + assert_int(AST_LITERAL, ==, ast_literal->kind); + assert_int(42, ==, ast_literal->data.literal.value.integer); ast_node_destroy(ast_function); @@ -89,7 +93,7 @@ test_parse_basic_syntax_errors(const MunitParameter params[], assert_parser_error("main(): { return 42; }" , "expected 'TOKEN_NAME' but got '{'"); assert_parser_error("main(): i32 return 42; }" , "expected '{' but got 'TOKEN_NAME'"); assert_parser_error("main(): i32 { 42; }" , "expected 'TOKEN_NAME' but got 'TOKEN_NUMBER'"); - assert_parser_error("main(): i32 { return; }" , "expected 'TOKEN_NUMBER' but got ';'"); + assert_parser_error("main(): i32 { return; }" , "unexpected '; (;)' token"); assert_parser_error("main(): i32 { return 42;" , "expected '}' but got end of file"); assert_parser_error("main(): beff { return 42; }" , "type 'beff' is not defined"); assert_parser_error("main(): i32 { oxi 42; }" , "expected 'return' keyword but got 'oxi'"); |