From 219dfdfdc98529ce173f894b79d88919a65c2808 Mon Sep 17 00:00:00 2001 From: Carlos Maniero Date: Thu, 20 Apr 2023 13:42:10 -0300 Subject: 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 Reviewed-by: Johnny Richard --- test/parser_test.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'test/parser_test.c') 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'"); -- cgit v1.2.3