feat(v4): the system's UM*, UM/MOD, D+, DNEGATE, Q.* and Q./ call the ROM
MACHINE.md 2.2. Each is its entry's address, push and ;. Every node the tests make carries the host ROM (host_load, Hera's births, the depth and mesh tests' own nodes), and a division by zero inside the ROM returns to the prompt (hosted-check). test_host_quit's fetch outside memory moves past the ROM's range: 16384 is the ROM's first word now the tests' system has its ROM, as the product's always had. dict_hash 0xfec8c47cfc6f437f. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
11b5d402b1
commit
afd9d46d29
@@ -126,6 +126,65 @@ static int entry_jumps_to(const v4_cell *rom, unsigned i, const char *sym, const
|
||||
&& v4_iword_branch(V4_ROM_BASE + (v4_cell)i, w, 0) == (v4_cell)target;
|
||||
}
|
||||
|
||||
/* THE SYSTEM CALLS THE ROM. The system as text.c builds it (host_load, the
|
||||
* ROM attached): each of the six words is a literal of its entry's address,
|
||||
* then push, then ; -- it goes to the entry and the entry's ; returns to the
|
||||
* word's caller -- and it gives the table's results. On a node with no ROM
|
||||
* the call faults rather than computing anything. */
|
||||
static v4_text tx;
|
||||
static int system_cases(void)
|
||||
{
|
||||
static const char *const files[] = {
|
||||
#define SYS_FILE_NAME(file) #file ".f18",
|
||||
V4_SYS_FILES(SYS_FILE_NAME)
|
||||
#undef SYS_FILE_NAME
|
||||
};
|
||||
unsigned k;
|
||||
if (!host_load(&tx, &n, files, (unsigned)(sizeof files / sizeof files[0])) || !v4_text_finish(&tx)) {
|
||||
printf(" the system does not assemble: %s\n", v4_text_error(&tx));
|
||||
return 0;
|
||||
}
|
||||
#define CHECK_CALLS(i, routine, forth, effect) { \
|
||||
v4_cell w = v4_text_word(&tx, forth); \
|
||||
v4_iword iw = w >= 0 ? (v4_iword)((v4_ucell)n.mem[w] & 0xFFFFFFFFu) : 0; \
|
||||
CHECK(w >= 0 && v4_iword_op(iw, 0) == V4_OP_FETCH_P && v4_iword_op(iw, 1) == V4_OP_PUSH && v4_iword_op(iw, 2) == V4_OP_SEMI \
|
||||
&& n.mem[w + 1] == V4_ROM_BASE + (v4_cell)(i), "the system's %s is the ROM's entry %d, then push and ;", forth, i); }
|
||||
V4_ROM_MATH_ENTRIES(CHECK_CALLS)
|
||||
#undef CHECK_CALLS
|
||||
for (k = 0; k < CASES; k++) {
|
||||
static const char *const forth_of[] = {
|
||||
#define FORTH_NAME(i, routine, forth, effect) forth,
|
||||
V4_ROM_MATH_ENTRIES(FORTH_NAME)
|
||||
#undef FORTH_NAME
|
||||
};
|
||||
const math_case *c = &cases[k];
|
||||
v4_cell got[2] = { 0, 0 };
|
||||
unsigned i;
|
||||
int ok;
|
||||
v4_dstack_reset(&n.ds); v4_rstack_reset(&n.rs); v4_exec_reset(&rom_es); v4_heat_reset(&rom_h);
|
||||
n.mem[NODE_ERROR] = 0;
|
||||
v4_dstack_push(&n.ds, CANARY);
|
||||
for (i = 0; i < c->argc; i++) v4_dstack_push(&n.ds, c->in[i]);
|
||||
ok = v4_test_call(&n, &rom_es, &rom_h, v4_text_word(&tx, forth_of[c->entry]), 10000000L) > 0;
|
||||
for (i = c->outc; i-- > 0; ) got[i] = v4_dstack_pop(&n.ds);
|
||||
CHECK(ok && v4_dstack_pop(&n.ds) == CANARY && got[0] == c->out[0] && got[1] == c->out[1] && n.mem[NODE_ERROR] == c->error,
|
||||
"the system's %s, case %u: got %lld %lld error %lld", forth_of[c->entry], k,
|
||||
(long long)got[0], (long long)got[1], (long long)n.mem[NODE_ERROR]);
|
||||
}
|
||||
/* the same system with its ROM taken away: UM* does not return */
|
||||
v4_node_rom_attach(&n, ROM_IMAGE, 0u);
|
||||
v4_dstack_reset(&n.ds); v4_rstack_reset(&n.rs); v4_exec_reset(&rom_es); v4_heat_reset(&rom_h);
|
||||
v4_dstack_push(&n.ds, 12345); v4_dstack_push(&n.ds, 67890);
|
||||
{
|
||||
unsigned faults = n.faults;
|
||||
long r = v4_test_call(&n, &rom_es, &rom_h, v4_text_word(&tx, "UM*"), 100000L);
|
||||
CHECK(r <= 0 && n.faults > faults && n.fault_kind == V4_FAULT_ADDRESS && n.fault_addr == V4_ROM_BASE,
|
||||
"with no ROM, the system's UM* faults at the ROM's address and computes nothing: returned %ld, %u faults, kind %u at %lld",
|
||||
r, n.faults - faults, n.fault_kind, (long long)n.fault_addr);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf("v4 ROM math tests: V4_CELL_BITS=%d\n", V4_CELL_BITS);
|
||||
@@ -151,6 +210,8 @@ int main(void)
|
||||
cases_on("host", ROM_IMAGE, ROM_IMAGE_WORDS);
|
||||
cases_on("mesh", MESH_ROM, MESH_ROM_WORDS);
|
||||
|
||||
CHECK(system_cases(), "the system the tests build with text.c");
|
||||
|
||||
printf(" %d checks, %d failures\n", checks, failures);
|
||||
return failures != 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user