Added counter symbol naming to .rep
authorLukas Krickl <lukas@krickl.dev>
Sun, 24 Dec 2023 17:33:24 +0000 (18:33 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sun, 24 Dec 2023 17:33:24 +0000 (18:33 +0100)
src/ulas.c
tests/t0.bin
tests/t0.s

index 0a11ad16c982834325b93bb12dac65586d5ca477..dffea8920f9fa552ae7abfa6b1150b365c17ebb6 100644 (file)
@@ -2585,6 +2585,26 @@ int ulas_asmdirchr(FILE *dst, const char **line, unsigned long n, int *rc) {
 }
 
 int ulas_asmdirrep(FILE *dst, FILE *src, const char **line, unsigned long n) {
+  char name[ULAS_SYMNAMEMAX];
+  ulas_tok(&ulas.tok, line, n);
+  if (!ulas_isname(ulas.tok.buf, ulas.tok.maxlen)) {
+    ULASERR("Unexpected token '%s'\n", ulas.tok.buf);
+    return -1;
+  }
+  strncpy(name, ulas.tok.buf, ULAS_SYMNAMEMAX);
+
+  // consume ,
+  ulas_tok(&ulas.tok, line, n);
+  if (strncmp(ulas.tok.buf, ",", ulas.tok.maxlen) != 0) {
+    ULASERR("Unexpected token '%s'. Expected ','\n", ulas.tok.buf);
+    return -1;
+  }
+
+  union ulas_val val = {0};
+  val.intv = 0;
+  struct ulas_tok tok = {ULAS_INT, val};
+  ulas_symbolset(name, ulas.scope, tok, 0);
+
   int repval = 0;
   int rc = 0;
 
@@ -2609,6 +2629,8 @@ int ulas_asmdirrep(FILE *dst, FILE *src, const char **line, unsigned long n) {
   unsigned long argline_len = strlen(*line);
 
   for (int i = 0; i < repval; i += step) {
+    tok.val.intv = i;
+    ulas_symbolset(name, ulas.scope, tok, 0);
     rc = ulas_asmline(dst, src, *line, argline_len);
     if (rc == -1) {
       break;
index d480d73b283696097da413d86de46765d34ebc83..ec638b95dde8bd2d4f4eed37942e391c1444394a 100644 (file)
Binary files a/tests/t0.bin and b/tests/t0.bin differ
index 296c6fd1d3c0f94b4861930440eb53984fb58e31..17e0ab0fd6238d749eabbb4c65785940139e1d6f 100644 (file)
@@ -131,4 +131,5 @@ l3: .db 1
 .db 1, 2, 3
 .chr 01233213
 
-.rep 6, 2, halt
+.rep repc, 6, 2, ld a, repc
+.rep repc, 6, 1, ld a, repc