WIP: symbol defines
authorLukas Krickl <lukas@krickl.dev>
Thu, 30 Nov 2023 12:39:34 +0000 (13:39 +0100)
committerLukas Krickl <lukas@krickl.dev>
Thu, 30 Nov 2023 12:39:34 +0000 (13:39 +0100)
include/ulas.h
src/ulas.c

index 307cb14c0e0ce098eecc99e9fe905e966ec84e42..049038aabec1d7cbd08fae89fd1c42236b314c4d 100644 (file)
@@ -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
index 751220bdcfaa788e7fcedadc10e4934425bbfd51..29cd3e623d1cf81b46661e03d6dd96b80221dbdc 100644 (file)
@@ -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])