code wiki / _hdl_build / nx_memplane_lib.nx
nx_memplane_lib.nx
buildroot/runtime/_hdl_build/nx_memplane_lib.nx
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
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
| 34 | const MP_SLOT: i64 = 128 // per-name byte slot |
| 35 | const MP_HASH: i64 = 32768 // name index slots (power of two, > 2x corpus) |
| 36 | const MP_MAXF: i64 = 8192 // max memory nodes |
| 168 | const MP_DERIVED_MARK: *u8 = "<!-- NX-DERIVED: regenerated artefact, not authored memory -->" |
functions
| 40 | func mp_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 42 | func mp_streq(a: *u8, b: *u8) -> i64 |
| 54 | func mp_cat(buf: *u8, off: i64, s: *u8) -> i64 |
| 61 | func mp_catn(buf: *u8, off: i64, v: i64) -> i64 |
| 74 | func mp_write_all(fd: i64, buf: *u8, n: i64) -> i64 |
| 85 | func mp_say(buf: *u8, n: i64) -> i64 { return mp_write_all(1, buf, n) } |
| 87 | func mp_alnum(c: u8) -> i64 |
| 96 | func mp_join(dst: *u8, dir: *u8, name: *u8) -> i64 |
| 107 | func mp_readf(p: *u8, buf: *u8, cap: i64) -> i64 |
| 123 | func mp_is_md(name: *u8) -> i64 |
| 132 | func mp_base(p: *u8) -> *u8 |
| 147 | func mp_is_dump(name: *u8) -> i64 |
| 170 | func mp_is_derived(buf: *u8, n: i64) -> i64 |
| 188 | func mp_nameptr(names: *u8, i: i64) -> *u8 { return ((names as i64) + i * MP_SLOT) as *u8 } |
| 190 | func mp_hashr(p: *u8, n: i64) -> i64 |
| 201 | func mp_eqr(a: *u8, p: *u8, n: i64) -> i64 called by 1: mp_get |
| 208 | func mp_put(tbl: *i64, names: *u8, idx: i64) -> i64 |
| 218 | func mp_get(tbl: *i64, names: *u8, p: *u8, n: i64) -> i64 |
| 232 | func mp_scan(dir: *u8, names: *u8, tbl: *i64, cap: i64) -> i64 |
| 275 | func mp_link_next(buf: *u8, n: i64, from: i64, out: *i64) -> i64 |
| 337 | func mp_resolve(buf: *u8, out: *i64, names: *u8, tbl: *i64, scratch: *u8) -> i64 |
| 356 | func mp_declparent(buf: *u8, n: i64, out: *u8) -> i64 |