WIP: symbol resolver
authorLukas Krickl <lukas@krickl.dev>
Mon, 27 Nov 2023 17:17:59 +0000 (18:17 +0100)
committerLukas Krickl <lukas@krickl.dev>
Mon, 27 Nov 2023 17:17:59 +0000 (18:17 +0100)
include/ulas.h
src/ulas.c

index 2a7d5a24bbd1628cba11759a9e58bddcd1b1b789..570320175ff7079f4b08c0b4804cb5a2c9c067ed 100644 (file)
@@ -368,7 +368,9 @@ char *ulas_strndup(const char *src, unsigned long n);
 
 // resolve a symbol until an actual literal token (str, int) is found
 // returns NULL if the symbol cannot be resolved
-struct ulas_tok *ulas_symbolresolve(const char *name);
+// and sets rc to -1 if eunresolve is 1
+// if eunresolve is 0 rc will be set to 1 if the symbol is not resolved
+struct ulas_tok *ulas_symbolresolve(const char *name, int eunresolve, int *rc);
 
 // tokenisze according to pre-defined rules
 // returns the amount of bytes of line that were
@@ -445,9 +447,10 @@ char *ulas_preprocexpand(struct ulas_preproc *pp, const char *raw_line,
  */
 
 // convert literal to its int value
-int ulas_valint(struct ulas_tok *lit, int *rc);
+// retunrs -1 on error, 0 on success and 1 if there is an unresolved symbol
+int ulas_valint(struct ulas_tok *lit, int eunresolve, int *rc);
 // convert literal to its char value
-char *ulas_valstr(struct ulas_tok *lit, int *rc);
+char *ulas_valstr(struct ulas_tok *lit, int eunresolve, int *rc);
 
 struct ulas_tokbuf ulas_tokbuf(void);
 
index a07be33b9fa4814e2b1616b34bc5515b9718d758..7cc5d0f438052859bea687248a7ee490df920f16 100644 (file)
@@ -161,7 +161,7 @@ int ulas_isname(const char *tok, unsigned long n) {
   return 1;
 }
 
-struct ulas_tok *ulas_symbolresolve(const char *name) {
+struct ulas_tok *ulas_symbolresolve(const char *name, int eunresolve, int *rc) {
   // TODO: implement
   return NULL;
 }
@@ -931,7 +931,12 @@ fail:
  * Literals, tokens and expressions
  */
 
-int ulas_valint(struct ulas_tok *lit, int *rc) {
+int ulas_valint(struct ulas_tok *lit, int eunresolve, int *rc) {
+  if (lit->type == ULAS_SYMBOL) {
+    struct ulas_tok *stok = ulas_symbolresolve(lit->val.strv, eunresolve, rc);
+    return ulas_valint(stok, eunresolve, rc);
+  }
+
   if (!lit || lit->type != ULAS_INT) {
     ULASERR("Expected int\n");
     *rc = -1;
@@ -941,7 +946,7 @@ int ulas_valint(struct ulas_tok *lit, int *rc) {
   return lit->val.intv;
 }
 
-char *ulas_valstr(struct ulas_tok *lit, int *rc) {
+char *ulas_valstr(struct ulas_tok *lit, int eunresolve, int *rc) {
   if (!lit || lit->type != ULAS_STR) {
     ULASERR("Expected str\n");
     *rc = -1;
@@ -1329,7 +1334,7 @@ int ulas_intexpreval(int i, int *rc) {
   }
   case ULAS_EXPPRIM: {
     struct ulas_tok *t = ulas_tokbufget(&ulas.toks, e->val.prim.tok);
-    return ulas_valint(t, rc);
+    return ulas_valint(t, 0, rc);
   }
   }