feat(v4.0.0): the text assembler takes &NAME and CONST+N
&NAME is the address of a word as a literal; CONST+N is a loader constant plus an offset as one literal, so that a capsule file can address the cells of its scratch area without adding at run time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
26a6a16537
commit
44ffd261bb
+25
-1
@@ -300,7 +300,7 @@ static void end_word(v4_text *t)
|
||||
static void define(v4_text *t, const char *name, unsigned char kind, v4_cell value)
|
||||
{
|
||||
v4_cell v; int big;
|
||||
if (opcode_of(name) >= 0 || is_reserved(name) || is_label_def(name) || number_of(name, &v, &big)) {
|
||||
if (opcode_of(name) >= 0 || is_reserved(name) || is_label_def(name) || number_of(name, &v, &big) || name[0] == '&') {
|
||||
fail(t, "cannot be used as a name", name);
|
||||
return;
|
||||
}
|
||||
@@ -427,6 +427,14 @@ static void one_token(v4_text *t, reader *r, const char *tok)
|
||||
return;
|
||||
}
|
||||
|
||||
if (tok[0] == '&' && tok[1] != 0) { /* the address of a word, as a literal */
|
||||
s = find(t, tok + 1);
|
||||
if (!s || s->kind != KIND_WORD) { fail(t, "& needs a word that is already defined", tok + 1); return; }
|
||||
v4_asm_lit(as, s->value);
|
||||
check_asm(t, tok);
|
||||
return;
|
||||
}
|
||||
|
||||
s = find(t, tok);
|
||||
if (s && s->kind == KIND_MACRO) {
|
||||
if (r->depth == V4_TEXT_MAX_DEPTH + 1u) { fail(t, "macros nested too deep", tok); return; }
|
||||
@@ -444,6 +452,22 @@ static void one_token(v4_text *t, reader *r, const char *tok)
|
||||
check_asm(t, tok);
|
||||
return;
|
||||
}
|
||||
if (!s) { /* CONST+N: a constant and an offset, one literal */
|
||||
const char *plus = strrchr(tok, '+');
|
||||
if (plus && plus != tok && plus[1] != 0) {
|
||||
char left[V4_TEXT_MAX_TOKEN + 1u];
|
||||
const v4_text_symbol *c;
|
||||
size_t len = (size_t)(plus - tok);
|
||||
memcpy(left, tok, len);
|
||||
left[len] = 0;
|
||||
c = find(t, left);
|
||||
if (c && c->kind == KIND_CONST && number_of(plus + 1, &v, &big) && !big) {
|
||||
v4_asm_lit(as, (v4_cell)((v4_ucell)c->value + (v4_ucell)v));
|
||||
check_asm(t, tok);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
branch(t, V4_OP_CALL, tok, 0); /* a word, defined already or later */
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user