feat(v4): every word but the ten is called, so it can be checked
Plan 2026-10-20 (ENGINE step 4), Task A2, for #189. Captain Bob, 2026-11-13: "The ten"; "Accept it". - compile.f18 (COMPILE,): a word is copied in line only when it is flagged in-line and compile-only (24) -- the ten that work on the return stack, >R R> R@ I J LEAVE and the later UNLOOP 2>R 2R> 2R@. Every other word, in-line ones too, is a call the hook at `call` sees. - EXECUTE calls the xt: `call xt` (opcode 3, slot 0) and a ; in (EXEC), run. INTERPRET runs a word by (GO): `call xt` and `jump (IL)` in (RUNX), entered by a jump, at the old return-stack depth. - host_map.h: (EXEC) BUF0_W-22, (RUNX) BUF0_W-115, from what was free. - Its cost, accepted: one return entry at the bottom of a chain (30 deep from the prompt, not 31) and one per explicit EXECUTE while its word runs; the hosted boot +2.4% (2.917 s to 2.987 s), instructions +0.4%. - Tests first (logs/20261113-045122/a2): inline_words_are_called, residue_stays_inline, execute_passes_the_hook, rstack_kept_across_call, abandoned_definition_not_called -- 3 of 1096 failed before. The depth checks moved to the new figures; SEE shows the calls; two layout checks use in-line test words; 2>R 2R@ 2R> checked in test_host_quit. - DECOMPOSITION.md EXECUTE, the plan's A2 and rulings, FABRIC-3 XLVIII.22. Suite: test, test-32 99 programs 0 failures; v4-checks 79 under the sanitizers 0 failures, the hosted builds alike; hosted POST 539/539. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
This commit is contained in:
+34
-13
@@ -11,10 +11,13 @@
|
||||
\ instruction words, and compiling a word into one lays down a call to it.
|
||||
\ Two flags on an entry (dict.f18) change that:
|
||||
\ inline its code is a straight run of opcodes and literals ending
|
||||
\ in ; -- that run is copied in place of a call. Everything
|
||||
\ that touches the return stack must be, since a call would
|
||||
\ bury what it works on (DECOMPOSITION.md 0, fate IN).
|
||||
\ in ; -- that run can be copied in place of a call.
|
||||
\ compile-only it may not be executed by the interpreter.
|
||||
\ Only a word with both is copied in line: the words that work on the return
|
||||
\ stack (>R R> R@ I J LEAVE UNLOOP 2>R 2R> 2R@), which a call would bury
|
||||
\ (DECOMPOSITION.md 0, fate IN). Every other word is called, in-line ones
|
||||
\ too, so that the node's hook at `call` sees it (plan 2026-10-20, Task A2;
|
||||
\ #189; Captain Bob, 2026-11-13: "The ten").
|
||||
\ An immediate word is executed even when compiling.
|
||||
\
|
||||
\ THE STACKS ARE SHORT: written for ten cells of data and nine return entries
|
||||
@@ -38,6 +41,8 @@
|
||||
\ (C)+9 the error code a line is being abandoned with
|
||||
\ (CFP) word address of the control-flow stack's pointer
|
||||
\ CFBASE CFEND word addresses of its first cell and of the cell past its last
|
||||
\ (EXEC) word address of two cells: EXECUTE's call, and the ; after it
|
||||
\ (RUNX) word address of two cells: INTERPRET's call, and the jump back
|
||||
|
||||
macro ROT push SWAP pop SWAP endmacro
|
||||
|
||||
@@ -94,10 +99,11 @@ macro ROT push SWAP pop SWAP endmacro
|
||||
NOP: drop drop jump NXT
|
||||
END: drop ;
|
||||
|
||||
\ ( xt -- ) compile the word at xt: in line if it is flagged so, else a call
|
||||
\ ( xt -- ) compile the word at xt: in line if it is flagged in-line and
|
||||
\ compile-only (24), else a call
|
||||
: (COMPILE,)
|
||||
dup -3 + a! @ 8 and if CALL drop jump (INLINE,)
|
||||
CALL: drop jump (CALL,)
|
||||
dup -3 + a! @ 24 and -24 + if INL drop jump (CALL,)
|
||||
INL: drop jump (INLINE,)
|
||||
|
||||
\ ---- access control (5.20) -------------------------------------------------------
|
||||
\ Each entry's flags cell also holds its access control fields:
|
||||
@@ -144,7 +150,13 @@ macro ROT push SWAP pop SWAP endmacro
|
||||
: (.WORD) WBUF COUNT jump TYPE
|
||||
|
||||
set HDR-NFA here ", EXECUTE #, 0 #, HDR-NFA #, HDR-LINK set HDR-LINK here
|
||||
: EXECUTE ( xt -- ) push ;
|
||||
\ It calls the word, so that the hook at `call` sees it (#189, ENGINE.md 6,
|
||||
\ ruled 2026-10-20): a `call xt` instruction word -- `call`, opcode 3, in slot
|
||||
\ 0, the address in the 27 bits below it -- is put in (EXEC) with a ; after
|
||||
\ it, and run. The word returns to the ;, which returns to EXECUTE's caller.
|
||||
\ An EXECUTE inside the word rewrites only the call, which has been run.
|
||||
: EXECUTE ( xt -- )
|
||||
$07FFFFFF and $18000000 xor (EXEC) a! ! 0 (EXEC)+1 a! ! (EXEC) push ;
|
||||
|
||||
\ ---- the interpreter's inner loop ---------------------------------------------
|
||||
|
||||
@@ -183,25 +195,34 @@ set HDR-NFA here ", EXECUTE #, 0 #, HDR-NFA #, HDR-LINK set HDR-LINK here
|
||||
\ UNKNOWN WORD: 'xxx' xxx: compile-only
|
||||
set HDR-NFA here ", INTERPRET #, 0 #, HDR-NFA #, HDR-LINK set HDR-LINK here
|
||||
: INTERPRET
|
||||
L: 32 WORD dup C@ if EOL
|
||||
: (IL) 32 WORD dup C@ if EOL
|
||||
drop (LOOKUP) if NUM
|
||||
dup -3 + a! @ \ xt flags
|
||||
STATE a! @ if INTERP
|
||||
drop 1 and if COMP \ compiling: immediate words still run
|
||||
drop (ACL?) EXECUTE jump L
|
||||
COMP: drop (ACL?) (COMPILE,) jump L
|
||||
drop (ACL?) jump (GO)
|
||||
COMP: drop (ACL?) (COMPILE,) jump (IL)
|
||||
INTERP: drop 16 and if RUN
|
||||
drop drop (.WORD) \ ": compile-only"
|
||||
$6F63203A (EMIT4) $6C69706D (EMIT4) $6E6F2D65 (EMIT4) $796C (EMIT4) CR
|
||||
jump (ABANDON)
|
||||
RUN: drop (ACL?) EXECUTE jump L
|
||||
RUN: drop (ACL?) jump (GO)
|
||||
NUM: drop (NUM?) if BAD
|
||||
drop
|
||||
STATE a! @ if KEEP drop (LIT,) jump L
|
||||
KEEP: drop jump L
|
||||
STATE a! @ if KEEP drop (LIT,) jump (IL)
|
||||
KEEP: drop jump (IL)
|
||||
BAD: drop drop (UNKNOWN) drop jump (ABANDON)
|
||||
EOL: drop drop ;
|
||||
|
||||
\ ( xt -- ) INTERPRET runs a word by a call, so that the hook at `call` sees
|
||||
\ it (#189), and goes on at (IL) after it: `call xt` and `jump (IL)` are put in
|
||||
\ (RUNX), and run. Entered by a jump, it leaves the return stack as deep as
|
||||
\ EXECUTE's tail-jump did, so a word run from the prompt has the room it had.
|
||||
\ A word that interprets (LOAD) rewrites only the call, which has been run.
|
||||
: (GO)
|
||||
$07FFFFFF and $18000000 xor (RUNX) a! !
|
||||
&(IL) $07FFFFFF and $10000000 xor (RUNX)+1 a! ! (RUNX) push ;
|
||||
|
||||
\ ---- state ---------------------------------------------------------------------
|
||||
|
||||
set HDR-NFA here ", [ #, 1 #, HDR-NFA #, HDR-LINK set HDR-LINK here
|
||||
|
||||
@@ -113,6 +113,8 @@ constant -HFLOOR -63186
|
||||
constant DSTACK-DEPTH 16369
|
||||
constant RSTACK-DEPTH 16368
|
||||
constant HEAT-OP 13824
|
||||
constant (EXEC) 14690
|
||||
constant (RUNX) 14597
|
||||
constant ANTICLOCK 13856
|
||||
constant CFBASE 16288
|
||||
constant CFEND 16320
|
||||
|
||||
@@ -113,6 +113,8 @@ constant -HFLOOR -63186
|
||||
constant DSTACK-DEPTH 16369
|
||||
constant RSTACK-DEPTH 16368
|
||||
constant HEAT-OP 13824
|
||||
constant (EXEC) 14690
|
||||
constant (RUNX) 14597
|
||||
constant ANTICLOCK 13856
|
||||
constant CFBASE 16288
|
||||
constant CFEND 16320
|
||||
|
||||
Reference in New Issue
Block a user