Added proper label resolver for globals with test
authorLukas Krickl <lukas@krickl.dev>
Sat, 2 Dec 2023 21:45:57 +0000 (22:45 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sat, 2 Dec 2023 21:45:57 +0000 (22:45 +0100)
src/ulas.c
tests/t0.bin
tests/t0.s

index 24376f25109f4ce16fbe829705b6b930bf0ae2aa..33be3a28dc5c170f88766159c7be92e38bb27b36 100644 (file)
@@ -246,6 +246,8 @@ int ulas_symbolset(const char *name, int scope, struct ulas_tok tok,
 
     // def new symbol
     struct ulas_sym new_sym = {strdup(name), tok, scope, ulas.pass, constant};
+    // last char of name has to be : so we trim it away 
+    new_sym.name[strlen(new_sym.name) - 1] = '\0';
     ulas_symbufpush(&ulas.syms, new_sym);
   } else if (exisitng->lastdefin != ulas.pass) {
     // redefine if not defined this pass
@@ -1027,11 +1029,8 @@ fail:
 int ulas_valint(struct ulas_tok *lit, int *rc) {
   if (lit->type == ULAS_SYMBOL) {
     struct ulas_sym *stok = ulas_symbolresolve(lit->val.strv, rc);
-    // bail if symbol is not resolvable
-    if (*rc > 0) {
-      return 0;
-    }
     if (!stok || *rc == -1) {
+      ULASERR("Unabel to resolve '%s'\n", lit->val.strv);
       *rc = -1;
       return 0;
     }
index 1cc8c84c6ddfe8c65a6145558e67d10ebf7de588..b752c2e50338234207c621f181d226c45683c051 100644 (file)
Binary files a/tests/t0.bin and b/tests/t0.bin differ
index 102f333ffe22b1c164b8dcf42c9ab619d366899d..cf5efec084d14a4e87ef9a9e5735e6c07f93ec93 100644 (file)
@@ -73,4 +73,4 @@ l1:
   bit 0, d
   bit 0, [hl]
 
-  ld bc, l1 + 1
+  ld bc, l1 + 1