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:
@@ -24,3 +24,44 @@ Block 8201
|
||||
-34 KERNEL-WORD INFER-EARLY-EXIT@ ( -- flag )
|
||||
( v3's DECAY_RATE_PER_US_Q16, its compile-time constant )
|
||||
1 CONSTANT DECAY-RATE@
|
||||
Block 8202
|
||||
( v3's StarForth module: a word's execution heat, by the )
|
||||
( address ' leaves; and the hottest -- the kernel's records )
|
||||
-35 KERNEL-WORD ENTROPY@ ( addr -- n )
|
||||
-36 KERNEL-WORD ENTROPY! ( n addr -- )
|
||||
-37 KERNEL-WORD RESET-ENTROPY ( -- )
|
||||
-38 KERNEL-WORD (HOT#) ( -- n )
|
||||
-39 KERNEL-WORD (HOT) ( i -- xt heat )
|
||||
-40 KERNEL-WORD (XT-HEAT) ( xt -- n )
|
||||
( TOP-WORDS n: the n hottest, in v3's form )
|
||||
: TOP-WORDS ( n -- )
|
||||
DUP 1 < IF ." TOP-WORDS: invalid count " 0 .R CR EXIT THEN
|
||||
." Top " DUP 0 .R ." most frequently used words:" CR
|
||||
." ==================================" CR
|
||||
(HOT#) MIN 0 ?DO I (HOT) SWAP I 1+ 0 .R ." . "
|
||||
>NAME COUNT TYPE ." : " 0 .R CR LOOP ;
|
||||
Block 8203
|
||||
( WORD-ENTROPY: every word with heat, then the totals, as v3 )
|
||||
VARIABLE (WE-T) VARIABLE (WE-N)
|
||||
: WORD-ENTROPY ( -- )
|
||||
." Word Usage Statistics (Execution Heat Counts):" CR
|
||||
." =============================================" CR
|
||||
0 (WE-T) ! 0 (WE-N) ! LATEST
|
||||
BEGIN DUP WHILE 1 (WE-N) +!
|
||||
DUP (XT-HEAT) ?DUP IF OVER >NAME COUNT TYPE ." : "
|
||||
DUP 0 .R CR (WE-T) +! THEN >LINK @
|
||||
REPEAT DROP
|
||||
." -------------------------------------" CR
|
||||
." Total executions: " (WE-T) @ 0 .R CR
|
||||
." Total words: " (WE-N) @ 0 .R CR
|
||||
(WE-T) @ IF ." Average executions per word: "
|
||||
(WE-T) @ (WE-N) @ / 0 .R CR THEN ;
|
||||
Block 8204
|
||||
( (- skips its input to the matching close paren, nesting, )
|
||||
( as v3's code does -- its documentation says to the line end )
|
||||
: (- ( -- ) 1
|
||||
BEGIN DUP 0= IF DROP EXIT THEN
|
||||
>IN @ SOURCE SWAP DROP < 0= IF DROP EXIT THEN
|
||||
SOURCE DROP >IN @ + C@ 1 >IN +!
|
||||
DUP 40 = IF DROP 1+ ELSE 41 = IF 1- THEN THEN
|
||||
AGAIN ;
|
||||
|
||||
Reference in New Issue
Block a user