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
+10 -2
View File
@@ -5,7 +5,7 @@
\ written here as text for the text assembler (v4/include/v4/text.h).
\
\ Constants the loader supplies: N-1 (cell bits - 1), NODE-ERROR, CONSOLE-TX,
\ CONSOLE-RX, CONSOLE-STATUS, BASE.
\ CONSOLE-RX, CONSOLE-STATUS, BASE, (EMIT-HOOK).
\
\ ERRORS (D-18). A word that finds an error takes its arguments off the stack
\ and stores a code in NODE-ERROR. On a node with a prompt that store is a
@@ -91,8 +91,16 @@ header CMOVE
DONE: drop drop drop ;
\ ---- section 5.10: the console -------------------------------------------
\ EMIT sends the character to the console, unless (EMIT-HOOK) holds the xt
\ of a word: then that word is given it instead ( c -- ), and returns to
\ EMIT's caller. Everything the node prints goes through EMIT, so a hook
\ sees all of it. The prompt takes the hook off at the end of every line
\ (quit.v4), so that nothing can leave the console silent. POST uses it
\ to compare what a case prints (docs/v4.0.0/NUCLEUS.md 6.3).
header EMIT
: EMIT ( c -- ) CONSOLE-TX b! !b ;
: EMIT ( c -- )
(EMIT-HOOK) b! @b if NONE push ;
NONE: drop CONSOLE-TX b! !b ;
header KEY
: KEY ( -- c )
L: CONSOLE-STATUS b! @b if WAIT drop CONSOLE-RX b! @b ;