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:
@@ -76,6 +76,14 @@ Phase 4).
|
||||
Mama and the C modules ruled (above).
|
||||
|
||||
### Task 1: the records' physics fields, and the per-node state
|
||||
- [x] Test first (`test_mesh_boot.c`): a new word's heat, temperature, last decay tick and state flags
|
||||
are 0; each node starts with v3's decay slope (21845, Q48.16) and Loop #3 on; a word's state
|
||||
flags as v3 derives them (IMMEDIATE read from its header).
|
||||
- [x] `v4_mesh_account` gains `heat` (v3's `execution_heat`), `last_decay_tick`, `temperature_q8`,
|
||||
`state_flags` (the kernel's own: pinned, frozen); `v4_mesh_physics` per node (tick, decay slope,
|
||||
L8's Loop #3 gate); `v4_mesh_state_flags`. Immediate and hidden are read from the node's header
|
||||
when asked, so they are never stale. v3's `mass_bytes` is only ever set, never read, in v3: not
|
||||
kept until a word reads it.
|
||||
### Task 2: the per-call loops at `call` (decay on touch, window, transitions) -- measured
|
||||
### Task 3: the per-tick loops (tuner, slope, background decay, L8, inference, snapshot)
|
||||
### Task 4: the words that read and set them (`FREEZE-WORD`, the inference words, ...), and their POST
|
||||
|
||||
@@ -77,6 +77,7 @@ static v4_cell sk_v4_keyed[SK_V4_PLACES]; /* by place: the number its
|
||||
static uint32_t sk_v4_charge_ids[V4_MESH_WORD_IDS];
|
||||
static uint64_t sk_v4_charge_calls[V4_MESH_WORD_IDS];
|
||||
static uint32_t sk_v4_charge_n;
|
||||
static v4_mesh_physics sk_v4_physics[SK_V4_PLACES]; /* each node's physics: its tick, decay slope, L8's gates (#189, Phase 7) */
|
||||
static void sk_v4_charge_one(void *ctx, v4_cell id, v4_uheat_t calls)
|
||||
{
|
||||
(void)ctx;
|
||||
@@ -309,6 +310,7 @@ void sk_v4_boot(void (*chain)(void), const BootDisk *boot_disk)
|
||||
for (i = 0; i < (size_t)SK_V4_PLACES * (V4_NODE_WORDS / 8u); i++) sk_v4_mesh.is_word[i] = 0;
|
||||
}
|
||||
sk_v4_mesh.forgot = sk_v4_forgot;
|
||||
sk_v4_mesh.physics = sk_v4_physics;
|
||||
sk_v4_mesh.out = sk_v4_out; sk_v4_mesh.key = sk_v4_key;
|
||||
sk_v4_mesh.words = sk_v4_words; sk_v4_mesh.word_count = sizeof sk_v4_words / sizeof sk_v4_words[0];
|
||||
sk_v4_mesh.serve = sk_v4_serve;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user