code wiki / _hdl_build / nx_memplane_lib.nx

nx_memplane_lib.nx

buildroot/runtime/_hdl_build/nx_memplane_lib.nx

16330 B408 linesdepth 2pulls 2 transitivereach 13 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_memplane_lib.nx -- shared primitives for the memory-plane organs. WHY THIS EXISTS (two reasons, both measured) ------------------------------------------- 1. RULE 15. Six organs -- memcliff, memhealth, memfix, memorph, memfind, memroot -- each carried its own copy of: the getdents64 directory walk, the name table + open-addressing index, the bounded file read, the path join, and the markdown/wiki link scanner. That is a pattern in six services, copied by hand each time. 2. THE COPIES DRIFTED, AND THE DRIFT WAS THE BUG. Each defence below was learned once, banked in ONE organ, and then absent from the next one written: * DUMP EXCLUSION -- memhealth, memorph and memfind all skip the aggregate dumps. memroot did not, so its first live run walked MEMORY.md -> reference-orphan-catalogue -> everything the catalogue listed and reported ROOTED 2178 / FLOATING 0 / GREEN, contradicting an already measured 581 orphans. A false GREEN on the one metric that would have exposed the problem. * NESTED-ARRAY REJECTION -- a scanner that stops at the first `]]` reads `[[433,94,2],[434,90,2]]` out of a code block as a wiki link. 25 of memhealth's first 427 "dangling" links were this. * FRONTMATTER-ONLY PARENT -- `parent:` appears in prose ("kill children before parent:"), and a grep counting those said 9 declared edges when the truth was 0. ★★★★★★ A LAW BANKED IN ONE ORGAN IS NOT BANKED IN THE NEXT. Putting the defence in a shared lib is the only version of "we learned that" that survives the next author. 3. IT IS ALSO WHAT MAKES GATES SOVEREIGN. Every gate for these organs was a `sh` script run by WSL from PowerShell -- Linux shell + Windows host + third-party runtime on the program path, in violation of the estate's own bits-up doctrine. A gate cannot import a monolith that owns `main()`, so shell was the only way to exercise them. With the logic in a lib, the gate becomes an ORGAN that imports it and asserts IN-PROCESS: no shell, no fixture scripts, no CRLF or backtick-escape corruption (both of which cost real debugging time this session). Lineage: the getdents64 + name-slot walk is the proven nx_ws_index_lib / nx_sov_tree_audit idiom. Sovereign: imports only nx_syscalls. license_tier: ORIGINAL

dependencies 1 imports · 13 importers

nx_syscalls.nx nx_memplane_lib.nx nx_engine_dispatch.nx nx_gatesubj.nx nx_memcliff.nx nx_memfind.nx nx_memfix.nx nx_memhealth.nx nx_memorph.nx nx_memplane_gate.nx nx_memroot.nx nx_seat_meter_beat.nx

diagram shows first 10 each side; +0 more imports, +3 more importers in the complete lists below.

imports: nx_syscalls.nx

imported by: nx_engine_dispatch.nxnx_gatesubj.nxnx_memcliff.nxnx_memfind.nxnx_memfix.nxnx_memhealth.nxnx_memorph.nxnx_memplane_gate.nxnx_memroot.nxnx_seat_meter_beat.nxnx_srclint.nxnx_stderronly.nxnx_unwired.nx

structs

none

consts

34const MP_SLOT: i64 = 128 // per-name byte slot
35const MP_HASH: i64 = 32768 // name index slots (power of two, > 2x corpus)
36const MP_MAXF: i64 = 8192 // max memory nodes
168const MP_DERIVED_MARK: *u8 = "<!-- NX-DERIVED: regenerated artefact, not authored memory -->"

functions

40func mp_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
42func mp_streq(a: *u8, b: *u8) -> i64
54func mp_cat(buf: *u8, off: i64, s: *u8) -> i64
61func mp_catn(buf: *u8, off: i64, v: i64) -> i64
74func mp_write_all(fd: i64, buf: *u8, n: i64) -> i64
85func mp_say(buf: *u8, n: i64) -> i64 { return mp_write_all(1, buf, n) }
called by 10: mainmainmainmainmainmain+4 calls 1: mp_write_all
87func mp_alnum(c: u8) -> i64
96func mp_join(dst: *u8, dir: *u8, name: *u8) -> i64
107func mp_readf(p: *u8, buf: *u8, cap: i64) -> i64
123func mp_is_md(name: *u8) -> i64
called by 2: mainmp_scan calls 1: mp_len
132func mp_base(p: *u8) -> *u8
called by 1: main calls 1: mp_len
147func mp_is_dump(name: *u8) -> i64
called by 6: mainmainmainmainmainmain calls 1: mp_streq
170func mp_is_derived(buf: *u8, n: i64) -> i64
called by 4: mainmainmainmain calls 1: mp_len
188func mp_nameptr(names: *u8, i: i64) -> *u8 { return ((names as i64) + i * MP_SLOT) as *u8 }
called by 13: mainmainmainmainmainmain+7
190func mp_hashr(p: *u8, n: i64) -> i64
called by 2: mp_putmp_get
201func mp_eqr(a: *u8, p: *u8, n: i64) -> i64
called by 1: mp_get
208func mp_put(tbl: *i64, names: *u8, idx: i64) -> i64
218func mp_get(tbl: *i64, names: *u8, p: *u8, n: i64) -> i64
232func mp_scan(dir: *u8, names: *u8, tbl: *i64, cap: i64) -> i64
337func mp_resolve(buf: *u8, out: *i64, names: *u8, tbl: *i64, scratch: *u8) -> i64
called by 4: mainmainmainmain calls 1: mp_get
356func mp_declparent(buf: *u8, n: i64, out: *u8) -> i64
called by 2: mainmain calls 1: mp_len