Added $ for current address
authorLukas Krickl <lukas@krickl.dev>
Mon, 4 Dec 2023 08:58:30 +0000 (09:58 +0100)
committerLukas Krickl <lukas@krickl.dev>
Mon, 4 Dec 2023 08:58:30 +0000 (09:58 +0100)
include/ulas.h
src/test.c
src/ulas.c
tests/t0.bin
tests/t0.s

index 433bd02b70ad952616c75f25e870e7f954e72f59..c078a04d9e46a5df6413963176c1ba4704129852 100644 (file)
@@ -49,6 +49,7 @@
 // start of preprocessor directives such as #define or #include
 #define ULAS_TOK_PREPROC_BEGIN '#'
 #define ULAS_TOK_SCOPED_SYMBOL_BEGIN '@'
+#define ULAS_TOK_CURRENT_ADDR '$'
 
 #define ULASINFO() fprintf(ulaserr, "%s:%ld ", ulas.filename, ulas.line);
 #define ULASDBG(...)                                                           \
index e89e39a88745ab66327191cc87cae605526df33d..80c407aba0431ad8c9903f55f585bd5234e584ac 100644 (file)
 void test_tok(void) {
   TESTBEGIN("tok");
 
-  assert_tok(
-      "  test  tokens   with,   line / * + - , ; $1 = == != > < >= <=",
-      {"test", "tokens", "with", ",",  "line", "/", "*", "+",  "-",  ",",
-       ";",    "$1",     "=",    "==", "!=",   ">", "<", ">=", "<=", NULL});
+  assert_tok("  test  tokens   with,   line / * + - , ; $1 $ = == != > < >= <=",
+             {"test", "tokens", "with", ",", "line", "/",  "*",
+              "+",    "-",      ",",    ";", "$1",   "$",  "=",
+              "==",   "!=",     ">",    "<", ">=",   "<=", NULL});
 
   assert_tokuntil(" this is a, test for tok , until", ',',
                   {"this is a", "test for tok ", "until", NULL});
index 60cc6f650d18f96964f68ab16305acd9cc129130..6cb5cd2bb758b08d7214f553509be8763be2f19c 100644 (file)
@@ -213,6 +213,7 @@ int ulas_islabelname(const char *tok, unsigned long n) {
   return tok[n - 1] == ':' && ulas_isname(tok, n - 1);
 }
 
+struct ulas_sym ulas_symaddr = {NULL, {ULAS_INT, {0}}, 0, 0, 1};
 struct ulas_sym *ulas_symbolresolve(const char *name, int scope, int *rc) {
   for (int i = 0; i < ulas.syms.len; i++) {
     struct ulas_sym *sym = &ulas.syms.buf[i];
@@ -322,7 +323,9 @@ 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++];
-      dst->buf[write++] = line[i++];
+      if (line[i] && !isspace(line[i])) {
+        dst->buf[write++] = line[i++];
+      }
       goto tokdone;
     case '=':
     case '<':
@@ -1051,12 +1054,16 @@ int ulas_valint(struct ulas_tok *lit, int *rc) {
     return ulas_valint(&stok->tok, rc);
   }
 
-  if (!lit || lit->type != ULAS_INT) {
+  if (!lit || (lit->type != ULAS_INT && lit->type != ULAS_TOK_CURRENT_ADDR)) {
     ULASERR("Expected int\n");
     *rc = -1;
     return 0;
   }
 
+  if (lit->type == ULAS_TOK_CURRENT_ADDR) {
+    return ulas.address;
+  }
+
   return lit->val.intv;
 }
 
@@ -1272,8 +1279,9 @@ int ulas_parseexprat(int *i);
 
 int ulas_parseprim(int *i) {
   struct ulas_tok *t = ulas_tokbufget(&ulas.toks, *i);
-  if (!t || (t->type != ULAS_INT && t->type != ULAS_STR &&
-             t->type != ULAS_SYMBOL && t->type != '(' && t->type != ')')) {
+  if (!t ||
+      (t->type != ULAS_INT && t->type != ULAS_STR && t->type != ULAS_SYMBOL &&
+       t->type != ULAS_TOK_CURRENT_ADDR && t->type != '(' && t->type != ')')) {
     ULASERR("Primary expression expected\n");
     return -1;
   }
index 04a9544411aa838e08d9db0135683215d0c8050c..5d2bc3aa118fc25e69c9fc3dc65fd15b28184333 100644 (file)
Binary files a/tests/t0.bin and b/tests/t0.bin differ
index 9dc13210265c20daff372105b27483b284f697a1..f6eb38d4a9e5b68c376c7145487ce618e9badf48 100644 (file)
@@ -78,3 +78,4 @@ l1:
   ld bc, @local
 l2:
 @local: ld bc, @local
+  ld bc, $