code wiki / _hdl_build / nx_wiki_exceed.nx
nx_wiki_exceed.nx source
↩ module page · 176 lines · 7787 B
1// nx_wiki_exceed.nx -- MEASURED head-to-head of a Nishi wiki page vs the incumbent wiki engine.
2//
3// module: nishi-core.wiki.exceed_census
4// capability: CORE_COMPUTE (the honest "how far is our page from a real wiki page" measurement)
5//
6// Per the no-wave law: an EXCEED is MEASURED per-feature, never self-graded. This organ reads
7// knowledge/registry/wiki_feature_census.tsv (the MediaWiki/Wikipedia feature bar) and SCANS the actual
8// rendered page for each feature's signal -> PRESENT/ABSENT, COMPUTED, not asserted. It reports how many
9// of the incumbent's features our page has, and is HONEST that being behind is the worklist (it refuses
10// to call a behind page an "exceed"). The wiki PAGE BUILDER climbs this census rung by rung.
11// Sovereign: imports only nx_syscalls. license_tier: ORIGINAL
12
13import "nx_syscalls.nx"
14import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc)
15
16const WE_CENSUS: *u8 = "knowledge/registry/wiki_feature_census.tsv"
17const WE_PAGE: *u8 = "web_assets/charter.html"
18
19static WE_N: i64
20static WE_FID: i64 // *i64 of *u8
21static WE_INC: i64 // *i64 of i64 (incumbent_has 0/1)
22static WE_SIG: i64 // *i64 of *u8
23static WE_NOTE: i64 // *i64 of *u8
24static WE_PRESENT: i64 // *i64 of i64 (computed present 0/1)
25
26func we_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != 0 as u8 { n = n + 1 } sys_write(1, s, n); return 0 }
27// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer
28// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the
29// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls).
30// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign.
31func we_putn(v: i64) -> i64 { nxi_out(v); return 0 }
32func we_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != 0 as u8 { n = n + 1 } return n }
33
34func we_field_dup(b: *u8, ls: i64, le: i64, f: i64) -> *u8 {
35 var cur: i64 = 0
36 var i: i64 = ls
37 while cur < f {
38 if i >= le { let e: *u8 = sys_mmap(2); e[0] = 0 as u8; return e }
39 if b[i] == 9 as u8 { cur = cur + 1 }
40 i = i + 1
41 }
42 let out: *u8 = sys_mmap(256)
43 var o: i64 = 0
44 while i < le {
45 if b[i] == 9 as u8 { i = le } else { if o < 255 { out[o] = b[i]; o = o + 1 } i = i + 1 }
46 }
47 out[o] = 0 as u8
48 return out
49}
50
51// substring contains: 1 if needle occurs in hay[0..hn). flag-style (no break/continue in nested ifs).
52func we_contains(hay: *u8, hn: i64, needle: *u8) -> i64 {
53 let nl: i64 = we_slen(needle)
54 if nl == 0 { return 0 }
55 if hn < nl { return 0 }
56 var i: i64 = 0
57 let last: i64 = hn - nl
58 var hit: i64 = 0
59 while i <= last {
60 if hit == 0 {
61 var j: i64 = 0; var ok: i64 = 1
62 while j < nl { if hay[i + j] != needle[j] { ok = 0; j = nl } else { j = j + 1 } }
63 if ok == 1 { hit = 1 }
64 }
65 i = i + 1
66 }
67 return hit
68}
69
70// MEASURE: parse the census, scan `page_file`, fill module globals + outs.
71// outs[0]=n_features outs[1]=incumbent_total outs[2]=ours_match(of incumbent) outs[3]=behind
72func we_measure(census_file: *u8, page_file: *u8, outs: *i64) -> i64 {
73 let lenbox: *i64 = sys_mmap(16) as *i64; lenbox[0] = 0
74 let data: *u8 = sys_read_file(census_file, lenbox)
75 if (data as i64) == 0 { return 0 - 1 }
76 let n: i64 = lenbox[0]
77 var rows: i64 = 0; var ls: i64 = 0; var i: i64 = 0
78 while i <= n {
79 var atend: i64 = 0
80 if i == n { atend = 1 }
81 if i < n { if data[i] == 10 as u8 { atend = 1 } }
82 if atend == 1 { if i > ls { if data[ls] != 35 as u8 { rows = rows + 1 } } ls = i + 1 }
83 i = i + 1
84 }
85 let fid: *i64 = sys_mmap(8 * (rows + 1)) as *i64
86 let inc: *i64 = sys_mmap(8 * (rows + 1)) as *i64
87 let sig: *i64 = sys_mmap(8 * (rows + 1)) as *i64
88 let note: *i64 = sys_mmap(8 * (rows + 1)) as *i64
89 let present: *i64 = sys_mmap(8 * (rows + 1)) as *i64
90 var r: i64 = 0
91 ls = 0; i = 0
92 while i <= n {
93 var atend: i64 = 0
94 if i == n { atend = 1 }
95 if i < n { if data[i] == 10 as u8 { atend = 1 } }
96 if atend == 1 {
97 if i > ls { if data[ls] != 35 as u8 {
98 fid[r] = we_field_dup(data, ls, i, 0) as i64
99 let inctok: *u8 = we_field_dup(data, ls, i, 1)
100 var iv: i64 = 0
101 if inctok[0] == 49 as u8 { iv = 1 }
102 inc[r] = iv
103 sig[r] = we_field_dup(data, ls, i, 2) as i64
104 note[r] = we_field_dup(data, ls, i, 4) as i64
105 present[r] = 0
106 r = r + 1
107 } }
108 ls = i + 1
109 }
110 i = i + 1
111 }
112 WE_N = r
113 WE_FID = fid as i64; WE_INC = inc as i64; WE_SIG = sig as i64; WE_NOTE = note as i64; WE_PRESENT = present as i64
114
115 // read the target page (unreadable -> treated as all-absent, the honest worst case).
116 let pbox: *i64 = sys_mmap(16) as *i64; pbox[0] = 0
117 let page: *u8 = sys_read_file(page_file, pbox)
118 var pn: i64 = 0
119 if (page as i64) != 0 { pn = pbox[0] }
120
121 var inc_total: i64 = 0; var ours_match: i64 = 0; var behind: i64 = 0; var exceed: i64 = 0
122 var c: i64 = 0
123 while c < WE_N {
124 var pr: i64 = 0
125 if pn > 0 { pr = we_contains(page, pn, sig[c] as *u8) }
126 present[c] = pr
127 if inc[c] == 1 {
128 inc_total = inc_total + 1
129 if pr == 1 { ours_match = ours_match + 1 } else { behind = behind + 1 }
130 }
131 if inc[c] == 0 { if pr == 1 { exceed = exceed + 1 } }
132 c = c + 1
133 }
134 outs[0] = WE_N; outs[1] = inc_total; outs[2] = ours_match; outs[3] = behind; outs[4] = exceed
135 return 0
136}
137
138func main() -> i64 {
139 we_puts("=== NISHI WIKI PAGE vs INCUMBENT (MediaWiki/Wikipedia) -- MEASURED feature census ===\n")
140 let outs: *i64 = sys_mmap(256) as *i64
141 if we_measure(WE_CENSUS, WE_PAGE, outs) != 0 {
142 we_puts("FATAL: "); we_puts(WE_CENSUS); we_puts(" unreadable\n"); sys_exit(1); return 1
143 }
144 we_puts(" page measured: "); we_puts(WE_PAGE); we_puts("\n")
145 let fids: *i64 = WE_FID as *i64
146 let incs: *i64 = WE_INC as *i64
147 let notes: *i64 = WE_NOTE as *i64
148 let pres: *i64 = WE_PRESENT as *i64
149 var i: i64 = 0
150 while i < WE_N {
151 if pres[i] == 1 { we_puts(" [x] ") } else { we_puts(" [ ] ") }
152 we_puts(fids[i] as *u8)
153 if incs[i] == 1 { we_puts(" (MediaWiki: yes) ") } else { we_puts(" (MediaWiki: no) ") }
154 we_puts(notes[i] as *u8); we_puts("\n")
155 i = i + 1
156 }
157 we_puts(" MEASURED: ours="); we_putn(outs[2])
158 we_puts("/"); we_putn(outs[1])
159 we_puts(" standard incumbent features present; BEHIND by "); we_putn(outs[3])
160 we_puts("; EXCEED axes present (incumbent lacks)="); we_putn(outs[4]); we_puts(".\n")
161 if outs[3] == 0 {
162 if outs[4] > 0 {
163 we_puts(" VERDICT: MEASURED S-class -- PARITY on all "); we_putn(outs[1])
164 we_puts(" standard wiki features AND exceeds on "); we_putn(outs[4])
165 we_puts(" axis(es) the incumbent structurally lacks (machine-verified live evidence, no-drift regeneration).\n")
166 we_puts(" NARROW + HONEST: the exceed is on integrity/freshness for a self-documenting system -- NOT a claim of beating Wikipedia on content/scale/community.\n")
167 } else {
168 we_puts(" VERDICT: PARITY on all "); we_putn(outs[1])
169 we_puts(" standard features -- an exceed claim is EARNABLE (add an axis the incumbent lacks).\n")
170 }
171 } else {
172 we_puts(" VERDICT: NOT S-class -- BEHIND the incumbent by "); we_putn(outs[3])
173 we_puts(" features. Those ABSENT features ARE the page builder's worklist (no overclaim).\n")
174 }
175 sys_exit(0); return 0
176}