From 64f75f275e98030f6718d395e2f4291ae5c3b126 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Sat, 8 May 2021 12:26:19 -0400 Subject: Fixed a bug with how local symbols with a depth greater than one are handled. It wasn't getting the correct depth when relative local symbols were used. So to account for that, it adds the relative depth (number of '@'s in a row), with the absolute depth (number of '.'s), to get the true scope depth. --- lexer.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lexer.c b/lexer.c index 2c618d2..099204e 100644 --- a/lexer.c +++ b/lexer.c @@ -313,6 +313,8 @@ char *mk_scope_name(symbol *csym, int depth, const char *name, uint8_t dbg) { scopes = malloc(sizeof(char *)*depth); } + for (; s && s->depth > depth; s = s->up); + for (int i = depth; i && s; i--) { if (dbg) { printf("mk_scope_name(): s->depth: %i\n", s->depth); @@ -754,8 +756,9 @@ int get_expr_type(char **p, uint64_t address, void *val, int *found_reg, char st if (is_reg(tmp) >= 0) { *found_reg = 1; } else { - scope_name = (!scope_depth) ? mk_scope_name(cur_sym, depth, tmp, dbg) : tmp; - s = get_sym(scope_name, address, NULL, (scope_depth) ? scope_depth : depth, 1, dbg); + int total_depth = depth+scope_depth; + scope_name = (!scope_depth || total_depth) ? mk_scope_name(cur_sym, depth, tmp, dbg) : tmp; + s = get_sym(scope_name, address, NULL, total_depth, 1, dbg); isfixup += (s == NULL); type = EXPR_SYM; *(symbol **)val = s; @@ -1289,7 +1292,7 @@ uint64_t lex(char *str, uint64_t address, uint16_t bline, uint8_t dbg) { for (; isdelm(str[i+spaces], dbg) == 16; spaces++); uint8_t ret = get_ptok(str[i+spaces], dbg); if (ret == PTOK_COLON || ret == PTOK_EQU) { - depth = (lex_type == TOK_LOCAL); + depth = (lex_type != TOK_LOCAL) ? 0 : depth; } int is_expr = (!is_struct && str[i+spaces] != ':' && str[i+spaces] != '='); l->count++; -- cgit v1.2.3-13-gbd6f