code wiki / _hdl_build / nx_vacuity_census.nx
nx_vacuity_census.nx source
↩ module page · 562 lines · 26156 B
1// nx_vacuity_census.nx -- WHICH RENDER-GATES CANNOT SEE A MISSING FEATURE AT ALL.
2//
3// THE DEFECT IT MEASURES, from a real one caught 2026-08-14. nx_wasm_craft_gate passed 58/58 while the
4// game had NO CHARACTERS IN THE PICTURE. Its mob teeth (T16/T17/T28/T29) assert the girls exist in
5// STATE; its frame teeth (T3/T19/T23) assert the frame has colour VARIETY. Both are true of a frame
6// with every character missing, because the terrain alone satisfies them. The renderer had started
7// writing one pixel per ray while mob_draw still projected into the framebuffer CEILING, so every girl
8// landed outside the written region -- and not one tooth could tell.
9//
10// THE EXACT PREDICATE, and it is a PROOF rather than a heuristic: to detect that feature X is absent
11// from a picture, a gate must hold TWO frames that differ only in X and compare them. A gate that
12// renders EXACTLY ONCE cannot do that -- there is no second frame to compare against.
13// ⚠WHAT THIS IS AND IS NOT. It is a STRONG CANDIDATE FILTER, not a proof. v1 of this header called
14// render_calls==1 a sound certificate with no false negatives; that was wrong twice over, and both
15// corrections are recorded here rather than quietly edited away:
16// 1. a call SITE is not a render -- one site inside a helper main invokes N times is N renders
17// (nx_wasm_mineworld_gate, which v1 wrongly accused). FIXED: each site is multiplied by its
18// enclosing function's invocation count.
19// 2. an invocation inside a LOOP is one static site but many runtime renders, and this organ does
20// no brace matching, so such a gate still reads as 1. That is the remaining false-positive
21// class and it is NOT fixed -- read the gate before acting on its row.
22// The converse was never claimed and still is not: a gate that renders MANY times can be just as
23// blind. nx_wasm_craft_gate rendered dozens of times and still could not see that every character
24// was missing, because it never compared two frames differing only in the characters.
25// Both directions land in the same place: this names candidates, and nx_gate_bite decides.
26//
27// WHY THIS IS TRIAGE AND NOT A SECOND RULER: nx_gate_bite mutates the SUBJECT and rebuilds it. For
28// nx_wasm_craft that is ~30 minutes per mutant, so it can never sweep a fleet. This census is static
29// and instant, and its whole job is to tell the expensive instrument where to spend. Composition,
30// not duplication -- the same reason the estate has one line-differ and many tallies.
31//
32// DECLARED IMPRECISION (so the next reader does not trust it as exact):
33// - a gate that renders through a wrapper it defines itself counts as 0 render calls
34// - a backslash-escaped quote inside a string literal is not tracked, so a token inside such a
35// string could be counted as code
36// - the token list below is the render entries this estate actually uses; a new render entry must
37// be added here or its gates read as NOT-A-RENDER-GATE
38// license_tier: ORIGINAL
39import "nx_syscalls.nx"
40
41const VC_DIRBUF: i64 = 131072
42const VC_NAMEBUF: i64 = 4096
43const VC_MAXSHOW: i64 = 60 // printed worklist head; the COUNTS are always the full population
44const VC_CH_NL: i64 = 10
45const VC_CH_SP: i64 = 32
46const VC_CH_QUOTE: i64 = 34
47const VC_CH_SLASH: i64 = 47
48// anti-vacuity floor: this estate has thousands of gate sources. Finding almost none means the scan
49// is pointed at the wrong tree, and a census that reports a confident near-zero is worse than one
50// that refuses. Measured 2026-08-14: 2,317 gate sources estate-wide.
51const VC_MIN_GATES: i64 = 200
52// THE RATCHET. A census nobody enforces is a report, and a report is a comment. This floor only ever
53// falls: fixing a gate tightens it automatically, and a NEW render-once gate pushes the count above it
54// and goes RED with the offenders NAMED above -- a count without a worklist is not actionable.
55const VC_CONF: *u8 = "knowledge/status/vacuity.conf"
56
57func vc_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
58func vc_num(v: i64) -> i64 {
59 if v == 0 { vc_puts("0" as *u8); return 0 }
60 var x: i64 = v
61 var neg: i64 = 0
62 if x < 0 { neg = 1; x = 0 - x }
63 let d: *u8 = sys_mmap(32)
64 var k: i64 = 0
65 while x > 0 { d[k] = (48 + (x % 10)) as u8; x = x / 10; k = k + 1 }
66 let o: *u8 = sys_mmap(34)
67 var w: i64 = 0
68 if neg == 1 { o[0] = 45 as u8; w = 1 }
69 var j: i64 = 0
70 while j < k { o[w+j] = d[k-1-j]; j = j + 1 }
71 sys_write(1, o, w + k)
72 return 0
73}
74
75// name ends with "_gate.nx"
76func vc_is_gate(nm: *u8) -> i64 {
77 var n: i64 = 0
78 while nm[n] != (0 as u8) { n = n + 1 }
79 if n < 9 { return 0 }
80 let s: i64 = n - 8
81 if nm[s] != (95 as u8) { return 0 }
82 if nm[s+1] != (103 as u8) { return 0 }
83 if nm[s+2] != (97 as u8) { return 0 }
84 if nm[s+3] != (116 as u8) { return 0 }
85 if nm[s+4] != (101 as u8) { return 0 }
86 if nm[s+5] != (46 as u8) { return 0 }
87 if nm[s+6] != (110 as u8) { return 0 }
88 if nm[s+7] != (120 as u8) { return 0 }
89 return 1
90}
91
92func vc_match(b: *u8, n: i64, p: i64, t: *u8) -> i64 {
93 var i: i64 = 0
94 var ok: i64 = 1
95 var go: i64 = 1
96 while go == 1 {
97 if t[i] == (0 as u8) { go = 0 } else {
98 if p + i >= n { ok = 0; go = 0 } else {
99 if b[p+i] != t[i] { ok = 0; go = 0 } else { i = i + 1 }
100 }
101 }
102 }
103 return ok
104}
105
106// a definition ("func render_impl(") is NOT a call site. Without this the engine's own source, and any
107// gate that re-declares a helper, would be counted as if it rendered.
108func vc_after_func(b: *u8, p: i64) -> i64 {
109 var q: i64 = p - 1
110 var stop: i64 = 0
111 while stop == 0 {
112 if q < 0 { stop = 1 } else {
113 if b[q] == (VC_CH_SP as u8) { q = q - 1 } else { stop = 1 }
114 }
115 }
116 if q < 3 { return 0 }
117 if b[q] != (99 as u8) { return 0 }
118 if b[q-1] != (110 as u8) { return 0 }
119 if b[q-2] != (117 as u8) { return 0 }
120 if b[q-3] != (102 as u8) { return 0 }
121 return 1
122}
123
124const VC_MAXFN: i64 = 1024
125static VC_FNS: i64
126static VC_FNL: i64
127static VC_FBS: i64
128// allocated ONCE, never in the per-file loop: 3 tables x 1024 x 8 B re-mmap'd across 3,217 files
129// would be 77 MB of churn to answer a question that needs 24 KB.
130func vc_tables() -> i64 {
131 if VC_FNS == 0 {
132 VC_FNS = sys_mmap(VC_MAXFN*8) as i64
133 VC_FNL = sys_mmap(VC_MAXFN*8) as i64
134 VC_FBS = sys_mmap(VC_MAXFN*8) as i64
135 }
136 return 0
137}
138
139func vc_name_end(b: *u8, n: i64, s: i64) -> i64 {
140 var q: i64 = s
141 var stop: i64 = 0
142 while stop == 0 {
143 if q >= n { stop = 1 } else {
144 let c: i64 = b[q] as i64
145 if c == 40 { stop = 1 } else { if c == VC_CH_SP { stop = 1 } else { if c == VC_CH_NL { stop = 1 } else { q = q + 1 } } }
146 }
147 }
148 return q
149}
150
151func vc_eq(b: *u8, a: i64, alen: i64, p: i64, n: i64) -> i64 {
152 if p + alen > n { return 0 }
153 var i: i64 = 0
154 var ok: i64 = 1
155 while i < alen { if b[p+i] != b[a+i] { ok = 0; i = alen } else { i = i + 1 } }
156 return ok
157}
158
159func vc_isword(c: i64) -> i64 {
160 if c == 95 { return 1 }
161 if c >= 48 { if c <= 57 { return 1 } }
162 if c >= 65 { if c <= 90 { return 1 } }
163 if c >= 97 { if c <= 122 { return 1 } }
164 return 0
165}
166
167// how many times is this function INVOKED. A name followed by '(' that is not its own definition and
168// not the tail of a longer identifier.
169func vc_invocations(b: *u8, n: i64, a: i64, alen: i64) -> i64 {
170 var cnt: i64 = 0
171 var p: i64 = 0
172 var incom: i64 = 0
173 var instr: i64 = 0
174 while p < n {
175 let c: i64 = b[p] as i64
176 if c == VC_CH_NL { incom = 0; instr = 0 }
177 if incom == 0 {
178 if instr == 1 {
179 if c == VC_CH_QUOTE { instr = 0 }
180 } else {
181 if c == VC_CH_QUOTE { instr = 1 } else {
182 var isc: i64 = 0
183 if c == VC_CH_SLASH { if p + 1 < n { if b[p+1] == (VC_CH_SLASH as u8) { isc = 1 } } }
184 if isc == 1 { incom = 1 } else {
185 if vc_eq(b, a, alen, p, n) == 1 {
186 if p + alen < n {
187 if b[p+alen] == (40 as u8) {
188 var okpre: i64 = 1
189 if p > 0 { if vc_isword(b[p-1] as i64) == 1 { okpre = 0 } }
190 if okpre == 1 { if vc_after_func(b, p) == 0 { cnt = cnt + 1 } }
191 }
192 }
193 }
194 }
195 }
196 }
197 }
198 p = p + 1
199 }
200 return cnt
201}
202
203func vc_is_main(b: *u8, a: i64, alen: i64) -> i64 {
204 if alen != 4 { return 0 }
205 if b[a] != (109 as u8) { return 0 }
206 if b[a+1] != (97 as u8) { return 0 }
207 if b[a+2] != (105 as u8) { return 0 }
208 if b[a+3] != (110 as u8) { return 0 }
209 return 1
210}
211
212// out[0] = EFFECTIVE render count, out[1] = framebuffer reads
213// ★CORRECTED AFTER A FALSE POSITIVE, 2026-08-14. v1 counted render CALL SITES and called
214// render_calls==1 a SOUND certificate. nx_wasm_mineworld_gate refuted that within the hour: it has
215// exactly ONE call site, sitting inside a helper rend() that main invokes many times, and it does
216// genuinely difference frames (checksum compare, far vs spawn). A CALL SITE IS NOT A RENDER.
217// This version attributes every render site to its enclosing function and multiplies by how many
218// times that function is invoked; a render written directly in main counts once.
219// Comments and string literals are excluded throughout -- a scanner that does not skip comments
220// measures the documentation, and this organ hunts a defect whose description contains its own
221// pattern, so an unstripped scan would accuse its own header.
222func vc_scan_buf(b: *u8, n: i64, out: *i64) -> i64 {
223 out[0] = 0
224 out[1] = 0
225 vc_tables()
226 let fns: *i64 = VC_FNS as *i64
227 let fnl: *i64 = VC_FNL as *i64
228 let fbs: *i64 = VC_FBS as *i64
229 var nf: i64 = 0
230 var p: i64 = 0
231 var incom: i64 = 0
232 var instr: i64 = 0
233 while p < n {
234 let c: i64 = b[p] as i64
235 if c == VC_CH_NL { incom = 0; instr = 0 }
236 if incom == 0 {
237 if instr == 1 {
238 if c == VC_CH_QUOTE { instr = 0 }
239 } else {
240 if c == VC_CH_QUOTE { instr = 1 } else {
241 var isc: i64 = 0
242 if c == VC_CH_SLASH { if p + 1 < n { if b[p+1] == (VC_CH_SLASH as u8) { isc = 1 } } }
243 if isc == 1 { incom = 1 } else {
244 var atl: i64 = 0
245 if p == 0 { atl = 1 } else { if b[p-1] == (VC_CH_NL as u8) { atl = 1 } }
246 if atl == 1 {
247 if vc_match(b, n, p, "func " as *u8) == 1 {
248 if nf < VC_MAXFN {
249 let s: i64 = p + 5
250 fns[nf] = s
251 fnl[nf] = vc_name_end(b, n, s) - s
252 fbs[nf] = p
253 nf = nf + 1
254 }
255 }
256 }
257 }
258 }
259 }
260 }
261 p = p + 1
262 }
263 p = 0
264 incom = 0
265 instr = 0
266 while p < n {
267 let c2: i64 = b[p] as i64
268 if c2 == VC_CH_NL { incom = 0; instr = 0 }
269 if incom == 0 {
270 if instr == 1 {
271 if c2 == VC_CH_QUOTE { instr = 0 }
272 } else {
273 if c2 == VC_CH_QUOTE { instr = 1 } else {
274 var isc2: i64 = 0
275 if c2 == VC_CH_SLASH { if p + 1 < n { if b[p+1] == (VC_CH_SLASH as u8) { isc2 = 1 } } }
276 if isc2 == 1 { incom = 1 } else {
277 var hit: i64 = 0
278 if vc_match(b, n, p, "render_impl(" as *u8) == 1 { hit = 1 }
279 if vc_match(b, n, p, "trimesh_render(" as *u8) == 1 { hit = 1 }
280 if vc_match(b, n, p, "trimesh_render_aa(" as *u8) == 1 { hit = 1 }
281 if vc_match(b, n, p, "render_at(" as *u8) == 1 { hit = 1 }
282 if hit == 1 { if vc_after_func(b, p) == 0 {
283 var k: i64 = 0
284 var enc: i64 = 0 - 1
285 while k < nf { if fbs[k] <= p { enc = k } k = k + 1 }
286 var mult: i64 = 1
287 if enc >= 0 { if vc_is_main(b, fns[enc], fnl[enc]) == 0 {
288 mult = vc_invocations(b, n, fns[enc], fnl[enc])
289 if mult < 1 { mult = 1 }
290 } }
291 out[0] = out[0] + mult
292 } }
293 if vc_match(b, n, p, "wfb(" as *u8) == 1 { if vc_after_func(b, p) == 0 { out[1] = out[1] + 1 } }
294 }
295 }
296 }
297 }
298 p = p + 1
299 }
300 return 0
301}
302
303// sys_read_file sizes its buffer FROM THE FILE, so there is no cap to guess and no silent short read
304func vc_scan_file(path: *u8, out: *i64) -> i64 {
305 let lp: *i64 = sys_mmap(16) as *i64
306 let b: *u8 = sys_read_file(path, lp)
307 if (b as i64) == 0 { return 0 }
308 vc_scan_buf(b, lp[0], out)
309 return 1
310}
311
312// tallies[0]=gate files [1]=not-a-render-gate [2]=RENDER-ONCE [3]=RENDER-MULTI
313func vc_scan_dir(dir: *u8, nbuf: *u8, out: *i64, tal: *i64, shown: *i64) -> i64 {
314 let fd: i64 = sys_openat_rd(dir)
315 if fd < 0 { return 0 }
316 let dbuf: *u8 = sys_mmap(VC_DIRBUF)
317 var go: i64 = 1
318 while go == 1 {
319 let nb: i64 = sys_getdents64(fd, dbuf, VC_DIRBUF)
320 if nb <= 0 { go = 0 } else {
321 var off: i64 = 0
322 while off < nb {
323 let rec: *u8 = ((dbuf as i64) + off) as *u8
324 let rl: i64 = dirent_reclen(rec)
325 if rl <= 0 { off = nb } else {
326 let nm: *u8 = dirent_name(rec)
327 if vc_is_gate(nm) == 1 {
328 var c: i64 = 0
329 while dir[c] != (0 as u8) { nbuf[c] = dir[c]; c = c + 1 }
330 nbuf[c] = 47 as u8
331 c = c + 1
332 var d: i64 = 0
333 while nm[d] != (0 as u8) { nbuf[c+d] = nm[d]; d = d + 1 }
334 nbuf[c+d] = 0 as u8
335 if vc_scan_file(nbuf, out) == 1 {
336 tal[0] = tal[0] + 1
337 if out[0] == 0 {
338 tal[1] = tal[1] + 1
339 } else {
340 if out[0] == 1 {
341 tal[2] = tal[2] + 1
342 if shown[0] < VC_MAXSHOW {
343 vc_puts(" CANNOT-SEE-AN-ABSENT-FEATURE " as *u8); vc_puts(nbuf)
344 vc_puts(" renders=1 fb_reads=" as *u8); vc_num(out[1])
345 vc_puts("\n" as *u8)
346 shown[0] = shown[0] + 1
347 }
348 } else {
349 tal[3] = tal[3] + 1
350 }
351 }
352 }
353 }
354 off = off + rl
355 }
356 }
357 }
358 }
359 sys_close(fd)
360 sys_munmap(dbuf, VC_DIRBUF)
361 return 0
362}
363
364func vc_write_fixture(path: *u8, body: *u8) -> i64 {
365 var n: i64 = 0
366 while body[n] != (0 as u8) { n = n + 1 }
367 let fd: i64 = sys_openat_wr(path, MODE_0644)
368 if fd < 0 { return 0 }
369 sys_write(fd, body, n)
370 sys_close(fd)
371 return 1
372}
373
374// A DETECTOR THAT HAS ONLY EVER AGREED WITH ME IS UNVERIFIED. Each fixture below is a trap this
375// estate has actually fallen into: a comment that contains the pattern, and a DEFINITION mistaken
376// for a call. Both must read ZERO, or the census would accuse every engine source of rendering.
377func vc_selftest() -> i64 {
378 sys_mkdir("/tmp/nx_vacuity_census" as *u8, MODE_0755)
379 let out: *i64 = sys_mmap(64) as *i64
380 var pass: i64 = 0
381 var total: i64 = 0
382
383 vc_write_fixture("/tmp/nx_vacuity_census/one.nx" as *u8, "func main() -> i64 { render_impl(0); return 0 }\n" as *u8)
384 vc_scan_file("/tmp/nx_vacuity_census/one.nx" as *u8, out)
385 total = total + 1
386 vc_puts(" T1 a single render call reads renders=1 got=" as *u8); vc_num(out[0])
387 if out[0] == 1 { pass = pass + 1; vc_puts(" PASS\n" as *u8) } else { vc_puts(" FAIL\n" as *u8) }
388
389 vc_write_fixture("/tmp/nx_vacuity_census/two.nx" as *u8, "func main() -> i64 { render_impl(0); render_impl(1); return 0 }\n" as *u8)
390 vc_scan_file("/tmp/nx_vacuity_census/two.nx" as *u8, out)
391 total = total + 1
392 vc_puts(" T2 two render calls read renders=2 got=" as *u8); vc_num(out[0])
393 if out[0] == 2 { pass = pass + 1; vc_puts(" PASS\n" as *u8) } else { vc_puts(" FAIL\n" as *u8) }
394
395 vc_write_fixture("/tmp/nx_vacuity_census/com.nx" as *u8, "func main() -> i64 { return 0 }\n// render_impl(0) named in prose only\n" as *u8)
396 vc_scan_file("/tmp/nx_vacuity_census/com.nx" as *u8, out)
397 total = total + 1
398 vc_puts(" T3 neg-control-comment a render call inside a comment reads 0 got=" as *u8); vc_num(out[0])
399 if out[0] == 0 { pass = pass + 1; vc_puts(" PASS\n" as *u8) } else { vc_puts(" FAIL\n" as *u8) }
400
401 vc_write_fixture("/tmp/nx_vacuity_census/def.nx" as *u8, "func render_impl(base: i64) -> i64 { return 0 }\n" as *u8)
402 vc_scan_file("/tmp/nx_vacuity_census/def.nx" as *u8, out)
403 total = total + 1
404 vc_puts(" T4 neg-control-definition a DEFINITION is not a call, reads 0 got=" as *u8); vc_num(out[0])
405 if out[0] == 0 { pass = pass + 1; vc_puts(" PASS\n" as *u8) } else { vc_puts(" FAIL\n" as *u8) }
406
407 // T5 neg-control-string: a render token inside a STRING LITERAL must read 0. The fixture is
408 // ASSEMBLED BYTE-WISE, quotes injected as byte 34, so it tests THE SCANNER rather than this
409 // compiler's escape convention -- and so that this source does not itself contain the pattern.
410 let sb: *u8 = sys_mmap(256)
411 var w5: i64 = 0
412 let pre5: *u8 = "func main() -> i64 { vc_puts(" as *u8
413 var q5: i64 = 0
414 while pre5[q5] != (0 as u8) { sb[w5] = pre5[q5]; w5 = w5 + 1; q5 = q5 + 1 }
415 sb[w5] = VC_CH_QUOTE as u8
416 w5 = w5 + 1
417 let mid5: *u8 = "render_impl( sitting inside a string" as *u8
418 q5 = 0
419 while mid5[q5] != (0 as u8) { sb[w5] = mid5[q5]; w5 = w5 + 1; q5 = q5 + 1 }
420 sb[w5] = VC_CH_QUOTE as u8
421 w5 = w5 + 1
422 let post5: *u8 = " as *u8); return 0 }\n" as *u8
423 q5 = 0
424 while post5[q5] != (0 as u8) { sb[w5] = post5[q5]; w5 = w5 + 1; q5 = q5 + 1 }
425 sb[w5] = 0 as u8
426 vc_write_fixture("/tmp/nx_vacuity_census/str.nx" as *u8, sb)
427 vc_scan_file("/tmp/nx_vacuity_census/str.nx" as *u8, out)
428 total = total + 1
429 vc_puts(" T5 neg-control-string a render token inside a STRING reads 0 got=" as *u8); vc_num(out[0])
430 if out[0] == 0 { pass = pass + 1; vc_puts(" PASS\n" as *u8) } else { vc_puts(" FAIL\n" as *u8) }
431
432 // T6 THE CASE THAT REFUTED v1. One render CALL SITE inside a helper that main invokes twice is
433 // TWO renders. nx_wasm_mineworld_gate is exactly this shape and v1 accused it of being unable to
434 // difference frames while it was doing so on every run. A regression here revives that false
435 // positive, which is the worst kind: it sends the expensive instrument at an innocent gate.
436 vc_write_fixture("/tmp/nx_vacuity_census/helper.nx" as *u8, "func rend(b: i64) -> i64 { render_impl(b); return 0 }\nfunc main() -> i64 { rend(0); rend(1); return 0 }\n" as *u8)
437 vc_scan_file("/tmp/nx_vacuity_census/helper.nx" as *u8, out)
438 total = total + 1
439 vc_puts(" T6 one render site in a helper invoked twice counts as 2 got=" as *u8); vc_num(out[0])
440 if out[0] == 2 { pass = pass + 1; vc_puts(" PASS\n" as *u8) } else { vc_puts(" FAIL\n" as *u8) }
441
442 // T7 and the other direction: a helper invoked ONCE is still one render, so the correction did
443 // not simply inflate every count until nothing is ever flagged.
444 vc_write_fixture("/tmp/nx_vacuity_census/helper1.nx" as *u8, "func rend(b: i64) -> i64 { render_impl(b); return 0 }\nfunc main() -> i64 { rend(0); return 0 }\n" as *u8)
445 vc_scan_file("/tmp/nx_vacuity_census/helper1.nx" as *u8, out)
446 total = total + 1
447 vc_puts(" T7 neg-control-helper-once a helper invoked once is still 1 got=" as *u8); vc_num(out[0])
448 if out[0] == 1 { pass = pass + 1; vc_puts(" PASS\n" as *u8) } else { vc_puts(" FAIL\n" as *u8) }
449
450 vc_puts("NX-VACUITY-CENSUS selftest passed " as *u8); vc_num(pass); vc_puts("/" as *u8); vc_num(total)
451 if pass == total { vc_puts(" verdict=GREEN\n" as *u8); return 0 }
452 vc_puts(" verdict=RED\n" as *u8)
453 return 1
454}
455
456func vc_read_floor() -> i64 {
457 let lp: *i64 = sys_mmap(16) as *i64
458 let b: *u8 = sys_read_file(VC_CONF, lp)
459 if (b as i64) == 0 { return 0 - 1 }
460 var i: i64 = 0
461 var v: i64 = 0
462 var seen: i64 = 0
463 while i < lp[0] {
464 let c: i64 = b[i] as i64
465 if c >= 48 { if c <= 57 { v = v*10 + (c - 48); seen = 1 } }
466 i = i + 1
467 }
468 if seen == 0 { return 0 - 1 }
469 return v
470}
471
472func vc_write_floor(v: i64) -> i64 {
473 let fd: i64 = sys_openat_wr(VC_CONF, MODE_0644)
474 if fd < 0 { return 0 }
475 let d: *u8 = sys_mmap(32)
476 var x: i64 = v
477 var k: i64 = 0
478 if x == 0 { d[0] = 48 as u8; k = 1 } else {
479 while x > 0 { d[k] = (48 + (x % 10)) as u8; x = x / 10; k = k + 1 }
480 }
481 let o: *u8 = sys_mmap(34)
482 var j: i64 = 0
483 while j < k { o[j] = d[k-1-j]; j = j + 1 }
484 o[k] = VC_CH_NL as u8
485 sys_write(fd, o, k + 1)
486 sys_close(fd)
487 return 1
488}
489
490func main(argc: i64, argv: *i64) -> i64 {
491 if argc > 1 {
492 let a1: *u8 = argv[1] as *u8
493 if a1[0] == (115 as u8) { return vc_selftest() }
494 }
495 let out: *i64 = sys_mmap(64) as *i64
496 let tal: *i64 = sys_mmap(64) as *i64
497 let shown: *i64 = sys_mmap(16) as *i64
498 var z: i64 = 0
499 while z < 8 { tal[z] = 0; z = z + 1 }
500 shown[0] = 0
501 let nbuf: *u8 = sys_mmap(VC_NAMEBUF)
502
503 vc_puts("nx_vacuity_census -- render-gates that CANNOT detect a feature missing from the picture\n\n" as *u8)
504 vc_scan_dir("buildroot/runtime/_hdl_build" as *u8, nbuf, out, tal, shown)
505 vc_scan_dir("buildroot/runtime" as *u8, nbuf, out, tal, shown)
506
507 vc_puts("\n gate_sources=" as *u8); vc_num(tal[0])
508 vc_puts(" not_a_render_gate=" as *u8); vc_num(tal[1])
509 vc_puts(" RENDER_ONCE=" as *u8); vc_num(tal[2])
510 vc_puts(" render_multi=" as *u8); vc_num(tal[3])
511 let sum: i64 = tal[1] + tal[2] + tal[3]
512 vc_puts("\n partition sum=" as *u8); vc_num(sum)
513 vc_puts(" of gate_sources=" as *u8); vc_num(tal[0])
514 if sum == tal[0] { vc_puts(" RECONCILES\n" as *u8) } else { vc_puts(" LEAKS -- do not trust these numbers\n" as *u8) }
515 if shown[0] >= VC_MAXSHOW {
516 vc_puts(" worklist head shown=" as *u8); vc_num(shown[0])
517 vc_puts(" of RENDER_ONCE=" as *u8); vc_num(tal[2])
518 vc_puts(" -- the COUNT is the full population, the LIST is its head\n" as *u8)
519 }
520 if tal[0] < VC_MIN_GATES {
521 vc_puts("\nREFUSING: only " as *u8); vc_num(tal[0])
522 vc_puts(" gate sources found, below the floor of " as *u8); vc_num(VC_MIN_GATES)
523 vc_puts(". A census pointed at the wrong tree reports a confident near-zero; that is worse than refusing.\nverdict=UNPROVEN\n" as *u8)
524 return 3
525 }
526 let floor: i64 = vc_read_floor()
527 if floor < 0 {
528 vc_write_floor(tal[2])
529 vc_puts("\n ratchet SEEDED at " as *u8); vc_num(tal[2])
530 vc_puts(" -- first run, nothing to compare against yet\n" as *u8)
531 } else {
532 vc_puts("\n ratchet floor=" as *u8); vc_num(floor)
533 vc_puts(" now=" as *u8); vc_num(tal[2])
534 if tal[2] > floor {
535 vc_puts(" ROSE -- a render-gate that cannot see an absent feature was ADDED. The offenders are\n" as *u8)
536 vc_puts(" named above; give the new one a second frame to compare against.\nverdict=RED\n" as *u8)
537 return 1
538 }
539 if tal[2] < floor {
540 vc_write_floor(tal[2])
541 vc_puts(" FELL -- ratchet tightened to the new value\n" as *u8)
542 } else {
543 vc_puts(" HELD\n" as *u8)
544 }
545 }
546 vc_puts("\n RENDER_ONCE is a CANDIDATE FILTER, not a proof. One static render means there is no second\n" as *u8)
547 vc_puts(" frame to compare against, so such a gate very likely cannot tell a picture with the feature\n" as *u8)
548 vc_puts(" from one without it -- but an invocation inside a LOOP is one static site and many runtime\n" as *u8)
549 vc_puts(" renders, and this organ does no brace matching. READ THE GATE before acting on its row.\n" as *u8)
550 vc_puts(" The converse is NOT claimed: rendering many times buys nothing on its own. nx_wasm_craft_gate\n" as *u8)
551 vc_puts(" rendered dozens of times and still could not see that every character was missing.\n" as *u8)
552 vc_puts(" nx_gate_bite is the ruler that decides; this only tells it where to spend.\n" as *u8)
553 vc_puts("\n ⚠THIS COUNT DOES NOT MEASURE WHETHER THE LISTED GATES HAVE BEEN FIXED. There are two valid\n" as *u8)
554 vc_puts(" remedies and this metric only sees one. Adding a SECOND RENDER (re-render with the feature\n" as *u8)
555 vc_puts(" removed, compare frames) moves a gate off this list. Comparing TWO SAMPLES WITHIN ONE FRAME\n" as *u8)
556 vc_puts(" -- the usual remedy for a sprite-presence tooth, e.g. 'this pixel differs from the\n" as *u8)
557 vc_puts(" background two tiles over' -- is equally sound and leaves the gate rendering once, so it\n" as *u8)
558 vc_puts(" STAYS LISTED. On 2026-08-14 five listed gates were fixed that way and remain on this list.\n" as *u8)
559 vc_puts(" Read the ratchet as a guard against NEW render-once gates, never as a fix-progress bar.\n" as *u8)
560 vc_puts("verdict=GREEN\n" as *u8)
561 return 0
562}