COLD set VOC-LINK to 0, assuming the sealed system has one vocabulary. With starshipos.4th sealed in, STARSHIPOS fell out of the chain after COLD. A word defined in it then forgotten, or COLDed away, hung the node. ACL-INIT-PRIMITIVES would also have skipped its words. FORGET's loop is now (PRUNE-ALL). It drops the vocabularies above (Q) and prunes the lists of those that stay. FORGET calls it as before, and COLD calls it with the sealed DP. No new cell and no new word. Test first in test_mesh_boot.c: FORGET and COLD of a word in STARSHIPOS, and STARSHIPOS's own words staying. The before-run hung and was stopped at 500 s. After: 109 checks pass, POST is 990/990, all 52 64-bit tests and test-32 pass, ASan/UBSan are clean, and the amd64 build is clean. Found by Captain Bob's "make sure we're not applying incorrect logic". Ruled: fix first, then the protocol. Logs are in logs/20261118-cold-vocabularies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
204 lines
10 KiB
Plaintext
204 lines
10 KiB
Plaintext
\ system.f18 -- words about the dictionary as a whole: WORDS, FORGET, FENCE.
|
|
\
|
|
\ DECOMPOSITION.md 5.13 and 5.15. Part of the compiler capsule; rests on
|
|
\ dict.f18, quit.f18 and forth.f18.
|
|
\
|
|
\ Constants the loader supplies:
|
|
\ (FENCE) word address of the variable: FORGET will not remove an entry
|
|
\ that starts below the address it holds
|
|
\ VOC-LINK word address of the variable: the newest vocabulary, or 0
|
|
\ (BOOT) word address of two cells: DP and (LATEST) as the loader left them
|
|
\ HEAT-OP ANTICLOCK word addresses of HEAT-OP[0] and ANTICLOCK, the heat
|
|
\ registers (DECOMPOSITION.md section 7): read-only
|
|
|
|
\ ( -- ) as v3: what is defined now FORGET will not remove -- the fence is
|
|
\ raised to HERE (v3's table; no standard defines FENCE, ruled 2026-11-14).
|
|
set HDR-NFA here ", FENCE #id, #, 0 #, HDR-NFA #, HDR-LINK set HDR-LINK here
|
|
: FENCE DP a! @ 3 + 2/ 2/ (FENCE) a! ! ;
|
|
|
|
\ ---- the heat registers (DECOMPOSITION.md section 7; #189) -----------------------
|
|
\ Captain Bob, 2026-11-12: "Add HEAT-OP". The node counts every instruction it
|
|
\ retires, by opcode, and the anti-clock ticks once for each; these read them.
|
|
\ ( op -- n ) how many times opcode op has retired; op is taken mod 32
|
|
set HDR-NFA here ", HEAT-OP@ #id, #, 0 #, HDR-NFA #, HDR-LINK set HDR-LINK here
|
|
: HEAT-OP@ 31 and HEAT-OP + b! @b ;
|
|
\ ( -- n ) the anti-clock: one tick per instruction retired
|
|
set HDR-NFA here ", ANTICLOCK@ #id, #, 0 #, HDR-NFA #, HDR-LINK set HDR-LINK here
|
|
: ANTICLOCK@ ANTICLOCK b! @b ;
|
|
|
|
\ ---- vocabularies (FORTH-79) ----------------------------------------------------
|
|
\ A vocabulary is two cells: its head -- the xt of its newest entry, or 0 --
|
|
\ and the address of the vocabulary defined before it, or 0. VOC-LINK holds
|
|
\ the newest one's address. FORTH's head is (LATEST) and it is in no chain.
|
|
set HDR-NFA here ", CONTEXT #id, #, 8 #, HDR-NFA #, HDR-LINK set HDR-LINK here : CONTEXT' CONTEXT ;
|
|
set HDR-NFA here ", CURRENT #id, #, 8 #, HDR-NFA #, HDR-LINK set HDR-LINK here : CURRENT' CURRENT ;
|
|
|
|
\ FORTH-79: the primary vocabulary; it becomes the CONTEXT vocabulary.
|
|
set HDR-NFA here ", FORTH #id, #, 1 #, HDR-NFA #, HDR-LINK set HDR-LINK here
|
|
: FORTH (LATEST) CONTEXT a! ! ;
|
|
\ FORTH-79: new definitions go into the CONTEXT vocabulary from now on.
|
|
set HDR-NFA here ", DEFINITIONS #id, #, 0 #, HDR-NFA #, HDR-LINK set HDR-LINK here
|
|
: DEFINITIONS CONTEXT a! @ CURRENT a! ! ;
|
|
|
|
\ VOCABULARY xxx FORTH-79: xxx is a new, empty list of words; executing
|
|
\ xxx makes it the CONTEXT vocabulary. When a search of it finds nothing,
|
|
\ FORTH is searched.
|
|
: (DOVOC) pop CONTEXT a! ! ;
|
|
set HDR-NFA here ", VOCABULARY #id, #, 0 #, HDR-NFA #, HDR-LINK set HDR-LINK here
|
|
: VOCABULARY
|
|
&(DOVOC) (C)+3 a! ! (DATA) (C)+8 a! @ if NONE drop
|
|
0 , VOC-LINK a! @ , HERE -2 + VOC-LINK a! ! ;
|
|
NONE: drop ;
|
|
|
|
\ ( cell -- ) print the name of the vocabulary whose head cell this is
|
|
: (.VOC)
|
|
dup (LATEST) xor if F drop -1 + -2 + a! @ 4* COUNT 31 and jump TYPE
|
|
F: drop drop $54524F46 (EMIT4) $48 (EMIT4) ;
|
|
|
|
\ ( -- ) as v3's, but true: where names are looked for, and where new ones go
|
|
set HDR-NFA here ", ORDER #id, #, 0 #, HDR-NFA #, HDR-LINK set HDR-LINK here
|
|
: ORDER
|
|
$72616553 (EMIT4) $6F206863 (EMIT4) $72656472 (EMIT4) $203A (EMIT4)
|
|
CONTEXT a! @ dup (.VOC) SPACE
|
|
(LATEST) xor if ONLY drop (LATEST) (.VOC) jump TWO
|
|
ONLY: drop
|
|
TWO: CR
|
|
$72727543 (EMIT4) $3A746E65 (EMIT4) $20 (EMIT4)
|
|
CURRENT a! @ (.VOC) jump CR
|
|
|
|
\ ( -- ) the names in the CONTEXT vocabulary, the newest first, a blank after
|
|
\ each, a new line whenever one has passed column 64. Hidden entries -- a
|
|
\ definition under way -- are not shown. (Q)+0 is the column.
|
|
set HDR-NFA here ", WORDS #id, #, 0 #, HDR-NFA #, HDR-LINK set HDR-LINK here
|
|
: WORDS
|
|
0 (Q) a! !
|
|
CONTEXT a! @ a! @
|
|
L: if DONE
|
|
dup -3 + a! @ 2 and if SHOW drop jump NXT
|
|
SHOW: drop
|
|
dup -2 + a! @ 4* COUNT 31 and \ xt baddr u
|
|
dup (Q) a! @ + 1 + !
|
|
TYPE SPACE
|
|
(Q) a! @ -64 + -if WRAP drop jump NXT
|
|
WRAP: drop CR 0 (Q) a! !
|
|
NXT: -1 + a! @ jump L
|
|
DONE: drop jump CR
|
|
set HDR-NFA here ", VLIST #id, #, 0 #, HDR-NFA #, HDR-LINK set HDR-LINK here
|
|
: VLIST jump WORDS
|
|
|
|
\ ( cell -- ) take off a vocabulary's list every entry at or above the
|
|
\ address in (Q)+0. The newest are first, so it stops at the first one below.
|
|
: (PRUNE)
|
|
(Q)+1 a! !
|
|
L: (Q)+1 a! @ a! @ if DONE
|
|
dup (Q) a! @ inv + 1 + -if CUT drop drop ;
|
|
CUT: drop -1 + a! @ (Q)+1 a! @ a! ! jump L
|
|
DONE: drop ;
|
|
|
|
\ ( -- ) take off every list every entry at or above the address in (Q)+0:
|
|
\ FORTH's, and each vocabulary's that stays; a vocabulary defined at or above
|
|
\ it goes from the chain. FORGET does this for what it forgets, and COLD for
|
|
\ everything since the seal, so a vocabulary sealed into the system stays.
|
|
: (PRUNE-ALL)
|
|
(LATEST) (PRUNE)
|
|
V: VOC-LINK a! @ if PRUNED \ vocabularies that go
|
|
dup (Q) a! @ inv + 1 + -if GONE drop jump KEPT
|
|
GONE: drop 1 + a! @ VOC-LINK a! ! jump V
|
|
KEPT: P: if PRUNED \ the lists of those that stay
|
|
dup (PRUNE) 1 + a! @ jump P
|
|
PRUNED: drop ;
|
|
|
|
\ FORGET xxx FORTH-79: remove xxx and every word defined after it, in
|
|
\ whatever vocabulary; the space they took is free again. A vocabulary that
|
|
\ goes is no longer CONTEXT or CURRENT: FORTH is. A word that is not there
|
|
\ is an error, and so is one below the fence, which is where the capsule's own
|
|
\ words are (code 10, "Protected word").
|
|
set HDR-NFA here ", FORGET #id, #, 0 #, HDR-NFA #, HDR-LINK set HDR-LINK here
|
|
: FORGET
|
|
32 WORD (LOOKUP) if MISSING
|
|
-2 + a! @ \ where its name starts
|
|
dup (FENCE) a! @ inv + 1 + -if OK \ name - fence
|
|
drop drop NODE-ERROR b! 10 !b ;
|
|
OK: drop
|
|
dup (Q) a! ! 4* DP a! ! \ the space from its name on
|
|
(PRUNE-ALL)
|
|
CONTEXT a! @ (Q) a! @ inv + 1 + -if C1 drop jump C2
|
|
C1: drop (LATEST) CONTEXT a! !
|
|
C2: CURRENT a! @ (Q) a! @ inv + 1 + -if C3 drop jump TOLD
|
|
C3: drop (LATEST) CURRENT a! !
|
|
TOLD: (Q) a! @ 4* NAME> -4 + a! @ (NEXT-ID) a! ! \ their IDs are free again: the newest are
|
|
(Q) a! @ jump (FORGOTTEN) \ the kernel's records of them go too (dict.f18)
|
|
MISSING: drop (UNKNOWN) drop ;
|
|
|
|
\ ---- the system as a whole -------------------------------------------------------
|
|
\ (BOOT) is two cells the loader fills when the capsule is in place: DP and
|
|
\ the newest FORTH entry as they then are. COLD goes back to them.
|
|
|
|
\ FORTH-79: execute to be sure a FORTH-79 system is there. It is: nothing
|
|
\ happens. (v3's prints two lines and leaves a flag.)
|
|
set HDR-NFA here ", 79-STANDARD #id, #, 0 #, HDR-NFA #, HDR-LINK set HDR-LINK here
|
|
: 79-STANDARD ;
|
|
|
|
\ ( -- ) which system this is, and its cell width
|
|
set HDR-NFA here ", VERSION #id, #, 0 #, HDR-NFA #, HDR-LINK set HDR-LINK here
|
|
: VERSION
|
|
$72617453 (EMIT4) $74726F46 (EMIT4) $34762068 (EMIT4) $302E302E (EMIT4) $38314620 (EMIT4) $20 (EMIT4)
|
|
N-1 1 + 0 U-DOT-R $7469622D (EMIT4) CR ;
|
|
|
|
\ ( -- ) clear the screen and put the cursor at the top, as v3: ESC [2J ESC [H
|
|
set HDR-NFA here ", PAGE #id, #, 0 #, HDR-NFA #, HDR-LINK set HDR-LINK here
|
|
: PAGE 27 EMIT 91 EMIT 50 EMIT 74 EMIT 27 EMIT 91 EMIT 72 jump EMIT
|
|
|
|
\ ( -- ) as v3's message, and then ABORT: both stacks emptied, the prompt
|
|
set HDR-NFA here ", WARM #id, #, 0 #, HDR-NFA #, HDR-LINK set HDR-LINK here
|
|
: WARM
|
|
$54524F46 (EMIT4) $39372D48 (EMIT4) $72615720 (EMIT4) $7453206D (EMIT4) $747261 (EMIT4) CR
|
|
$74737953 (EMIT4) $72206D65 (EMIT4) $61747365 (EMIT4) $64657472 (EMIT4) $2E (EMIT4) CR
|
|
jump ABORT
|
|
|
|
\ ( -- ) the system as it was when the capsule had just been loaded:
|
|
\ everything defined since is gone, the vocabularies are as sealed, numbers are
|
|
\ decimal, the block buffers are empty. Then as WARM.
|
|
set HDR-NFA here ", COLD #id, #, 0 #, HDR-NFA #, HDR-LINK set HDR-LINK here
|
|
: COLD
|
|
(BOOT) a! @ DP a! !
|
|
(BOOT)+1 a! @ (LATEST) a! !
|
|
(BOOT) a! @ 2/ 2/ (FENCE) a! !
|
|
(BOOT-ID) a! @ (NEXT-ID) a! !
|
|
(LATEST) CONTEXT a! ! (LATEST) CURRENT a! !
|
|
(BOOT) a! @ 2/ 2/ (Q) a! ! (PRUNE-ALL) \ the vocabularies as sealed, with what was sealed in them
|
|
10 BASE a! ! 0 SCR a! ! 2 (LOG-LEVEL) a! ! 0 (ACL-HOOK) a! ! EMPTY-BUFFERS
|
|
(BOOT) a! @ 2/ 2/ (FORGOTTEN) \ the kernel's records of what has gone go too (dict.f18)
|
|
$54524F46 (EMIT4) $39372D48 (EMIT4) $6C6F4320 (EMIT4) $74532064 (EMIT4) $747261 (EMIT4) CR
|
|
$74737953 (EMIT4) $69206D65 (EMIT4) $6974696E (EMIT4) $7A696C61 (EMIT4) $2E6465 (EMIT4) CR
|
|
jump ABORT
|
|
|
|
\ ---- deferred words (as v3) -------------------------------------------------------
|
|
\ DEFER xxx makes xxx, which does whatever word it has been given:
|
|
\ ' yyy IS xxx gives it one; DEFER@ xxx leaves the one it has. A deferred
|
|
\ word with none is an error (code 15, "Deferred word not set"). DEFER marks
|
|
\ its word with flag 128 (dict.f18); IS and DEFER@ refuse any other word, as v3
|
|
\ does ("was not created by DEFER"): error 22, "Not deferred".
|
|
: (DODEFER)
|
|
pop a! @ if UNSET push ; \ go to it: it returns to xxx's caller
|
|
UNSET: drop NODE-ERROR b! 15 !b ;
|
|
set HDR-NFA here ", DEFER #id, #, 0 #, HDR-NFA #, HDR-LINK set HDR-LINK here
|
|
: DEFER &(DODEFER) (C)+3 a! ! (DATA) (C)+8 a! @ if NONE drop LATEST (FLAGS) a! @ 128 OR ! 0 jump , NONE: drop ;
|
|
: (is!) a! ! ;
|
|
\ ( "name" -- addr ) the data address of the deferred word named next
|
|
: (DEFERRED)
|
|
32 WORD (LOOKUP) if MISSING
|
|
dup (FLAGS) a! @ 128 and if NOTDEF drop jump PFA
|
|
NOTDEF: drop drop NODE-ERROR b! 22 !b ;
|
|
MISSING: drop jump (UNKNOWN)
|
|
: (defer@) a! @ ;
|
|
set HDR-NFA here ", IS #id, #, 1 #, HDR-NFA #, HDR-LINK set HDR-LINK here
|
|
: IS
|
|
(DEFERRED) STATE a! @ if NOW drop (LIT,) &(is!) jump (CALL,)
|
|
NOW: drop jump (is!)
|
|
set HDR-NFA here ", DEFER@ #id, #, 1 #, HDR-NFA #, HDR-LINK set HDR-LINK here
|
|
: DEFER@
|
|
(DEFERRED) STATE a! @ if NOW drop (LIT,) &(defer@) jump (CALL,)
|
|
NOW: drop jump (defer@)
|
|
|