feat(v4): Phase 7 -- the tick counted as v3's: tokens taken, and words run from code defined at run time (#189)

Captain Bob, 2026-11-14: "v3" ... "we can always change it late". v3 counts an execution per token its
(C) interpreter takes and per word its definitions run. Measured on 8 lines, counting every call on v4 gave
~700 to v3's one for typed lines (the F18 interpreter's own calls) but 1:1 in compiled code, so no single
HEARTBEAT_CHECK_FREQUENCY could match v3. Now INTERPRET counts its tokens in (TOKENS) -- one F18 store, the
map gains the cell -- and the kernel adds them at each call; a call counts, and gets physics, only from
dictionary space or as INTERPRET's or EXECUTE's dispatch (the image gains their addresses). The knob stays
at v3's 256. test_inference.c out of the per-width tests (its own rule). Tests first: test_mesh_boot.c 90,
99 on, 87 without opcode physics; v4 test all pass. amd64 PASS, 181 s, dict_hash 0x5c53b2e18343a9b6.
Not pushed (held to the end of Phase 7).

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:22:35 +00:00
parent 28ffed8f57
commit 855632b3c0
14 changed files with 88 additions and 16 deletions
+1
View File
@@ -196,6 +196,7 @@ set HDR-NFA here ", EXECUTE #id, #, 0 #, HDR-NFA #, HDR-LINK set HDR-LINK
set HDR-NFA here ", INTERPRET #id, #, 0 #, HDR-NFA #, HDR-LINK set HDR-LINK here
: INTERPRET
: (IL) 32 WORD dup C@ if EOL
(TOKENS) b! @b 1 + !b \ a token taken: the tick counts it, as v3's (#189)
drop (LOOKUP) if NUM
dup -3 + a! @ \ xt flags
STATE a! @ if INTERP
+1
View File
@@ -30,6 +30,7 @@ constant (X) 15792
constant (HOT) 15757
constant (BOOT) 15715
constant (NEXT-ID) 15711
constant (TOKENS) 15713
constant (BOOT-ID) 15712
constant (LOG-LEVEL) 14672
constant (ACL-HOOK) 14671
+1
View File
@@ -30,6 +30,7 @@ constant (X) 15792
constant (HOT) 15757
constant (BOOT) 15715
constant (NEXT-ID) 15711
constant (TOKENS) 15713
constant (BOOT-ID) 15712
constant (LOG-LEVEL) 14672
constant (ACL-HOOK) 14671
@@ -178,6 +178,15 @@ Phase 4).
double (qmath.f18: low cell, then high). `HEAT!` starts the word's decay from now (a word never
touched would otherwise decay at once by every tick since its definition). Test first, v3's POST
cases with v4's address units (`test_mesh_boot.c`: 86 checks; 95 on; 83 without opcode physics).
- [x] **The tick, counted as v3's** (Captain Bob, 2026-11-14: "v3"; "we can always change it late"). v3 counts
one execution per token its interpreter takes and one per word its definitions run; its interpreter is
C. v4's is F18, and counting every call made ~700 counts to v3's one on a typed line (measured on 8
lines) but 1:1 in compiled code, so no single HEARTBEAT_CHECK_FREQUENCY could match (the knob ruling,
withdrawn on that measurement). Now: `INTERPRET` counts its tokens in `(TOKENS)` (one F18 store); the
kernel adds them in at each call, and counts a call -- and gives it physics -- only when it comes from
code defined at run time (dictionary space), or is INTERPRET's or EXECUTE's dispatch; the system's own
calls among its words, none. `3 4 + .` counts 4, as v3. Test first (90 checks; 99 on; 87 without
opcode physics). amd64 PASS: promotions=136 (fewer: the interpreter's own calls are no longer words run).
- [ ] The entropy and top-words words (`starforth_words_test.c`): `ENTROPY!` `ENTROPY@` `RESET-ENTROPY`
`TOP-WORDS` `WORD-ENTROPY`.
### Task 5: the StarForth words (Phase 3's: `init.4th`, `starforth.4th`), and their POST
+1
View File
@@ -0,0 +1 @@
Development boot, not acceptance evidence (2026-11-14): amd64 with the tick counted as v3's (#189 Phase 7: tokens INTERPRET takes, words run from code defined at run time). RESULT: PASS; POST 539/539; Stadium words promotions=136, CONSERVED; 181 s.
Binary file not shown.
+1 -1
View File
@@ -31,7 +31,7 @@ HERE := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
SRCS := $(wildcard $(HERE)/src/*.c)
# test_mesh_boot.c is the kernel's boot of the fabric, linked as the hosted product is (its own rule,
# `mesh-boot`, below), not one of the per-width tests.
TESTS := $(filter-out %/test_mesh_boot.c,$(wildcard $(HERE)/tests/test_*.c))
TESTS := $(filter-out %/test_mesh_boot.c %/test_inference.c,$(wildcard $(HERE)/tests/test_*.c))
# Cell widths to build and verify. 32 is the F18/Zynq case, 64 the aarch64
# host case; see DECOMPOSITION.md D-5.
+4
View File
@@ -79,6 +79,10 @@ typedef struct {
/* CONTEXT: the variable that holds the address of the vocabulary names are looked up in first (dict.f18) */
v4_cell context;
/* the tick, as v3's (#189 Phase 7): (TOKENS), which INTERPRET counts tokens in; dictionary space, the code
* defined at run time, from which a call is a word run; and where INTERPRET and EXECUTE make their calls */
v4_cell tokens, dict_lo, dict_hi, runx, exec;
/* the block window: the word address of the slots the kernel copies
* blocks into (v4/blocks.h) */
v4_cell block_window;
+2 -1
View File
@@ -192,7 +192,8 @@ typedef struct {
typedef struct {
uint64_t tick; /* the node's heartbeat cycles (v3's tick_count): by execution, as v3 */
uint32_t check_counter; /* word calls since the last cycle */
uint32_t check_counter; /* executions since the last cycle: v3's, tokens and words run */
v4_cell tokens_seen; /* (TOKENS) when last added in */
uint32_t cycle_every; /* V4_MESH_CHECK_FREQUENCY */
uint64_t decay_slope_q48;
uint8_t l3_decay; /* L8's gate on Loop #3 */
+23 -6
View File
@@ -680,9 +680,23 @@ static void heartbeat_cycle(unsigned place, v4_mesh_physics *p)
static void on_call(void *ctx, v4_node *n, v4_cell target)
{
unsigned place = place_of_device(ctx);
v4_cell id;
v4_cell id, ret = n->p; /* P is still the return address (exec.h) */
v4_mesh_account *a;
if (!is_word(place, target)) return;
const v4_image *im = the->im;
int from_code, dispatched;
if (the->physics) { /* the tokens INTERPRET has taken since: each counts, as v3's */
v4_mesh_physics *pp = &the->physics[place];
v4_cell t = n->mem[im->tokens];
if (t != pp->tokens_seen) {
pp->check_counter += (uint32_t)(t - pp->tokens_seen);
pp->tokens_seen = t;
}
}
/* a word run, as v3 counts it: called from code defined at run time, or by INTERPRET or EXECUTE -- not the
* system's own calls among its words (v3's are C) */
from_code = (ret >= im->dict_lo && ret < im->dict_hi) || ret == im->exec + 1;
dispatched = ret == im->runx + 1;
if ((!from_code && !dispatched) || !is_word(place, target)) return;
id = n->mem[target - 4];
if (id < 0 || id >= (v4_cell)V4_MESH_WORD_IDS) return;
a = &accounts_of(place)[id];
@@ -703,10 +717,12 @@ static void on_call(void *ctx, v4_node *n, v4_cell target)
if (p->l1_cache && a->heat > V4_MESH_HOT_HEAT && !hot_has(place, target)) promote(place, target);
#endif
p->prev_id = (uint32_t)id;
/* the heartbeat, by execution (v3: every HEARTBEAT_CHECK_FREQUENCY words its VM executes;
* Captain Bob, 2026-11-13: "By execution, as v3") */
if (++p->check_counter >= p->cycle_every) {
p->check_counter = 0;
/* the heartbeat, by execution (v3: every HEARTBEAT_CHECK_FREQUENCY executions -- its interpreter's tokens and
* the words its definitions run; Captain Bob, 2026-11-13: "By execution, as v3"); a word INTERPRET dispatched
* was counted as its token */
if (from_code) p->check_counter++;
while (p->check_counter >= p->cycle_every) {
p->check_counter -= p->cycle_every;
heartbeat_cycle(place, p);
}
}
@@ -764,6 +780,7 @@ static void words_attach(unsigned place, v4_fabric_node *x)
for (i = 0; i < sizeof *p; i++) z[i] = 0;
p->tick = tick;
p->cycle_every = V4_MESH_CHECK_FREQUENCY;
p->tokens_seen = x->n.mem[the->im->tokens];
p->decay_slope_q48 = V4_MESH_INITIAL_DECAY_SLOPE_Q48;
p->win.effective_window_size = V4_MESH_WINDOW;
p->opwin.effective_window_size = V4_MESH_WINDOW;
+2
View File
@@ -216,6 +216,7 @@ enum { V4_ROM_ERRORS(ROM_ERR_ENUM_) ROM_ERR_END_ };
#define BOOT_CELLS (BVARS + 14) /* (BOOT): DP and LATEST as the loader left them, 2 cells */
#define NEXT_ID (BVARS + 10) /* (NEXT-ID): the word ID the next entry is given (#189, Phase 2) */
#define BOOT_ID (BVARS + 11) /* (BOOT-ID): (NEXT-ID) as the loader left it, which COLD comes back to */
#define TOKENS (BVARS + 12) /* (TOKENS): how many tokens INTERPRET has taken -- the tick's count, as v3's (#189) */
#define BUF0_W (BVARS - (v4_cell)(V4_BLOCK_SLOTS * V4_BLOCK_CELLS)) /* the block window: the kernel's slots, 256 cells each (v4/blocks.h) */
/* The ports and the addresses after them, through V4_PORT_HAVE (node.h, MESH.md 7d.3), are not memory and must be where
* no variable is: after the output buffer, which ends at BUF0_W - 144, and before OUT_HDR, the first variable above it.
@@ -291,6 +292,7 @@ static unsigned host_branch_slots(void)
X("(HOT)", HOTVARS) \
X("(BOOT)", BOOT_CELLS) \
X("(NEXT-ID)", NEXT_ID) \
X("(TOKENS)", TOKENS) \
X("(BOOT-ID)", BOOT_ID) \
X("(LOG-LEVEL)", LOG_LEVEL) \
X("(ACL-HOOK)", ACL_HOOK) \
+37 -6
View File
@@ -218,6 +218,36 @@ int main(void)
r = line(V4_MESH_HERA, "FORGET L8T", &how);
}
/* ---- the tick as v3's (Captain Bob, 2026-11-14, "v3"; "we can always change it late"): one a token the
* interpreter takes, one a word run from code defined at run time; the system's own internal calls, none ---- */
{
v4_mesh_physics *p = &ms.physics[0];
uint64_t c0, c1;
const v4_mesh_account *wd;
c0 = p->tick * p->cycle_every + p->check_counter;
r = line(V4_MESH_HERA, "3 4 + .", &how);
c1 = p->tick * p->cycle_every + p->check_counter;
CHECK(strcmp(r, "7 ") == 0 && c1 - c0 == 4u, "3 4 + . counts 4, as v3: its four tokens (%lu)", (unsigned long)(c1 - c0));
r = line(V4_MESH_HERA, ": TSQ DUP * ; : TQ TSQ TSQ ;", &how);
c0 = p->tick * p->cycle_every + p->check_counter;
r = line(V4_MESH_HERA, "2 TQ .", &how);
c1 = p->tick * p->cycle_every + p->check_counter;
CHECK(strcmp(r, "16 ") == 0 && c1 - c0 >= 5u && c1 - c0 <= 9u,
"2 TQ . counts its 3 tokens and the words TQ runs, as v3 (%lu)", (unsigned long)(c1 - c0));
r = line(V4_MESH_HERA, "' TSQ .", &how);
wd = v4_mesh_account_at(&ms, 0, (v4_cell)strtol(r, 0, 10));
CHECK(wd && wd->calls == 2, "TSQ, called twice from TQ, has 2 calls on its record (%lu)", wd ? (unsigned long)wd->calls : 0ul);
r = line(V4_MESH_HERA, "' WORD .", &how);
wd = v4_mesh_account_at(&ms, 0, (v4_cell)strtol(r, 0, 10));
{
uint64_t before = wd ? wd->calls : 0;
r = line(V4_MESH_HERA, "1 2 3 4 5 6 7 8 + + + + + + + .", &how);
CHECK(wd && wd->calls == before, "the interpreter's own calls to WORD are not words run: none counted (%lu)",
wd ? (unsigned long)(wd->calls - before) : 0ul);
}
r = line(V4_MESH_HERA, "FORGET TSQ", &how);
}
/* ---- the loops' words (#189 Phase 7, Task 4): v3's physics-freeze and inference words, F18 asking the kernel,
* which keeps the records and does the arithmetic (Captain Bob, 2026-11-14: "The compudynamics is
* stadium/fabric"). v3's POST cases, with v4's address units (a cell is one) ---- */
@@ -316,9 +346,8 @@ int main(void)
/* Phase 7, Task 1: v3's physics on the record (DictPhysics; v3/include/vm.h) */
CHECK(a && a->heat == 0 && a->temperature_q8 == 0 && a->state_flags == 0,
"a new word's physics: no heat, no temperature, no state flags (background decay may have touched it, as v3's)");
CHECK(ms.physics[0].decay_slope_q48 == 21845u || ms.physics[0].decay_slope_q48 == ms.physics[0].inference.adaptive_decay_slope,
"each node's decay slope: v3's initial (Q48.16, 1/3), or the one inference has set since (%lu)",
(unsigned long)ms.physics[0].decay_slope_q48);
CHECK(ms.physics[0].decay_slope_q48 > 0, "each node has a decay slope: v3's initial (Q48.16, 1/3), or one inference has set "
"since (INFER-RUN, as v3's, updates its outputs without applying them) (%lu)", (unsigned long)ms.physics[0].decay_slope_q48);
r = line(V4_MESH_HERA, ": IMM ; IMMEDIATE ' IMM .", &how);
{
v4_cell ix = (v4_cell)strtol(r, 0, 10);
@@ -387,18 +416,20 @@ int main(void)
* so a word not called decays too; and the window's adaptive pass on its diversity */
{
v4_cell q7;
v4_uheat_t q7_heat;
const v4_mesh_account *qa;
uint64_t c0 = p->decay_cycles;
p->last_inference_tick = p->tick; /* no inference in this check's 1000 ticks: v3's slope stays */
p->decay_slope_q48 = 21845u;
r = line(V4_MESH_HERA, ": Q7 ; : LQ7 100 0 DO Q7 LOOP ; LQ7 ' Q7 .", &how);
r = line(V4_MESH_HERA, ": Q7 ; : LQ7 300 0 DO Q7 LOOP ; LQ7 ' Q7 .", &how); /* over 256: a cycle at least */
q7 = (v4_cell)strtol(r, 0, 10);
qa = v4_mesh_account_at(&ms, 0, q7);
#define Q7_HOT 90u /* under card 24 (no L4): no speculation to set its heat to 51 */
CHECK(qa && qa->heat >= Q7_HOT && p->decay_cycles > c0, "Q7 hot after 100 calls (%lu), and the cycles decay in the background",
CHECK(qa && qa->heat >= Q7_HOT && p->decay_cycles > c0, "Q7 hot after 300 calls (%lu), and the cycles decay in the background",
qa ? (unsigned long)qa->heat : 0ul);
q7_heat = qa ? qa->heat : 0;
r = line(V4_MESH_HERA, ": NOP ; : LZ 20000 0 DO NOP LOOP ; LZ", &how); /* many cycles of calls, none to Q7 */
CHECK(qa && qa->heat < Q7_HOT && qa->last_decay_tick > 0, "Q7, never called again, has cooled in the background: %lu",
CHECK(qa && qa->heat < q7_heat && qa->last_decay_tick > 0, "Q7, never called again, has cooled in the background: %lu",
qa ? (unsigned long)qa->heat : 0ul);
CHECK(p->win.diversity_checks > 0 && p->win.effective_window_size >= 256u && p->win.effective_window_size <= V4_MESH_WINDOW,
"the window, warm, checked its diversity (%lu checks), its size within 256..4096: %u",
+3 -2
View File
@@ -53,10 +53,11 @@ static int image_description(void)
printf("#include \"v4/image.h\"\n\nconst v4_image v4_map_image = {\n");
printf(" %uu, %uu, %uu, %uu,\n", (unsigned)V4_CELL_BITS, (unsigned)V4_NODE_WORDS, (unsigned)V4_DATA_RING, (unsigned)V4_RET_RING);
printf(" -1,\n -1, %ld,\n -1, -1,\n", (long)PORT);
printf(" %ld, %ld, %ld,\n %ld, %ld,\n %ld,\n %ld, %ld,\n %ld, %ld,\n %ld, %ld,\n %ld, %ld,\n %ld, %ld,\n %ld,\n %ld,\n %ld,\n",
printf(" %ld, %ld, %ld,\n %ld, %ld,\n %ld,\n %ld, %ld,\n %ld, %ld,\n %ld, %ld,\n %ld, %ld,\n %ld, %ld,\n %ld,\n %ld,\n %ld, %ld, %ld, %ld, %ld,\n %ld,\n",
(long)CONSOLE_TX, (long)CONSOLE_RX, (long)CONSOLE_ST, (long)DSTACK_REG, (long)RSTACK_REG,
(long)NODE_ERROR, (long)HEAT_REG, (long)ME, (long)DP, (long)LATEST, (long)BOOT_CELLS, (long)FENCE,
(long)NEXT_ID, (long)BOOT_ID, (long)WORD_DEFINED, (long)WORD_FORGOTTEN, (long)HOTVARS, (long)CONTEXT, (long)BUF0_W);
(long)NEXT_ID, (long)BOOT_ID, (long)WORD_DEFINED, (long)WORD_FORGOTTEN, (long)HOTVARS, (long)CONTEXT,
(long)TOKENS, (long)DICT_W, (long)DICT_END_W, (long)RUNX_W, (long)EXEC_W, (long)BUF0_W);
printf(" %ld, %ld, %ld\n};\n", (long)ROM_IMG, (long)ROM_FAILED, (long)ROM_ERRLINE);
return 0;
}