From: Lukas Krickl Date: Thu, 30 Nov 2023 12:39:34 +0000 (+0100) Subject: WIP: symbol defines X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=6e904ade5f7ea5f50a88c43f174c2b805ba80230;p=ulas%2F.git WIP: symbol defines --- diff --git a/include/ulas.h b/include/ulas.h index 307cb14..049038a 100644 --- a/include/ulas.h +++ b/include/ulas.h @@ -149,17 +149,30 @@ struct ulas_exprbuf { }; /** - * Symbols + * The assembler can go over the code twice to resolve all future labels as well + * as past labels This causes the entire process to start over for now meaning + * that the 2 passes will behave as if they run their own assembly process with + * slightly different settings. Pass settings ULAS_SYM_FINAL: Final pass, enable + * code output and evaluate all expressions and directives ULAS_SYM_RESOLVE: + * Disable code output and the .set directive. Resolve labels */ +enum ulas_pass { + ULAS_PASS_FINAL = 0, + ULAS_PASS_RESOLVE = 1, +}; -enum ulas_syms { ULAS_SYM_LABEL, ULAS_SYM_SET }; +/** + * Symbols + */ struct ulas_sym { char *name; struct ulas_tok tok; - enum ulas_syms type; // this label's scope index int scope; + // last pass this was defined in... + // a symbol may only be defined once per pass/scope + enum ulas_pass lastdefin; }; // holds all currently defned symbols @@ -173,19 +186,6 @@ struct ulas_symbuf { * Assembly context */ -/** - * The assembler can go over the code twice to resolve all future labels as well - * as past labels This causes the entire process to start over for now meaning - * that the 2 passes will behave as if they run their own assembly process with - * slightly different settings. Pass settings ULAS_SYM_FINAL: Final pass, enable - * code output and evaluate all expressions and directives ULAS_SYM_RESOLVE: - * Disable code output and the .set directive. Resolve labels - */ -enum ulas_pass { - ULAS_PASS_FINAL = 0, - ULAS_PASS_RESOLVE = 1, -}; - struct ulas_preproc { struct ulas_ppdef *defs; unsigned long defslen; @@ -412,6 +412,11 @@ char *ulas_strndup(const char *src, unsigned long n); // respective flag value struct ulas_tok *ulas_symbolresolve(const char *name, int *rc); +// define a new symbol +// scope 0 indicates global scope +// if the symbol already exists -1 is returned +int ulas_symboldef(const char *name, int scope, struct ulas_tok token); + // tokenisze according to pre-defined rules // returns the amount of bytes of line that were // consumed or -1 on error diff --git a/src/ulas.c b/src/ulas.c index 751220b..29cd3e6 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -222,6 +222,10 @@ struct ulas_tok *ulas_symbolresolve(const char *name, int *rc) { return NULL; } +int ulas_symboldef(const char *name, int scope, struct ulas_tok token) { + return 0; +} + #define WELD_TOKISTERM write #define WELD_TOKCOND (i < n && write < n && line[i])