feat(v4): Phase 7 Task 1 -- v3's physics fields on the word records, and each node's physics state (#189)

v4_mesh_account gains v3's DictPhysics: heat (execution_heat), last_decay_tick, temperature_q8, and the
kernel's own state flags (pinned, frozen); v4_mesh_physics gives each node v3's VM fields -- its tick,
the decay slope (v3's initial 21845, Q48.16), L8's gate on Loop #3. v4_mesh_state_flags derives a word's
flags as v3 does, immediate and hidden read from the node's header when asked. Test first:
test_mesh_boot.c, 48 checks. The kernel gives each of its 16 places its physics. Not pushed (held,
Captain Bob 2026-11-13: "Hold it, go ahead with Task 1").

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-13 20:00:28 +00:00
parent 41f8c1ec28
commit 922451cf52
5 changed files with 69 additions and 0 deletions
+25
View File
@@ -56,8 +56,29 @@ typedef struct {
v4_uheat_t calls; /* every call since the word was defined */
v4_uheat_t since; /* calls since the owner last charged them */
v4_cell xt; /* the word's xt; 0: no word has this ID */
/* v3's physics on a word (DictPhysics, v3/include/vm.h; #189 Phase 7, Task 1) */
v4_uheat_t heat; /* v3's execution_heat: +1 a call, decayed by the ticks since (Loop #3) */
uint64_t last_decay_tick; /* the node's tick when decay was last applied: the only clock decay reads */
uint16_t temperature_q8; /* the heat, smoothed (an EMA), in Q8 */
uint8_t state_flags; /* the kernel's own: V4_MESH_STATE_PINNED, _FROZEN */
} v4_mesh_account;
/* A word's state flags, as v3's (PHYSICS_STATE_*): immediate and hidden are the node's (its header's
* flags); pinned and frozen are the kernel's, on the record. */
#define V4_MESH_STATE_IMMEDIATE 0x01u
#define V4_MESH_STATE_PINNED 0x02u
#define V4_MESH_STATE_HIDDEN 0x04u
#define V4_MESH_STATE_FROZEN 0x10u
/* Each node's physics (v3's VM fields): its heartbeat's tick, the decay slope (Q48.16 heat a tick;
* v3's INITIAL_DECAY_SLOPE_Q48, which the inference engine tunes), and L8's gate on Loop #3. */
#define V4_MESH_INITIAL_DECAY_SLOPE_Q48 21845u
typedef struct {
uint64_t tick;
uint64_t decay_slope_q48;
uint8_t l3_decay;
} v4_mesh_physics;
typedef struct v4_mesh v4_mesh;
struct v4_mesh {
/* ---- the owner's: set before v4_mesh_boot ---- */
@@ -91,6 +112,7 @@ struct v4_mesh {
* bytes, a bit for each address of a node: set for a word's xt (0: none kept) */
v4_mesh_account *accounts;
unsigned char *is_word;
v4_mesh_physics *physics; /* `capacity` of them: each node's (#189, Phase 7) */
/* a word has gone, its ID free for the next: the owner forgets what it keeps by it (may be 0) */
void (*forgot)(void *self, unsigned place, v4_cell id);
void *self;
@@ -130,6 +152,9 @@ int v4_mesh_busy(const v4_mesh *ms);
/* A word's record on the node in `place`, by its xt: 0 if that is not a word's xt. */
const v4_mesh_account *v4_mesh_account_at(const v4_mesh *ms, unsigned place, v4_cell xt);
/* A word's state flags (V4_MESH_STATE_*), or 0 if xt is not a word's. */
unsigned v4_mesh_state_flags(const v4_mesh *ms, unsigned place, v4_cell xt);
/* For each word on the node in `place` called since the last charge: `each(ctx, id, calls)`, and its
* count since is cleared. */
void v4_mesh_charge(v4_mesh *ms, unsigned place, void (*each)(void *ctx, v4_cell id, v4_uheat_t calls), void *ctx);
+19
View File
@@ -158,6 +158,7 @@ static void word_made(unsigned place, const v4_node *n, v4_cell xt)
if (id >= 0 && id < (v4_cell)V4_MESH_WORD_IDS) {
v4_mesh_account *a = &accounts_of(place)[id];
a->calls = 0; a->since = 0; a->xt = xt;
a->heat = 0; a->last_decay_tick = 0; a->temperature_q8 = 0; a->state_flags = 0; /* as v3's physics_metadata_init */
}
}
@@ -175,6 +176,7 @@ static void words_gone(unsigned place, const v4_node *n, v4_cell w)
if (id >= 0 && id < (v4_cell)V4_MESH_WORD_IDS && accounts_of(place)[id].xt == a) {
v4_mesh_account *r = &accounts_of(place)[id];
r->calls = 0; r->since = 0; r->xt = 0;
r->heat = 0; r->last_decay_tick = 0; r->temperature_q8 = 0; r->state_flags = 0;
if (the->forgot) the->forgot(the->self, place, id);
}
}
@@ -225,10 +227,27 @@ static void words_attach(unsigned place, v4_fabric_node *x)
x->n.mem[im->word_defined] = told;
x->n.mem[im->word_forgotten] = gone;
}
if (the->physics) { /* the node's physics, as v3's VM starts */
the->physics[place].tick = 0;
the->physics[place].decay_slope_q48 = V4_MESH_INITIAL_DECAY_SLOPE_Q48;
the->physics[place].l3_decay = 1;
}
x->es.on_call = on_call;
x->es.on_call_ctx = &the->kernel[place];
}
unsigned v4_mesh_state_flags(const v4_mesh *ms, unsigned place, v4_cell xt)
{
const v4_mesh_account *a = v4_mesh_account_at(ms, place, xt);
v4_fabric_node *x = v4_fabric_node_at(&ms->f, place);
unsigned f;
if (!a || !x) return 0;
f = a->state_flags & (V4_MESH_STATE_PINNED | V4_MESH_STATE_FROZEN);
if (x->n.mem[xt - 3] & 1) f |= V4_MESH_STATE_IMMEDIATE; /* dict.f18: 1 immediate, 2 hidden */
if (x->n.mem[xt - 3] & 2) f |= V4_MESH_STATE_HIDDEN;
return f;
}
const v4_mesh_account *v4_mesh_account_at(const v4_mesh *ms, unsigned place, v4_cell xt)
{
v4_fabric_node *x = v4_fabric_node_at(&ms->f, place);
+15
View File
@@ -35,6 +35,7 @@ static v4_image im;
static v4_mesh ms;
static v4_mesh_account accounts[PLACES * V4_MESH_WORD_IDS]; /* the words' records (#189, Phase 2) */
static unsigned char is_word[PLACES * (V4_NODE_WORDS / 8u)];
static v4_mesh_physics physics[PLACES];
static unsigned forgotten;
static v4_cell forgotten_id = -1;
static void forgot(void *self, unsigned place, v4_cell id) { (void)self; (void)place; forgotten++; forgotten_id = id; }
@@ -89,6 +90,7 @@ int main(void)
ms.out = out; ms.key = key; ms.words = words; ms.word_count = 1; ms.serve = serve;
ms.capsules = capsules; ms.capsule_count = 2; ms.im = &im; ms.self = 0;
ms.accounts = accounts; ms.is_word = is_word; ms.forgot = forgot;
ms.physics = physics;
/* ---- the boot ---- */
CHECK(v4_mesh_boot(&ms) == 1, "the boot: %s", said);
@@ -184,6 +186,19 @@ int main(void)
a = v4_mesh_account_at(&ms, 0, xt);
CHECK(how == V4_TEXT_COMPLETED && xt > 0 && a && a->calls == 0 && a->xt == xt,
"a word defined at the prompt has a record, called 0 times: \"%s\"", r);
/* 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->last_decay_tick == 0 && a->state_flags == 0,
"a new word's physics: no heat, no temperature, never decayed, no state flags");
CHECK(ms.physics[0].decay_slope_q48 == 21845u && ms.physics[0].l3_decay == 1,
"each node has v3's initial decay slope (Q48.16, 1/3) and Loop #3 on");
r = line(V4_MESH_HERA, ": IMM ; IMMEDIATE ' IMM .", &how);
{
v4_cell ix = (v4_cell)strtol(r, 0, 10);
CHECK(v4_mesh_state_flags(&ms, 0, ix) == V4_MESH_STATE_IMMEDIATE,
"a word's state flags, as v3 derives them: IMMEDIATE, read from its header when asked");
CHECK(v4_mesh_state_flags(&ms, 0, xt) == 0, "and none for SQ");
}
r = line(V4_MESH_HERA, "FORGET IMM", &how);
r = line(V4_MESH_HERA, "3 SQ .", &how);
CHECK(strcmp(r, "9 ") == 0 && a && a->calls == 1, "a call to it counts one: %lu", a ? (unsigned long)a->calls : 0ul);
r = line(V4_MESH_HERA, "5 SQ 6 SQ + .", &how);