// 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(...) \
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});
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];
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 '<':
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;
}
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;
}
ld bc, @local
l2:
@local: ld bc, @local
+ ld bc, $