code wiki / _hdl_build / nx_gatemap_gate.nx

nx_gatemap_gate.nx source

↩ module page · 184 lines · 8550 B

1// nx_gatemap_gate.nx -- WHICH DOMAIN DOES EACH UNWIRED GATE BELONG TO? Proposes, never writes. 2// 3// ★THE FINDING THIS SERVES (id=1785448222): 214 `_gate.elf` binaries exist on this host and only 19 are 4// DECLARED in any knowledge/compare/<domain>.gates. Thirty of forty domains read CLAIM-ONLY not because 5// nobody built the evidence but because nobody WIRED it. 0/40 PROVEN understates what is provable today by 6// roughly an order of magnitude. 7// 8// ★THE RULE IS STRUCTURAL, NOT A GUESS: **a gate belongs to the domain whose MATRIX NAMES ITS STEM.** 9// A `<domain>.matrix` row carries the organ path it claims (`runtime/nx_natstat.nx`, `runtime/_hdl_build/ 10// nx_vcodec_t8noise_gate.nx`). So for gate `nx_X_gate` the question is simply: which matrix mentions `nx_X`? 11// That is a fact about the corpus, not a similarity score, and it CANNOT drift the way keyword matching 12// does. A gate no matrix mentions is REFUSED, not assigned to its nearest neighbour. 13// ★WHY REFUSAL MATTERS AS MUCH AS THE MATCH: a wrong domain assignment is the same slander class as a wrong 14// subject -- it makes a working gate count against a domain it was never about. UNMATCHED is the honest 15// answer and it is cheap to read. 16// 17// ★AMBIGUITY IS REPORTED, NEVER BROKEN BY TASTE. If two matrices name the same stem the gate is listed as 18// AMBIGUOUS with both domains, because picking one silently is how a wiring pass launders a judgement call 19// into a fact. 20// 21// It WRITES NOTHING. Output is a proposal for human review (that is the whole point -- the operator asked to 22// see it before it lands). 23// 24// usage: nx_gatemap_gate (CWD = the store root) 25// exit 0 always -- this is a census, not a pass/fail gate; the verdict line reports the counts. 26// license_tier: ORIGINAL expect_exit: 0 27import "nx_syscalls.nx" 28 29const GM_MAXDOM: i64 = 128 30const GM_NAMEW: i64 = 64 31const GM_MATCAP: i64 = 262144 32const GM_MAXGATE: i64 = 512 33 34static gm_dnames: *u8 35static gm_dn: i64 36static gm_mbuf: *u8 37 38func w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 39func wn(v: i64) -> i64 { let t: *u8=sys_mmap(28); var m: i64=v; var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} let b: *u8=sys_mmap(28); var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 } 40 41func gm_dslot(i: i64) -> *u8 { return ((gm_dnames as i64) + i * GM_NAMEW) as *u8 } 42 43func gm_read(path: *u8, buf: *u8, cap: i64) -> i64 { 44 let fd: i64 = sys_openat_rd(path) 45 if fd < 0 { return 0 - 1 } 46 var tot: i64 = 0 47 var go: i64 = 1 48 while go == 1 { 49 let n: i64 = sys_read(fd, ((buf as i64)+tot) as *u8, cap - tot) 50 if n <= 0 { go = 0 } else { tot = tot + n; if tot >= cap { go = 0 } } 51 } 52 sys_close(fd) 53 return tot 54} 55func gm_find(hay: *u8, hn: i64, ned: *u8, nl: i64) -> i64 { 56 if nl <= 0 { return 0 - 1 } 57 var i: i64 = 0 58 while i + nl <= hn { 59 var j: i64 = 0 60 var m: i64 = 1 61 while j < nl { if hay[i+j] != ned[j] { m = 0; j = nl } else { j = j + 1 } } 62 if m == 1 { return i } 63 i = i + 1 64 } 65 return 0 - 1 66} 67func gm_cat(dst: *u8, off: i64, s: *u8) -> i64 { var o: i64=off; var i: i64=0; while s[i]!=(0 as u8){dst[o]=s[i];o=o+1;i=i+1} return o } 68 69func main() -> i64 { 70 gm_dnames = sys_mmap(GM_MAXDOM * GM_NAMEW) 71 gm_mbuf = sys_mmap(GM_MATCAP) 72 gm_dn = 0 73 74 w("=== nx_gatemap_gate -- unwired gates mapped to the domain whose MATRIX NAMES THEM ===\n") 75 76 // ---- collect domain names from knowledge/compare/*.matrix ---- 77 let dbuf: *u8 = sys_mmap(1 << 16) 78 var fd: i64 = sys_openat_rd("knowledge/compare\x00" as *u8) 79 if fd < 0 { w(" cannot open knowledge/compare\n"); sys_exit(2); return 2 } 80 var go: i64 = 1 81 while go == 1 { 82 let nr: i64 = sys_getdents64(fd, dbuf, 1 << 16) 83 if nr <= 0 { go = 0 } else { 84 var pos: i64 = 0 85 while pos < nr { 86 let rec: *u8 = ((dbuf as i64) + pos) as *u8 87 let reclen: i64 = dirent_reclen(rec) 88 let name: *u8 = ((rec as i64) + 19) as *u8 89 var ln: i64 = 0 90 while name[ln] != (0 as u8) { ln = ln + 1 } 91 var ism: i64 = 0 92 if ln > 7 { 93 let sfx: *u8 = ".matrix\x00" as *u8 94 var m: i64 = 1 95 var q: i64 = 0 96 while q < 7 { if name[ln-7+q] != sfx[q] { m = 0; q = 7 } else { q = q + 1 } } 97 ism = m 98 } 99 if ism == 1 { if gm_dn < GM_MAXDOM { if ln - 7 < GM_NAMEW - 1 { 100 let s: *u8 = gm_dslot(gm_dn) 101 var c: i64 = 0 102 while c < ln - 7 { s[c] = name[c]; c = c + 1 } 103 s[ln-7] = 0 as u8 104 gm_dn = gm_dn + 1 105 } } } 106 if reclen <= 0 { pos = nr } else { pos = pos + reclen } 107 } 108 } 109 } 110 sys_close(fd) 111 w(" domains="); wn(gm_dn); w("\n") 112 113 // ---- walk gate elfs in the serving root; for each, ask which matrix names its stem ---- 114 let path: *u8 = sys_mmap(512) 115 let stem: *u8 = sys_mmap(GM_NAMEW) 116 let hit1: *u8 = sys_mmap(GM_NAMEW) 117 var gates: i64 = 0 118 var matched: i64 = 0 119 var ambiguous: i64 = 0 120 var unmatched: i64 = 0 121 122 fd = sys_openat_rd(".\x00" as *u8) 123 if fd < 0 { w(" cannot open cwd\n"); sys_exit(2); return 2 } 124 go = 1 125 while go == 1 { 126 let nr: i64 = sys_getdents64(fd, dbuf, 1 << 16) 127 if nr <= 0 { go = 0 } else { 128 var pos: i64 = 0 129 while pos < nr { 130 let rec: *u8 = ((dbuf as i64) + pos) as *u8 131 let reclen: i64 = dirent_reclen(rec) 132 let name: *u8 = ((rec as i64) + 19) as *u8 133 var ln: i64 = 0 134 while name[ln] != (0 as u8) { ln = ln + 1 } 135 // exactly `<stem>_gate.elf` -- .prev/.bak/.DISABLED copies are excluded by construction 136 var isg: i64 = 0 137 if ln > 13 { 138 let sfx: *u8 = "_gate.elf\x00" as *u8 139 var m: i64 = 1 140 var q: i64 = 0 141 while q < 9 { if name[ln-9+q] != sfx[q] { m = 0; q = 9 } else { q = q + 1 } } 142 isg = m 143 } 144 if isg == 1 { if ln - 4 < GM_NAMEW - 1 { 145 gates = gates + 1 146 // stem INCLUDING _gate (that is what a matrix row would name), minus ".elf" 147 var c: i64 = 0 148 while c < ln - 4 { stem[c] = name[c]; c = c + 1 } 149 stem[ln-4] = 0 as u8 150 let sl: i64 = ln - 4 151 var found: i64 = 0 152 var d: i64 = 0 153 while d < gm_dn { 154 var o: i64 = gm_cat(path, 0, "knowledge/compare/" as *u8) 155 o = gm_cat(path, o, gm_dslot(d)) 156 o = gm_cat(path, o, ".matrix" as *u8) 157 path[o] = 0 as u8 158 let mn: i64 = gm_read(path, gm_mbuf, GM_MATCAP) 159 if mn > 0 { if gm_find(gm_mbuf, mn, stem, sl) >= 0 { 160 found = found + 1 161 if found == 1 { var z: i64 = 0; let ds: *u8 = gm_dslot(d); while ds[z] != (0 as u8) { hit1[z] = ds[z]; z = z + 1 } hit1[z] = 0 as u8 } 162 else { w(" AMBIGUOUS "); w(stem); w(" also="); w(gm_dslot(d)); w("\n") } 163 } } 164 d = d + 1 165 } 166 if found == 1 { matched = matched + 1; w(" MAP "); w(stem); w(" -> "); w(hit1); w("\n") } 167 else { if found > 1 { ambiguous = ambiguous + 1; w(" AMBIGUOUS "); w(stem); w(" first="); w(hit1); w(" (NOT auto-assigned)\n") } else { unmatched = unmatched + 1 } } 168 } } 169 if reclen <= 0 { pos = nr } else { pos = pos + reclen } 170 } 171 } 172 } 173 sys_close(fd) 174 175 w(" gate_elfs="); wn(gates) 176 w(" mapped="); wn(matched) 177 w(" ambiguous="); wn(ambiguous) 178 w(" unmatched="); wn(unmatched); w("\n") 179 w(" UNMATCHED means no domain matrix names that gate -- it is NOT evidence for any declared claim yet,\n") 180 w(" and inventing a home for it would make a working gate count against a domain it was never about.\n") 181 w("VERDICT: verdict=GREEN (census only -- nothing written; review the MAP lines before wiring)\n") 182 sys_exit(0) 183 return 0 184}