feat(v4): mkrom -- the ROM built off the node; it reads tokens
The ROM's source is F18 code in capsules/v4/rom, assembled off the node by v4/tools/mkrom.c with the memory map's constants from v4/tools/mkmap.c (MACHINE.md 2). main.f18 is the entry table payloads call through (2.1); in.f18 reads the console and splits it into tokens exactly as text.c does, the token held packed as a counted string. The ROM's state is a reserved area of the map (host_map.h ROM_*). text.c gains the constant directive, so the off-node assembler and the ROM speak one language. The map also names (NUMBER)'s state, for the next task. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
32753f5479
commit
0f82d8c22a
+17
-1
@@ -65,7 +65,7 @@ static int is_reserved(const char *s)
|
||||
return strcmp(s, ":") == 0 || strcmp(s, "macro") == 0 || strcmp(s, "endmacro") == 0
|
||||
|| strcmp(s, "\\") == 0 || strcmp(s, "(") == 0
|
||||
|| strcmp(s, "FOR") == 0 || strcmp(s, "NEXT") == 0 || strcmp(s, "UNEXT") == 0
|
||||
|| strcmp(s, "header") == 0 || flag_of(s) != 0;
|
||||
|| strcmp(s, "header") == 0 || strcmp(s, "constant") == 0 || flag_of(s) != 0;
|
||||
}
|
||||
|
||||
static int is_label_def(const char *s)
|
||||
@@ -342,6 +342,21 @@ static void define_macro(v4_text *t, reader *r)
|
||||
define(t, name, KIND_MACRO, (v4_cell)start);
|
||||
}
|
||||
|
||||
/* `constant NAME VALUE`: as v4_text_constant, written in the text. */
|
||||
static void constant_directive(v4_text *t, reader *r)
|
||||
{
|
||||
char name[V4_TEXT_MAX_TOKEN + 1u], value[V4_TEXT_MAX_TOKEN + 1u];
|
||||
v4_cell v;
|
||||
int big;
|
||||
|
||||
if (r->depth != 1) { fail(t, "not allowed in a macro", "constant"); return; }
|
||||
if (!next_token(t, r, name)) { if (!t->failed) fail(t, "constant without a name", NULL); return; }
|
||||
if (!next_token(t, r, value)) { if (!t->failed) fail(t, "constant without a value", name); return; }
|
||||
if (!number_of(value, &v, &big)) { fail(t, "not a number", value); return; }
|
||||
if (big) { fail(t, "number does not fit a cell", value); return; }
|
||||
define(t, name, KIND_CONST, v);
|
||||
}
|
||||
|
||||
static void one_token(v4_text *t, reader *r, const char *tok)
|
||||
{
|
||||
const v4_text_symbol *s;
|
||||
@@ -365,6 +380,7 @@ static void one_token(v4_text *t, reader *r, const char *tok)
|
||||
return;
|
||||
}
|
||||
if (strcmp(tok, "macro") == 0) { define_macro(t, r); return; }
|
||||
if (strcmp(tok, "constant") == 0) { constant_directive(t, r); return; }
|
||||
if (strcmp(tok, "endmacro") == 0) { fail(t, "endmacro without macro", NULL); return; }
|
||||
|
||||
if (is_label_def(tok)) {
|
||||
|
||||
Reference in New Issue
Block a user