From: Lukas Krickl Date: Mon, 4 Dec 2023 08:58:30 +0000 (+0100) Subject: Added $ for current address X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=54d01dc762ba9762cc1db47ef78ce4a142cbc8c9;p=ulas%2F.git Added $ for current address --- diff --git a/include/ulas.h b/include/ulas.h index 433bd02..c078a04 100644 --- a/include/ulas.h +++ b/include/ulas.h @@ -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(...) \ diff --git a/src/test.c b/src/test.c index e89e39a..80c407a 100644 --- a/src/test.c +++ b/src/test.c @@ -49,10 +49,10 @@ 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}); diff --git a/src/ulas.c b/src/ulas.c index 60cc6f6..6cb5cd2 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -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; } diff --git a/tests/t0.bin b/tests/t0.bin index 04a9544..5d2bc3a 100644 Binary files a/tests/t0.bin and b/tests/t0.bin differ diff --git a/tests/t0.s b/tests/t0.s index 9dc1321..f6eb38d 100644 --- a/tests/t0.s +++ b/tests/t0.s @@ -78,3 +78,4 @@ l1: ld bc, @local l2: @local: ld bc, @local + ld bc, $