fix(v4): the final review's six minors in the ROM boot

- Text after start is refused, as text.c refuses it: before it jumps, the
  ROM reads on to the end of the source; blanks, comments and the ends of
  blobs may follow, a token is ERR-AFTER (26), "text after start".
- A token too long where a name, a target or a value is wanted is "name
  too long", as text.c says: (MISSING) reports "missing" only when no error
  came first.  `", keeps "missing", which is text.c's word for both.
- text.c's "address out of range" names the address, not the value.
- The system's source files are one list, v4/sys_files.h: boot.c, the
  harness and the nucleus test are made from it.
- The ROM's error codes and words are one list, v4/rom_errors.h: boot.c's
  messages, host_map.h's ROM_ERR_* and mkmap's ERR-* are made from it.
- node.h says what v4_node_store does with a ROM address (nothing, as for
  any address outside RAM, D-14); test_host_rom_range pins it.

ROM: 2095 words, rom_hash 0x06d0dcb7a0cb41a1.  dict_hash unchanged,
0xe5a57f3eb72ff94a.  make -C v4 test test-32 hosted-check pass.  QEMU:
amd64, aarch64, riscv64 to ok>, POST 538/538, POST: PASSED.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rajames
2026-10-15 17:10:45 -04:00
co-authored by Claude Opus 5.5
parent ff75e69e91
commit a28b5f2230
18 changed files with 646 additions and 89 deletions
+39 -1
View File
@@ -11,6 +11,7 @@
#include "rom_harness.h"
#include "v4/text.h"
#include "rom_asm_cases.h"
#include "v4/rom_errors.h"
static int failures = 0, checks = 0;
#define CHECK(c,...) do{checks++; if(!(c)){failures++; printf("FAIL %s:%d: ",__FILE__,__LINE__); printf(__VA_ARGS__); printf("\n");}}while(0)
@@ -38,7 +39,7 @@ static v4_cell code_of(const char *m)
{ "write the number", ROM_ERR_FETCH_P }, { "too many unresolved", ROM_ERR_REFS },
{ "not a value", ROM_ERR_VALUE }, { "not a number", ROM_ERR_VALUE },
{ "too many names", ROM_ERR_NAMES }, { "out of name space", ROM_ERR_NAMES },
{ "address out of range", ROM_ERR_RANGE }, { "without", ROM_ERR_MISSING },
{ "address out of range", ROM_ERR_RANGE }, { "text after start", ROM_ERR_AFTER }, { "without", ROM_ERR_MISSING },
};
unsigned i;
for (i = 0; i < sizeof map / sizeof map[0]; i++) if (strstr(m, map[i].s)) return map[i].c;
@@ -246,6 +247,43 @@ int main(void)
snprintf(t, sizeof t, "store %ld 5", (long)V4_NODE_WORDS - 1); same(t);
}
/* a token too long where a name or a value is wanted: "name too long", as
* text.c says, not "missing" -- the first error stands */
{
static const char *const forms[] = { "constant %s 5", "constant K %s", "set %s 5", "set S %s", ": %s",
"store %s 5", "store 300 %s", "#, %s", "jump %s", "if %s", "\", %s" };
static char t[160], long_tok[65];
memset(long_tok, 'X', 64); long_tok[64] = 0;
for (i = 0; i < sizeof forms / sizeof forms[0]; i++) { snprintf(t, sizeof t, forms[i], long_tok); same(t); }
}
/* text after start: refused, as text.c refuses it; blanks, comments and
* the blob's end after it are not text */
CHECK(rom_run(": Z ;\nstart Z\n1\n\x04") == 0 && b.mem[ROM_FAILED] == ROM_ERR_AFTER, "text after start: refused (code %ld)",
(long)b.mem[ROM_FAILED]);
CHECK(rom_run(": Z ;\nstart Z \\ a comment\n( and another )\n\x1c\x04") == 1, "comments and a blob's end after start: started (code %ld)",
(long)b.mem[ROM_FAILED]);
{
v4_node_reset(&a);
v4_text_begin(&tx, &a, ROM_ORIGIN);
CHECK(!v4_text_assemble(&tx, ": Z ;\nstart Z\n1\n") && code_of(v4_text_error(&tx)) == ROM_ERR_AFTER,
"text.c refuses text after start too: %s", v4_text_error(&tx));
}
/* the ROM's error messages, as the boot prints them: one list
* (v4/rom_errors.h), its codes 1, 2, 3 ... in order */
{
static const struct { int code; const char *text; } list[] = {
#define E(name, code, text) { code, text },
V4_ROM_ERRORS(E)
#undef E
};
for (i = 0; i < sizeof list / sizeof list[0]; i++) if (list[i].code != (int)i + 1) break;
CHECK(i == sizeof list / sizeof list[0], "the ROM's error codes run 1, 2, 3 ... : entry %u is %d", i, list[i].code);
CHECK(ROM_ERR_RANGE == 25 && strcmp(list[ROM_ERR_RANGE - 1].text, "address out of range") == 0, "ROM_ERR_RANGE's message");
CHECK(strcmp(list[ROM_ERR_AFTER - 1].text, "text after start") == 0, "ROM_ERR_AFTER's message");
}
printf("test_host_rom_asm: %d checks, %d failures\n", checks, failures);
return failures != 0;
}