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
+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",