feat(v4): word accounts at call -- the word ID in the header, the kernel's records, the Stadium charged per tick (#189)

ENGINE step 4 Phase 2 (plan docs/v4.0.0/plans/2026-11-13-engine-step4-phase2-word-accounts.md). Rulings,
Captain Bob 2026-11-13: "ID field in the header"; "Per heartbeat tick"; the ACL "All of it in Phase 4".

- The word ID, at xt-4 before the flags (ENGINE.md 3b). The system's words are numbered as they are
  assembled, by a new directive, #id, (and #ids, the count), in the C assembler (text.c) and in the
  machine ROM's (capsules/v4/rom), which counts in the system's own (NEXT-ID). (HEADER) numbers later
  words; FORGET gives back the IDs it frees, always the newest; COLD resets to (BOOT-ID); (SEAL) records
  it. All 313 system headers carry the cell.
- The kernel's records (v4/mesh.h): (TELL-DEFINED) and (TELL-FORGOTTEN), requests -19/-20 on port 0,
  which the kernel puts in (WORD-DEFINED)/(WORD-FORGOTTEN) when it seals a node, and reads the system's
  own words once. A bit per address marks a word's xt (calls into the ROM or headerless code are not
  words); at call, the bit test and a count. v4_mesh_charge hands the owner the calls since.
- The Stadium: stadium_words_charge -- N calls as N of stadium_word_dispatch's dispatches, shared by calls
  when the reservoir is short; sk_v4.c charges every node's words at the tick beside its opcodes, and
  stadium_word_forget before an ID is used again.
- Tests first: test_text.c, test_host_dict.c, test_host_quit.c (numbering, FORGET, COLD),
  test_mesh_boot.c (44 checks), kernel/tests/test_stadium_words.c; qemu_session.py: Hera's words
  admitted after POST.
- amd64: Stadium words: promotions=141 after POST, CONSERVED; POST 539/539; word_count=377;
  dict_hash 0xa854ba15b437d288 (the new cell); the boot 142 s against Phase 1's 153 s.
- v4 test, test-32: all pass; v4-checks: 80 programs under the sanitizers, 0 failures; the hosted
  builds alike. docs/reference/v4-dictionary.tsv: the two new words; FABRIC-3 XLVIII.24.

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 19:12:44 +00:00
parent d64ad4a1c3
commit e8e7ec8b9f
44 changed files with 1060 additions and 349 deletions
+12 -12
View File
@@ -133,7 +133,7 @@ static int entry_is(v4_cell xt, const char *want, v4_cell link, v4_cell flags)
v4_cell nfa;
if (len > 31) len = 31;
cells = (len + 4) / 4;
nfa = xt - 3 - (v4_cell)cells;
nfa = xt - 4 - (v4_cell)cells; /* the name, then its word ID (#189, Phase 2), flags, NFA, link */
if (n.mem[xt - 1] != link || n.mem[xt - 2] != nfa || n.mem[xt - 3] != flags) return 0;
if (byte_at(nfa * 4) != len) return 0;
for (i = 0; i < len; i++) if (byte_at(nfa * 4 + 1 + (v4_cell)i) != (unsigned char)want[i]) return 0;
@@ -258,21 +258,21 @@ int main(void)
empty_dictionary();
CHECK(get("LATEST", 0, 0) == 0, "LATEST is 0 in an empty dictionary");
a = define("ALPHA");
CHECK(a == DICT_W + 2 + 3 && !err(), "an entry's xt follows its name and three cells: %ld", (long)a);
CHECK(a == DICT_W + 2 + 4 && !err(), "an entry's xt follows its name and four cells: %ld", (long)a);
CHECK(entry_is(a, "ALPHA", 0, 0), "the first entry: name, no flags, link 0");
CHECK(get("LATEST", 0, 0) == a && get("HERE", 0, 0) == a, "LATEST is its xt, and its code starts at HERE");
CHECK(run(",", 1, 1001, 0) && clean(), "some code");
b = define("B");
CHECK(b == a + 1 + 1 + 3 && entry_is(b, "B", a, 0), "the second entry links to the first");
CHECK(b == a + 1 + 1 + 4 && entry_is(b, "B", a, 0), "the second entry links to the first");
(void)run(",", 1, 1002, 0);
c = define("GAMMA-DELTA");
CHECK(c == b + 1 + 3 + 3 && entry_is(c, "GAMMA-DELTA", b, 0), "an eleven-character name takes three cells");
CHECK(c == b + 1 + 3 + 4 && entry_is(c, "GAMMA-DELTA", b, 0), "an eleven-character name takes three cells");
CHECK(get("LATEST", 0, 0) == c, "LATEST is the newest");
/* the field words, all from the xt */
CHECK(get(">LINK", 1, c) == c - 1 && get("LFA", 1, c) == c - 1, ">LINK and LFA are the link's address");
CHECK(get("LINK>", 1, c - 1) == b && get("LINK>", 1, b - 1) == a && get("LINK>", 1, a - 1) == 0, "LINK> follows it, to 0 at the end");
CHECK(get(">NAME", 1, c) == (c - 6) * 4 && get("NFA", 1, c) == (c - 6) * 4, ">NAME and NFA are the name's byte address");
CHECK(get(">NAME", 1, c) == (c - 7) * 4 && get("NFA", 1, c) == (c - 7) * 4, ">NAME and NFA are the name's byte address");
CHECK(byte_at(get(">NAME", 1, b)) == 1 && byte_at(get(">NAME", 1, b) + 1) == 'B', "which is its count byte, then its characters");
CHECK(get("NAME>", 1, get(">NAME", 1, a)) == a && get("NAME>", 1, get(">NAME", 1, b)) == b && get("NAME>", 1, get(">NAME", 1, c)) == c, "NAME> goes back to the xt");
CHECK(get("CFA", 1, c) == c, "CFA is the xt itself, as v3");
@@ -306,15 +306,15 @@ int main(void)
memset(long31, 'q', 31); long31[31] = 0;
memset(long40, 'q', 40); long40[40] = 0;
a = define(long31);
CHECK(a == DICT_W + 8 + 3 && entry_is(a, long31, 0, 0), "a 31-character name is kept whole");
CHECK(a == DICT_W + 8 + 4 && entry_is(a, long31, 0, 0), "a 31-character name is kept whole");
b = define(long40);
CHECK(b != 0 && entry_is(b, long31, a, 0) && b - a == 8 + 3, "a 40-character name is cut to 31");
CHECK(b != 0 && entry_is(b, long31, a, 0) && b - a == 8 + 4, "a 40-character name is cut to 31");
}
empty_dictionary();
n.mem[DP] = (DICT_END_W - 4) * 4;
CHECK(define("ABCD") == 0 && err() && n.mem[LATEST] == 0 && n.mem[DP] == (DICT_END_W - 4) * 4 && n.mem[DICT_END_W - 4] == GUARD,
"an entry that does not fit makes nothing, moves nothing, and sets NODE-ERROR");
n.mem[DP] = (DICT_END_W - 5) * 4;
CHECK(define("ABCD") == 0 && err() && n.mem[LATEST] == 0 && n.mem[DP] == (DICT_END_W - 5) * 4 && n.mem[DICT_END_W - 5] == GUARD,
"an entry that does not fit makes nothing, moves nothing, and sets NODE-ERROR");
n.mem[DP] = (DICT_END_W - 6) * 4;
CHECK(define("ABCD") == DICT_END_W && !err() && n.mem[DICT_END_W] == GUARD, "one that just fits is made");
/* ---- FIND ---- */
@@ -376,9 +376,9 @@ int main(void)
/* the same name through (HEADER): the same cells */
made = define("FIRST-HEADER");
CHECK(made != 0 && n.mem[made - 3] == n.mem[xa - 3] && made - n.mem[made - 2] == xa - n.mem[xa - 2], "an entry made by (HEADER) has the same shape");
for (i = 0; i < (unsigned)(xa - 3 - n.mem[xa - 2]); i++)
for (i = 0; i < (unsigned)(xa - 4 - n.mem[xa - 2]); i++)
if (n.mem[n.mem[xa - 2] + (v4_cell)i] != n.mem[n.mem[made - 2] + (v4_cell)i]) break;
CHECK(i == (unsigned)(xa - 3 - n.mem[xa - 2]), "and the same name cells");
CHECK(i == (unsigned)(xa - 4 - n.mem[xa - 2]), "and the same name cells");
CHECK(n.mem[made - 1] == xp && find("FIRST-HEADER") == made && find("B") == xb, "new entries link on to the assembler's");
}