feat(v4.0.0): (CATCH) and (EMIT-HOOK), the two nucleus hooks POST needs

(CATCH): while it is not zero, a line that ends in an error sets it to -1
and ends " ok" instead of " ERROR".  (EMIT-HOOK): the xt of a word that is
given each character EMIT would send to the console.  The prompt loop sets
(EMIT-HOOK) to 0 at the end of every line.  docs/v4.0.0/NUCLEUS.md 6.3,
amended: it said one nucleus word would do.

Verified: make -C v4 test passes at both widths; by hand at the hosted
prompt, an unknown word and a division by zero are caught, the output hook
receives every character, and an uncaught error still says ERROR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rajames
2026-10-05 15:49:43 -04:00
co-authored by Claude Opus 5.5
parent 506b645726
commit ed6b11ad88
4 changed files with 45 additions and 8 deletions
+16 -5
View File
@@ -156,11 +156,22 @@ departure is reported.
### 6.3 Form
`post79.4th` defines a small harness in FORTH — a case is written
`T{ 1 2 3 ROT -> 2 3 1 }T` — and a tally. Cases that check printed output
or an expected error use harness words for those. The harness needs one
thing from the nucleus that FORTH-79 does not provide: a way to run a case
and regain control if it raises an error. That is one nucleus word.
`post79.4th` defines a small harness in FORTH and a tally. The harness
needs two things from the nucleus that FORTH-79 does not provide. Both are
variables an assembled word consults, and both have FORTH names:
| Variable | Consulted by | Effect while not zero |
|---|---|---|
| `(CATCH)` | the prompt loop (`quit.v4`) | A line that ends in an error does not say `ERROR`: `(CATCH)` is set to −1 and the line ends ` ok`. POST can then go on to its next case, and can check a case that must fail. |
| `(EMIT-HOOK)` | `EMIT` (`core.v4`) | It holds the xt of a word ( c -- ) that is given each character instead of the console. POST uses it to compare what a case prints, and it keeps the messages of expected errors out of the boot log. |
The prompt loop sets `(EMIT-HOOK)` to 0 at the end of every line, so the
console cannot be left silent. (This section first said one nucleus word
would do; reading `quit.v4` and `core.v4` showed it takes these two.
Amended 2026-10-05.)
An error always ends the line it is on, so a case is several short lines
and the harness words work across them.
After the last case POST prints the number of cases, passes and failures,
and names each failing case.