feat(v4): Phase 7 Task 4 -- v3's entropy, TOP-WORDS, WORD-ENTROPY and (- words (#189)

capsules/v4/physics.4th, blocks 8202-8204: ENTROPY@ ENTROPY! RESET-ENTROPY as kernel requests -35..-37 (a
word's heat by the address ' leaves, a data word's too; an error for what is not a word, as v3's);
TOP-WORDS and WORD-ENTROPY in StarForth, printing in v3's form what the kernel gives them through (HOT#)
(HOT) (XT-HEAT), -38..-40 (the i-th hottest in v3's stable order); (- in StarForth, skipping to the
matching close paren with nesting, as v3's code does. Tests first: test_mesh_boot.c 101 checks, 110 on, 98
without opcode physics. Listing: 403 live words. amd64 PASS, word_count=403. Not pushed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
This commit is contained in:
Claude
2026-11-14 01:31:31 +00:00
parent 855632b3c0
commit c64c70bdb7
9 changed files with 167 additions and 3 deletions
+11
View File
@@ -7,10 +7,13 @@
#S ( ud -- 0 0 ) Pictured output: convert digits with # until the number is zero (at least one digit).
' ( -- addr ) ' xxx: the parameter field address of xxx; compiled as a literal when compiling.
( ( -- ) ( text): a comment, ended by the first ); immediate.
(- ( -- ) A comment: the input is skipped to the matching close paren, nesting, as v3's code does (its documentation says to the line's end).
(.") ( -- ) The run time of .": print the string compiled after the call, and go on after it.
(ABORT") ( flag -- ) The run time of ABORT": if flag is not zero, print the string compiled after the call and ABORT.
(BITS) ( -- n ) The number of bits in a cell, counted at run time (forth79.4th; used by U/MOD).
(CONSOLE) ( -- addr ) Variable: the node that what this node prints is sent to, as messages (core.f18).
(HOT#) ( -- n ) How many words have heat (TOP-WORDS's).
(HOT) ( i -- xt heat ) The i-th hottest word, as v3's TOP-WORDS orders them (ties in dictionary order); 0 0 past the last.
(LOG") ( level -- ) The run time of LOG-xxx": print the string compiled after the call if level is at or below LOG-LEVEL.
(LOST) ( -- addr ) Variable: a count of the messages this node has dropped -- nowhere to send them, or no room.
(ME) ( -- addr ) Variable: this node's number in the mesh.
@@ -21,8 +24,11 @@
(TELL-DEFINED) ( xt -- ) Tells the kernel that an entry has been made, with its code at xt (request -19 on port 0). The kernel puts it in (WORD-DEFINED) when it seals a node.
(TELL-FORGOTTEN) ( w -- ) Tells the kernel that every entry from word address w up has gone (request -20 on port 0). The kernel puts it in (WORD-FORGOTTEN) when it seals a node.
(UD) ( -- addr ) Variable: U/MOD's divisor while it divides (forth79.4th).
(WE-N) ( -- addr ) Variable: WORD-ENTROPY's count of the words.
(WE-T) ( -- addr ) Variable: WORD-ENTROPY's total of the heat.
(WORD-DEFINED) ( -- addr ) Variable: the hook told when an entry is made, with the xt its code will be at.
(WORD-FORGOTTEN) ( -- addr ) Variable: the hook told when entries are forgotten, with the word address they went from.
(XT-HEAT) ( xt -- n ) The heat of the word at xt; 0 for what is not a word.
* ( n1 n2 -- n3 ) Multiply: the low cell of the product.
*/ ( n1 n2 n3 -- n4 ) n1 times n2 divided by n3, through a double-cell intermediate product.
*/MOD ( n1 n2 n3 -- n4 n5 ) n1 times n2 divided by n3, through a double product: n4 the remainder, n5 the quotient.
@@ -162,6 +168,8 @@ EMPTY-BUFFERS ( -- ) Forget what is in the block buffers; nothing is written.
ENCLOSE ( baddr c -- baddr n1 n2 n3 ) Find a word delimited by c in the string at baddr: n1 its start, n2 its end, n3 the offset after the delimiter.
ENDCASE ( x -- ) Compile-only: end a CASE selection, dropping the value if no OF matched.
ENDOF ( -- ) Compile-only: end an OF branch; go on after ENDCASE.
ENTROPY! ( n addr -- ) The execution heat of the word at addr set to n; its decay counts from now. An error if addr is not a word's.
ENTROPY@ ( addr -- n ) The execution heat of the word at addr (what ' leaves), from the kernel's record of it, as v3's. An error if addr is not a word's.
ERASE ( baddr u -- ) Fill u bytes from baddr with zeros.
EXECUTE ( xt -- ) Run the word whose execution token is xt.
EXIT ( -- ) Compile-only: return from the definition at this point.
@@ -284,6 +292,7 @@ QUIT ( -- ) Empty the return stack, set execution mode and go back to the termin
R> ( -- x ) ( R: x -- ) Compile-only: move the top of the return stack to the data stack.
R@ ( -- x ) ( R: x -- x ) Compile-only: copy the top of the return stack.
REPEAT ( -- ) Compile-only: end a BEGIN ... WHILE ... REPEAT loop, jumping back to BEGIN.
RESET-ENTROPY ( -- ) Every word's heat and temperature back to 0, as v3's.
ROLL ( n -- ) Move the n-th value, not counting n itself, to the top: 2 ROLL is ROT.
ROT ( x1 x2 x3 -- x2 x3 x1 ) Rotate the third value to the top.
ROUTE ( node port -- ) The port, by its number, leads toward that node.
@@ -308,6 +317,7 @@ SWAP ( x1 x2 -- x2 x1 ) Exchange the top two values.
THEN ( -- ) Compile-only: end an IF ... THEN or IF ... ELSE ... THEN.
THRU ( first last -- ) LOAD each block from first to last.
TIB ( -- baddr ) The terminal input buffer.
TOP-WORDS ( n -- ) Print the n hottest words and their heat, in v3's form.
TRAVERSE ( baddr n -- baddr' ) Step across a name field: for n > 0 from its count byte to its last byte, for n < 0 back.
TRUE ( -- -1 ) Constant: the true flag, all bits set.
TYPE ( baddr u -- ) Print the u characters at baddr.
@@ -330,6 +340,7 @@ WARM ( -- ) Print the system's message and ABORT: both stacks emptied, the promp
WHILE ( flag -- ) Compile-only: in BEGIN ... WHILE ... REPEAT, leave the loop if flag is zero.
WITHIN ( n low high -- flag ) True if low <= n < high.
WORD ( c -- baddr ) Read the next word from the input stream, delimited by c, as a counted string.
WORD-ENTROPY ( -- ) Print every word with heat and its heat, newest first, then the totals, in v3's form.
WORDS ( -- ) List the names in the CONTEXT vocabulary, the newest first.
XOR ( x1 x2 -- x3 ) Bitwise exclusive or.
[ ( -- ) Stop compiling: interpret what follows; immediate.
Can't render this file because it contains an unexpected character in line 10 and column 3.