Added the ability to use defined consts inside of defines
authorLukas Krickl <lukas@krickl.dev>
Tue, 5 Nov 2024 11:16:50 +0000 (12:16 +0100)
committerLukas Krickl <lukas@krickl.dev>
Tue, 5 Nov 2024 11:16:50 +0000 (12:16 +0100)
src/ulas.c
tests/t0.s

index a7767aa9b88c4a9c04c6552b9a62d783f69a2d7f..7e2a234c3f4494c49a57be1e771a7c646f333d93 100644 (file)
@@ -803,6 +803,21 @@ void ulas_trimend(char c, char *buf, unsigned long n) {
   }
 }
 
+void ulas_preprocexpand_rec(struct ulas_preproc *pp) {
+  // expand macro result again to allow
+  // defines to appear in the macro
+  ulas_strensr(&pp->line2, strlen(pp->line.buf) + 1);
+  sprintf(pp->line2.buf, "%s", pp->line.buf);
+  unsigned long n = strlen(pp->line.buf);
+  pp->exp_depth++;
+  if (pp->exp_depth > ULAS_PREPROC_MAX_MACRO_DEPTH) {
+    ULASERR("Max macro recursion depth reached\n");
+    return;
+  }
+  ulas_preprocexpand(pp, pp->line2.buf, &n);
+  pp->exp_depth--;
+}
+
 char *ulas_preprocexpand(struct ulas_preproc *pp, const char *raw_line,
                          unsigned long *n) {
   const char *praw_line = raw_line;
@@ -855,6 +870,7 @@ char *ulas_preprocexpand(struct ulas_preproc *pp, const char *raw_line,
           } else {
             strncat(pp->line.buf, def->value, val_len);
           }
+          ulas_preprocexpand_rec(pp);
         }
         break;
       }
@@ -959,18 +975,7 @@ char *ulas_preprocexpand(struct ulas_preproc *pp, const char *raw_line,
             strncat(pp->line.buf, tocat, tocatlen);
           }
         }
-        // expand macro result again to allow
-        // defines to appear in the macro
-        ulas_strensr(&pp->line2, strlen(pp->line.buf) + 1);
-        sprintf(pp->line2.buf, "%s", pp->line.buf);
-        unsigned long n = strlen(pp->line.buf);
-        pp->exp_depth++;
-        if (pp->exp_depth > ULAS_PREPROC_MAX_MACRO_DEPTH) {
-          ULASERR("Max macro recursion depth reached\n");
-          goto end;
-        }
-        ulas_preprocexpand(pp, pp->line2.buf, &n);
-        pp->exp_depth--;
+        ulas_preprocexpand_rec(pp);
         goto end;
       }
       }
index 10a7beeff0e1a3b4c177d41a5fade6827b42059a..66b53bd2729c6e21bf7599d3b64a7d93ff45e629 100644 (file)
@@ -168,7 +168,8 @@ toplevel 5, 6
   xor a, a
 #endif
 
-#define DEFARG 1
+#define DEFDEF 1
+#define DEFARG DEFDEF
 
 #macro defarg 
   .db $1 + 1, $2