From 20db595f6b0be7dbd3c0fadf307f538ab73f59f6 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sun, 3 Dec 2023 19:58:20 +0100 Subject: [PATCH] WIP: re-assigning symbols --- include/ulas.h | 1 + src/test.c | 2 +- src/ulas.c | 12 ++++++++---- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/ulas.h b/include/ulas.h index 4d575e9..433bd02 100644 --- a/include/ulas.h +++ b/include/ulas.h @@ -514,6 +514,7 @@ int ulas_tokbufpush(struct ulas_tokbuf *tb, struct ulas_tok tok); struct ulas_tok *ulas_tokbufget(struct ulas_tokbuf *tb, int i); void ulas_tokbufclear(struct ulas_tokbuf *tb); void ulas_tokbuffree(struct ulas_tokbuf *tb); +void ulas_tokfree(struct ulas_tok *t); struct ulas_exprbuf ulas_exprbuf(void); diff --git a/src/test.c b/src/test.c index 483d451..dddcb69 100644 --- a/src/test.c +++ b/src/test.c @@ -317,7 +317,7 @@ void test_symscope(void) { ASSERT_SYMSCOPE(0, "@t1:", -1, 1); ASSERT_SYMSCOPE(-1, "@t1:", -1, 1); - // manual scoping + // manual scoping ASSERT_SYMSCOPE(0, "t2:", 5, 1); ASSERT_SYMSCOPE(-1, "t2:", 5, 1); ASSERT_SYMSCOPE(0, "t2:", 6, 1); diff --git a/src/ulas.c b/src/ulas.c index e8b4009..97d2539 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -226,7 +226,7 @@ struct ulas_sym *ulas_symbolresolve(const char *name, int scope, int *rc) { int ulas_symbolset(const char *cname, int scope, struct ulas_tok tok, int constant) { - // remove : from name + // remove : from name char name[ULAS_SYMNAMEMAX]; long len = strlen(cname); assert(len < ULAS_SYMNAMEMAX); @@ -247,8 +247,8 @@ int ulas_symbolset(const char *cname, int scope, struct ulas_tok tok, } } - struct ulas_sym *exisitng = ulas_symbolresolve(name, scope, &resolve_rc); - if (!exisitng) { + struct ulas_sym *existing = ulas_symbolresolve(name, scope, &resolve_rc); + if (!existing) { // inc scope when symbol is global if (name[0] != ULAS_TOK_SCOPED_SYMBOL_BEGIN) { ulas.scope++; @@ -257,8 +257,12 @@ int ulas_symbolset(const char *cname, int scope, struct ulas_tok tok, // def new symbol struct ulas_sym new_sym = {strdup(name), tok, scope, ulas.pass, constant}; ulas_symbufpush(&ulas.syms, new_sym); - } else if (exisitng->lastdefin != ulas.pass) { + } else if (existing->lastdefin != ulas.pass || !existing->constant) { // redefine if not defined this pass + existing->lastdefin = ulas.pass; + ulas_tokfree(&existing->tok); + existing->tok = tok; + existing->constant = constant; } else { // exists.. cannot have duplicates! rc = -1; -- 2.30.2