WIP: symbol definition
authorLukas Krickl <lukas@krickl.dev>
Sat, 2 Dec 2023 12:43:30 +0000 (13:43 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sat, 2 Dec 2023 12:43:30 +0000 (13:43 +0100)
include/ulas.h
src/ulas.c

index dcd60bf4be355c73633424b0fd9bf39c28cfc240..fe14628487dbeaab91db787603803cbce14a56dd 100644 (file)
@@ -47,6 +47,7 @@
 #define ULAS_TOK_ASMDIR_BEGIN '.'
 // start of preprocessor directives such as #define or #include
 #define ULAS_TOK_PREPROC_BEGIN '#'
+#define ULAS_TOK_SCOPED_SYMBOL_BEGIN '@'
 
 #define ULASINFO() fprintf(ulaserr, "%s:%ld ", ulas.filename, ulas.line);
 #define ULASDBG(...)                                                           \
index 466409f70ed9631ac1a6f7e750c2b0576960d9f0..854eebc6898da9a216aef258177d55029e401726 100644 (file)
@@ -227,9 +227,26 @@ int ulas_symbolset(const char *name, int scope, struct ulas_tok tok,
                    int constant) {
   int rc = 0;
   int resolve_rc = 0;
+
+  // auto-determine scope
+  if (scope == -1) {
+    if (name[0] == ULAS_TOK_SCOPED_SYMBOL_BEGIN) {
+      scope = ulas.scope;
+    } else {
+      scope = 0;
+    }
+  }
+
   struct ulas_sym *exisitng = ulas_symbolresolve(name, &resolve_rc);
-  // define new
   if (!exisitng) {
+    // inc scope when symbol is global
+    if (name[0] != ULAS_TOK_SCOPED_SYMBOL_BEGIN) {
+      ulas.scope++;
+    }
+
+    // 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) {
     // redefine if not defined this pass
   } else {