feat(v4.0.0): every error is raised and ends the line (D-18)

Ruled 2026-10-04: guard all errors.  The errors that set NODE-ERROR and
let the line run on now stop it at once, with a message.

- A store of a non-zero code to NODE-ERROR is a trap, a sixth kind of
  fault: nothing after it executes, the return stack is emptied, and the
  data stack is left as the word left it.  Not attached, NODE-ERROR is
  plain memory, as the tests below the prompt use it.
- The capsule's words store a code where they stored -1, and the prompt's
  (RAISED) prints its message: Negative count, Not a number, Number too
  long, Not a character, Dictionary full, Name missing, Control structure
  mismatch, Control structures too deep.
- ' and COMPILE and [COMPILE] of a word that is not there say
  UNKNOWN WORD: 'xxx', as the interpreter does.
- tests: the trap in test_exec.c; every message from the prompt, with the
  rest of the line not run and the stack kept, in test_host_quit.c.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rajames
2026-10-04 20:13:23 -04:00
co-authored by Claude Opus 5.5
parent 644bfc0a25
commit dc7e37ba5c
12 changed files with 181 additions and 38 deletions
+9 -1
View File
@@ -15,6 +15,12 @@ void v4_node_reset(v4_node *n)
v4_node_console_input_attach(n, -1, -1);
v4_node_fault_attach(n, -1);
v4_node_stack_regs_attach(n, -1, -1);
v4_node_error_attach(n, -1);
}
void v4_node_error_attach(v4_node *n, v4_cell addr)
{
n->error_reg = addr;
}
int v4_node_addr_ok(v4_cell addr)
@@ -45,7 +51,7 @@ void v4_node_fault(v4_node *n, unsigned kind, v4_cell addr)
n->fault_addr = addr;
n->faults++;
v4_rstack_clear(&n->rs);
v4_dstack_clear(&n->ds);
if (kind != V4_FAULT_RAISED) v4_dstack_clear(&n->ds);
if (n->fault_vector >= 0) n->p = n->fault_vector + (v4_cell)kind;
else n->stopped = 1;
}
@@ -80,6 +86,8 @@ void v4_node_store(v4_node *n, v4_cell addr, v4_cell value)
if (addr == n->rstack_reg) { v4_rstack_clear(&n->rs); return; }
if (!v4_node_addr_ok(addr)) return;
n->mem[(unsigned)addr] = value;
/* NODE-ERROR: a non-zero code raises an error. -1 when not attached. */
if (addr == n->error_reg && value != 0) v4_node_fault(n, V4_FAULT_RAISED, value);
}
v4_cell v4_node_fetch(v4_node *n, v4_cell addr)