From b1f7b0cccc6986ca107d9eeb1c7d5e5e5a32dc49 Mon Sep 17 00:00:00 2001 From: Johnny Richard Date: Sun, 30 Apr 2023 03:11:00 -0300 Subject: gas: Compile variable expression with scope support This patch adds the variable compilation and uses a scope (a stack of map) to lookup for identities. Today we use a vector + ref_entry structs in order to achieve the scope implementation. The ref_entry lacks memory management, we are still no sure who will be the owner of the pointer. We also want to replace the scope a hashtable_t type as soon as we get one. Signed-off-by: Johnny Richard Co-authored-by: Carlos Maniero --- src/parser.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/parser.c') diff --git a/src/parser.c b/src/parser.c index 48a9125..f4829ee 100644 --- a/src/parser.c +++ b/src/parser.c @@ -135,10 +135,10 @@ parser_parse_factor(parser_t *parser, ast_node_t *node) if (!drop_expected_token(parser, TOKEN_CPAREN)) return false; return true; - case TOKEN_NAME: - ast_node_init_identifier(node, token.value); + case TOKEN_NAME: { // TODO: Check node kind, today accepts only variables - if (scope_get(parser->scope, token.value) == NULL) { + ast_node_t *var_node = scope_get(parser->scope, token.value); + if (var_node == NULL) { parser_error_t error; error.token = token; sprintf(error.message, "identifier '" SVFMT "' not defined", SVARG(&token.value)); @@ -146,7 +146,10 @@ parser_parse_factor(parser_t *parser, ast_node_t *node) return false; } + ast_node_init_variable(node, &var_node->data.variable_declaration.identifier); + return true; + } default: { parser_error_t error; error.token = token; -- cgit v1.2.3