summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2021-05-08 12:26:19 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2021-05-08 12:26:19 -0400
commit64f75f275e98030f6718d395e2f4291ae5c3b126 (patch)
treed7d0bc0504480df24b7e0fc31582a3c61b91fec8
parent9cb8e4f83b49355610134b152df129b2f68ce9fe (diff)
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.
-rw-r--r--lexer.c9
1 files 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++;