From: Lukas Krickl Date: Sat, 2 Dec 2023 12:43:30 +0000 (+0100) Subject: WIP: symbol definition X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=399d8595594ca8d9166f09bf984044112f9afd4a;p=ulas%2F.git WIP: symbol definition --- diff --git a/include/ulas.h b/include/ulas.h index dcd60bf..fe14628 100644 --- a/include/ulas.h +++ b/include/ulas.h @@ -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(...) \ diff --git a/src/ulas.c b/src/ulas.c index 466409f..854eebc 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -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 {