Increased max macro parameters to 15
authorLukas Krickl <lukas@krickl.dev>
Wed, 3 Jan 2024 20:16:35 +0000 (21:16 +0100)
committerLukas Krickl <lukas@krickl.dev>
Wed, 3 Jan 2024 20:16:35 +0000 (21:16 +0100)
include/ulas.h
src/ulas.c
tests/t0.bin
tests/t0.s

index b06e5fbb029bdc68c07fa0ebe1213c961632c789..633a204b6f3c94494c331d95e0274c12c212e10d 100644 (file)
@@ -15,7 +15,7 @@
 #define ULAS_PATHMAX 4096
 #define ULAS_LINEMAX 4096
 #define ULAS_OUTBUFMAX 64
-#define ULAS_MACROPARAMMAX 9
+#define ULAS_MACROPARAMMAX 15
 
 #define MAX(x, y) (((x) > (y)) ? (x) : (y))
 #define MIN(x, y) (((x) < (y)) ? (x) : (y))
index 8f03ed9198a474b54be84dc6cb7e5635a2b80dbf..73e8c28025b00fb8d9f4be46c42ef9f75d246bee 100644 (file)
@@ -757,6 +757,7 @@ char *ulas_preprocexpand(struct ulas_preproc *pp, const char *raw_line,
       }
       case ULAS_PPMACRO: {
         // TODO: i am sure we can optimize the resize of line buffers here...
+        // TODO: allow recursive macro calls
 
         // get 9 comma separated values.
         // $1-$9 will reference the respective arg
@@ -773,6 +774,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 \, 
                ulas_tokuntil(&pp->macroparam[paramc], ',', &praw_line, *n) >
                    0) {
           // trim new lines from the end of macro params
@@ -783,7 +785,7 @@ 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"};
+            "$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 ec638b95dde8bd2d4f4eed37942e391c1444394a..b9eeb83f33a9afa4220a1c8dbc765c563ffecaea 100644 (file)
Binary files a/tests/t0.bin and b/tests/t0.bin differ
index 17e0ab0fd6238d749eabbb4c65785940139e1d6f..0609ee72fdb974b17493bd879f919e589ca127a8 100644 (file)
@@ -133,3 +133,11 @@ l3: .db 1
 
 .rep repc, 6, 2, ld a, repc
 .rep repc, 6, 1, ld a, repc
+
+#macro testmacro
+.db $10
+.db $11
+.db $12
+#endmacro
+
+testmacro 1, 2, 3, 4, 5, 6, 7, 8, 9, 61, 62, 63