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
+21 -8
View File
@@ -431,27 +431,40 @@ int main(void)
CHECK(ok("header DUP : (DUP) dup + ;"), "a header assembles: %s", v4_text_error(&tx));
{
v4_cell xt = v4_text_word(&tx, "(DUP)");
CHECK(xt == ORIGIN + 4 && v4_text_latest(&tx) == xt, "the code follows the name cell and three more: %ld", (long)xt);
CHECK(xt == ORIGIN + 5 && v4_text_latest(&tx) == xt, "the code follows the name cell and four more: %ld", (long)xt);
CHECK((v4_ucell)nb.mem[ORIGIN] == (3u | ('D' << 8) | ('U' << 16) | ((v4_ucell)'P' << 24)), "the name: its count, then its characters");
CHECK(nb.mem[xt - 4] == 0, "the word ID: the first header's is 0 (#189, Phase 2)");
CHECK(nb.mem[xt - 3] == 0 && nb.mem[xt - 2] == ORIGIN && nb.mem[xt - 1] == 0, "flags 0, the name's address, link 0");
CHECK(result("(DUP)", 1, 7, 0) == 14, "and the word runs");
}
/* the word ID (#189, Phase 2; Captain Bob, 2026-11-13: "ID field in the header"): numbered in the
* order the headers are assembled, from 0, by `header` and by `#id,`; `#ids` is how many so far */
CHECK(ok("header A : A' 1 ; header B : B' 2 ; header C : C' 3 ;"), "three headers: %s", v4_text_error(&tx));
CHECK(nb.mem[v4_text_word(&tx, "A'") - 4] == 0 && nb.mem[v4_text_word(&tx, "B'") - 4] == 1
&& nb.mem[v4_text_word(&tx, "C'") - 4] == 2, "their word IDs are 0, 1, 2");
CHECK(ok("#id, #id, #id, #, #ids"), "#id, three times, then #ids: %s", v4_text_error(&tx));
CHECK(nb.mem[ORIGIN] == 0 && nb.mem[ORIGIN + 1] == 1 && nb.mem[ORIGIN + 2] == 2 && nb.mem[ORIGIN + 3] == 3,
"#id, lays 0, 1, 2; #ids is then 3");
CHECK(ok("header A : A' 1 ; #id, header B : B' 2 ;"), "a header and #id, share the count: %s", v4_text_error(&tx));
CHECK(nb.mem[v4_text_word(&tx, "B'") - 4] == 2, "so the next header's ID is 2");
CHECK(ok("#, #ids") && nb.mem[ORIGIN] == 0, "with none yet, #ids is 0");
CHECK(refused("macro M #id, endmacro M", "not allowed in a macro", 0), "#id, is refused in a macro");
CHECK(ok(": BEFORE 1 ; header A : A' 2 ; header LONGER-NAM immediate : B' 3 ; : MID 4 ; header + inline compile-only : PLUS + ;")
&& result("BEFORE", 0, 0, 0) == 1 && result("B'", 0, 0, 0) == 3 && result("MID", 0, 0, 0) == 4, "headers among other words");
{
v4_cell a = v4_text_word(&tx, "A'"), b = v4_text_word(&tx, "B'"), c = v4_text_word(&tx, "PLUS");
CHECK(nb.mem[a - 1] == 0 && nb.mem[b - 1] == a && nb.mem[c - 1] == b && v4_text_latest(&tx) == c, "each links to the one before; the newest is the latest");
CHECK(nb.mem[a - 3] == 0 && nb.mem[b - 3] == 1 && nb.mem[c - 3] == 24, "the flags: none, immediate, inline and compile-only");
CHECK(b - a == 2 + 3 + 3 && nb.mem[b - 2] == b - 6, "a ten-character name takes three cells");
CHECK((v4_ucell)nb.mem[b - 4] == (('N') | ('A' << 8) | ('M' << 16)), "and is padded with zeros");
CHECK((v4_ucell)nb.mem[c - 4] == (1u | ('+' << 8)), "an opcode's name is taken as it stands");
CHECK(b - a == 2 + 3 + 4 && nb.mem[b - 2] == b - 7, "a ten-character name takes three cells");
CHECK((v4_ucell)nb.mem[b - 5] == (('N') | ('A' << 8) | ('M' << 16)), "and is padded with zeros");
CHECK((v4_ucell)nb.mem[c - 5] == (1u | ('+' << 8)), "an opcode's name is taken as it stands");
}
CHECK(ok("header ( immediate : PAREN ; header \\ immediate : BACKSLASH ; header : : COLON ; header ; : SEMI ; header header : H ;"),
"names the assembler would otherwise read as its own: %s", v4_text_error(&tx));
CHECK((v4_ucell)nb.mem[v4_text_word(&tx, "PAREN") - 4] == (1u | ('(' << 8))
&& (v4_ucell)nb.mem[v4_text_word(&tx, "BACKSLASH") - 4] == (1u | ('\\' << 8))
&& (v4_ucell)nb.mem[v4_text_word(&tx, "COLON") - 4] == (1u | (':' << 8))
&& (v4_ucell)nb.mem[v4_text_word(&tx, "SEMI") - 4] == (1u | (';' << 8)), "are names like any other");
CHECK((v4_ucell)nb.mem[v4_text_word(&tx, "PAREN") - 5] == (1u | ('(' << 8))
&& (v4_ucell)nb.mem[v4_text_word(&tx, "BACKSLASH") - 5] == (1u | ('\\' << 8))
&& (v4_ucell)nb.mem[v4_text_word(&tx, "COLON") - 5] == (1u | (':' << 8))
&& (v4_ucell)nb.mem[v4_text_word(&tx, "SEMI") - 5] == (1u | (';' << 8)), "are names like any other");
CHECK(ok("header data-word data : D 1 ;") && nb.mem[v4_text_word(&tx, "D") - 3] == 4, "the data flag");
CHECK(ok("header 1234567890123456789012345678901 : W ;"), "a 31-character name fits");
CHECK(refused("header 12345678901234567890123456789012 : W ;", "at most 31 characters", 1), "a 32-character one is refused");