code wiki / _hdl_build / nx_census_gallery.nx

nx_census_gallery.nx source

↩ module page · 95 lines · 5804 B

1// nx_census_gallery.nx -- SOVEREIGN visual gallery: the top-20 census as SIDE-BY-SIDE 2// pixels (Chrome oracle | Nishi daily driver) instead of a flat TSV. The TSV stays the 3// census's internal RECORD; this organ is the DELIVERABLE -- humans judge renders by 4// LOOKING, with the measured numbers beside the pixels (the visual-comp law: publish 5// metrics BESIDE the pixels, a number alone can lie). 6// reads bench/top20/results.tsv (site, class, chrome_h, nishi_h, ratio, coarse, tight, recall) 7// emits bench/top20/gallery.html (img src = /top20/<name>_*.png, served by the local lane) 8// Uses `break` freely -- safe as of the 2026-07-27 sealed-terminator fix, witness-protected. 9// exit 0 = written; fail-loud otherwise. 10import "nx_syscalls.nx" 11const CG_MAGIC_1048576: i64 = 1048576 12 13func cg_p(dst: *u8, off: i64, s: *u8) -> i64 { 14 var i: i64 = 0 15 while s[i] != (0 as u8) { dst[off + i] = s[i]; i = i + 1 } 16 return off + i 17} 18func cg_pn2(dst: *u8, off: i64, sp: *u8, n: i64) -> i64 { 19 var i: i64 = 0 20 while i < n { dst[off + i] = sp[i]; i = i + 1 } 21 return off + n 22} 23 24const CG_CSS: *u8 = "body{background:#10151a;color:#dde5ea;font-family:system-ui,sans-serif;margin:0;padding:24px}h1{font-size:1.3em}p.k{color:#8fa1ab;max-width:70em}div.site{border:1px solid #26333a;margin:18px 0;padding:14px;background:#151c21}div.hd{display:flex;gap:14px;align-items:baseline;flex-wrap:wrap}span.nm{font-size:1.15em;font-weight:700}span.cls{color:#8fa1ab;font-family:monospace}span.rec{font-family:monospace;color:#e8b34b}div.pair{display:flex;gap:10px;margin-top:10px;flex-wrap:wrap}div.half{flex:1;min-width:320px}div.half b{display:block;color:#8fa1ab;font-size:0.8em;margin-bottom:4px;font-family:monospace}img{width:100%;border:1px solid #26333a;background:#fff}div.miss{border:1px dashed #4a5a64;color:#8fa1ab;padding:40px;text-align:center;font-family:monospace}\x00" 25 26func main() -> i64 { 27 let lp: *i64 = sys_mmap(16) as *i64 28 let tsv: *u8 = sys_read_file("bench/top20/results.tsv\x00" as *u8, lp) 29 let tlen: i64 = lp[0] 30 if tlen <= 0 { sys_write(2, "gallery: no results.tsv\x0a\x00" as *u8, 24); return 1 } 31 32 let out: *u8 = sys_mmap(CG_MAGIC_1048576) 33 var o: i64 = 0 34 o = cg_p(out, o, "<html><head><meta charset=\"utf-8\"><title>Nishi vs Chrome -- top-20 census gallery</title><style>\x00" as *u8) 35 o = cg_p(out, o, CG_CSS) 36 o = cg_p(out, o, "</style></head><body><h1>Nishi browser vs Chrome oracle -- side by side</h1><p class=\"k\">Each site: the Chrome headless oracle (left) and the Nishi daily driver's own render (right), with the census class and OCR reading-recall (permille vs Chrome=1000) beside the pixels. Missing right-hand panels are sites where the fetch produced no frame -- shown as the absence they are, never faked.</p>\x00" as *u8) 37 38 var pos: i64 = 0 39 var line: i64 = 0 40 while pos < tlen { 41 // find end of this line 42 var lend: i64 = pos 43 while lend < tlen { if (tsv[lend] & 0xff) == 10 { break } lend = lend + 1 } 44 45 if line > 0 { if lend > pos { 46 // field 1 (site) and field 2 (class): split on the first two TABs 47 var site_end: i64 = pos 48 while site_end < lend { if (tsv[site_end] & 0xff) == 9 { break } site_end = site_end + 1 } 49 var cls_end: i64 = site_end + 1 50 while cls_end < lend { if (tsv[cls_end] & 0xff) == 9 { break } cls_end = cls_end + 1 } 51 // last field (recall): after the final TAB 52 var rec_start: i64 = pos 53 var sc: i64 = pos 54 while sc < lend { if (tsv[sc] & 0xff) == 9 { rec_start = sc + 1 } sc = sc + 1 } 55 56 o = cg_p(out, o, "<div class=\"site\"><div class=\"hd\"><span class=\"nm\">\x00" as *u8) 57 o = cg_pn2(out, o, ((tsv as i64) + pos) as *u8, site_end - pos) 58 o = cg_p(out, o, "</span><span class=\"cls\">\x00" as *u8) 59 o = cg_pn2(out, o, ((tsv as i64) + site_end + 1) as *u8, cls_end - site_end - 1) 60 o = cg_p(out, o, "</span><span class=\"rec\">reading-recall \x00" as *u8) 61 o = cg_pn2(out, o, ((tsv as i64) + rec_start) as *u8, lend - rec_start) 62 o = cg_p(out, o, " / 1000</span></div><div class=\"pair\"><div class=\"half\"><b>CHROME ORACLE</b><img src=\"/top20/\x00" as *u8) 63 o = cg_pn2(out, o, ((tsv as i64) + pos) as *u8, site_end - pos) 64 o = cg_p(out, o, "_chrome_top.png\"></div><div class=\"half\"><b>NISHI BROWSER</b>\x00" as *u8) 65 66 // nishi panel: check the frame exists so absence renders as a LABELED absence. 67 let pbuf: *u8 = sys_mmap(512) 68 var po: i64 = 0 69 po = cg_p(pbuf, po, "bench/top20/\x00" as *u8) 70 po = cg_pn2(pbuf, po, ((tsv as i64) + pos) as *u8, site_end - pos) 71 po = cg_p(pbuf, po, "_nishi_f0.png\x00" as *u8) 72 pbuf[po] = 0 as u8 73 let pfd: i64 = sys_openat_rd(pbuf) 74 if pfd >= 0 { 75 sys_close(pfd) 76 o = cg_p(out, o, "<img src=\"/top20/\x00" as *u8) 77 o = cg_pn2(out, o, ((tsv as i64) + pos) as *u8, site_end - pos) 78 o = cg_p(out, o, "_nishi_f0.png\">\x00" as *u8) 79 } else { 80 o = cg_p(out, o, "<div class=\"miss\">no frame captured (fetch produced nothing)</div>\x00" as *u8) 81 } 82 o = cg_p(out, o, "</div></div></div>\x00" as *u8) 83 } } 84 line = line + 1 85 pos = lend + 1 86 } 87 o = cg_p(out, o, "</body></html>\x00" as *u8) 88 89 let fd: i64 = sys_openat_wr("bench/top20/gallery.html\x00" as *u8, 420) 90 if fd < 0 { sys_write(2, "gallery: cannot write\x0a\x00" as *u8, 22); return 2 } 91 sys_write(fd, out, o) 92 sys_close(fd) 93 sys_write(1, "gallery: wrote bench/top20/gallery.html\x0a\x00" as *u8, 40) 94 return 0 95}