Fixed $10 - $15 macro args
authorLukas Krickl <lukas@krickl.dev>
Wed, 3 Jan 2024 22:18:40 +0000 (23:18 +0100)
committerLukas Krickl <lukas@krickl.dev>
Wed, 3 Jan 2024 22:18:40 +0000 (23:18 +0100)
src/ulas.c
tests/t0.bin
tests/t0.s

index e85672115ae3fa0b9006a0bd518d306c40323a4e..d74f8e589b555966abde4a84802a88c9d720d994 100644 (file)
@@ -408,8 +408,12 @@ int ulas_tok(struct ulas_str *dst, const char **out_line, unsigned long n) {
         ulas_strensr(dst, write + 2);
         // escape char tokens
         dst->buf[write++] = line[i++];
-        if (line[i] && !isspace(line[i])) {
+        if (line[i] == '$') {
           dst->buf[write++] = line[i++];
+        } else {
+          while (line[i] && isdigit(line[i])) {
+            dst->buf[write++] = line[i++];
+          }
         }
         goto tokdone;
       case '=':
@@ -774,7 +778,7 @@ char *ulas_preprocexpand(struct ulas_preproc *pp, const char *raw_line,
         // loop until 9 args are found or the line ends
         int paramc = 0;
         while (paramc < ULAS_MACROPARAMMAX &&
-                // TODO: allow escaping , with \, 
+               // TODO: allow escaping , with \,
                ulas_tokuntil(&pp->macroparam[paramc], ',', &praw_line, *n) >
                    0) {
           // trim new lines from the end of macro params
@@ -785,7 +789,8 @@ char *ulas_preprocexpand(struct ulas_preproc *pp, const char *raw_line,
         ulas_strensr(&pp->line, strlen(def->value) + 2);
 
         const char *macro_argname[ULAS_MACROPARAMMAX] = {
-            "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15"};
+            "$1", "$2",  "$3",  "$4",  "$5",  "$6",  "$7", "$8",
+            "$9", "$10", "$11", "$12", "$13", "$14", "$15"};
 
         const char *val = def->value;
         unsigned long vallen = strlen(def->value);
index b9eeb83f33a9afa4220a1c8dbc765c563ffecaea..03c89e17a30fd94f49614a9effe6dfd1cd4a83a3 100644 (file)
Binary files a/tests/t0.bin and b/tests/t0.bin differ
index 718063aca0c5a4fb60e5a761972c3b9d1f26f06e..04c960938300bddd8b83d36ac8be464ced49a709 100644 (file)
@@ -135,10 +135,11 @@ l3: .db 1
 .rep repc, 6, 1, ld a, repc
 
 #macro testmacro
+.db $9
 .db $10
 .db $11
 .db $12
 .str $13
 #endmacro
 
-testmacro 1, 2, 3, 4, 5, 6, 7, 8, 9, 61, 62, 63, "test" 
+testmacro 1, 2, 3, 4, 5, 6, 7, 8, 60, 61, 62, 63, "test"