code wiki / _hdl_build / nx_papers_index.nx

nx_papers_index.nx source

↩ module page · 194 lines · 10668 B

1// nx_papers_index.nx -- the Research Repository landing page, COMPILED FROM A REGISTRY (F1130). 2// 3// ★WHAT CHANGED AND WHY. This organ used to emit the index with one hardcoded paper_row() 4// call per paper, baked into the source. That is a rule-11 violation (data belongs in data, 5// not code): the list went stale on 2026-06-17, and adding a paper meant editing and 6// recompiling an organ. It also linked every paper into /wiki/, which is AUTH-GATED -- so 7// the "public research repository" was not publicly readable at all, and nothing that lives 8// only behind a login is citable. 9// 10// Now: rows come from a TSV registry and each row declares its own ACCESS. Adding a paper is 11// a data edit. Internal papers are listed honestly as access-controlled rather than rendered 12// as links that a reader cannot follow. 13// 14// nx_papers_index <registry.tsv> <out.html> 15// registry row: id \t access(public|internal) \t href \t title \t abstract \t result \t gates 16// 17// FAIL-CLOSED: an unreadable or empty registry REFUSES (exit 3) rather than emitting an empty 18// repository page -- a page saying "no papers" is indistinguishable from a broken read, and 19// silently publishing one would erase the repository. 20// 21// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 22import "nx_syscalls.nx" 23import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc) 24 25const PX_COLS: i64 = 7 26const PX_CAP: i64 = 262144 27const PX_OUT: i64 = 524288 28const PX_TAB: i64 = 9 29const PX_NL: i64 = 10 30 31func px_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 32func px_puts(s: *u8) -> i64 { sys_write(1, s, px_len(s)); return 0 } 33// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer 34// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the 35// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls). 36// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign. 37func px_num(v: i64) -> i64 { nxi_out(v); return 0 } 38func px_read(path: *u8, buf: *u8, cap: i64) -> i64 { 39 let fd: i64 = sys_openat_rd(path) 40 if fd < 0 { return 0 - 1 } 41 var n: i64 = 0 42 var go: i64 = 1 43 while go == 1 { 44 let base: i64 = buf as i64 45 let r: i64 = sys_read(fd, (base + n) as *u8, cap - n) 46 if r <= 0 { go = 0 } else { n = n + r } 47 if n >= cap { go = 0 } 48 } 49 sys_close(fd) 50 return n 51} 52// append a NUL-terminated literal 53func px_app(dst: *u8, off: i64, s: *u8) -> i64 { 54 var i: i64 = 0 55 var o: i64 = off 56 while s[i] != (0 as u8) { dst[o] = s[i]; o = o + 1; i = i + 1 } 57 return o 58} 59// append src[a..b) 60func px_appn(dst: *u8, off: i64, src: *u8, a: i64, b: i64) -> i64 { 61 var i: i64 = a 62 var o: i64 = off 63 while i < b { dst[o] = src[i]; o = o + 1; i = i + 1 } 64 return o 65} 66func px_eol(buf: *u8, n: i64, i: i64) -> i64 { 67 var e: i64 = i 68 var s: i64 = 1 69 while s == 1 { 70 if e >= n { s = 0 } else { if buf[e] == (PX_NL as u8) { s = 0 } else { e = e + 1 } } 71 } 72 return e 73} 74// split line [ls,le) into PX_COLS ranges; col[c*2],col[c*2+1]. Returns columns found. 75func px_cols(buf: *u8, ls: i64, le: i64, col: *i64) -> i64 { 76 var c: i64 = 0 77 var p: i64 = ls 78 while c < PX_COLS { 79 var q: i64 = p 80 var s: i64 = 1 81 while s == 1 { 82 if q >= le { s = 0 } else { if buf[q] == (PX_TAB as u8) { s = 0 } else { q = q + 1 } } 83 } 84 col[c*2] = p 85 col[c*2+1] = q 86 if q >= le { 87 c = c + 1 88 while c < PX_COLS { col[c*2] = le; col[c*2+1] = le; c = c + 1 } 89 return c 90 } 91 p = q + 1 92 c = c + 1 93 } 94 return c 95} 96func px_is(buf: *u8, a: i64, b: i64, lit: *u8) -> i64 { 97 let l: i64 = px_len(lit) 98 if b - a != l { return 0 } 99 var i: i64 = 0 100 while i < l { if buf[a+i] != lit[i] { return 0 } i = i + 1 } 101 return 1 102} 103 104func main(argc: i64, argv: *i64) -> i64 { 105 if argc < 3 { 106 px_puts("usage: nx_papers_index <registry.tsv> <out.html>\n" as *u8) 107 sys_exit(2); return 2 108 } 109 let reg: *u8 = sys_mmap(PX_CAP) 110 let rn: i64 = px_read(argv[1] as *u8, reg, PX_CAP - 16) 111 if rn <= 0 { 112 // FAIL-CLOSED: never publish an empty repository over a real one. 113 px_puts("PAPERS-INDEX REFUSED: registry unreadable or empty -> " as *u8) 114 px_puts(argv[1] as *u8) 115 px_puts("\n (an empty index is indistinguishable from a broken read; refusing to emit)\n" as *u8) 116 sys_exit(3); return 3 117 } 118 let out: *u8 = sys_mmap(PX_OUT) 119 var o: i64 = 0 120 o = px_app(out, o, "<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n" as *u8) 121 o = px_app(out, o, "<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n" as *u8) 122 o = px_app(out, o, "<title>Nishi Research Repository</title>\n" as *u8) 123 o = px_app(out, o, "<meta name=\"description\" content=\"Papers compiled from measured gates. Every quantitative claim cites a re-runnable gate.\">\n" as *u8) 124 o = px_app(out, o, "<style>\n:root{--bg:#fbfbfa;--fg:#16181d;--mut:#5a6472;--ln:#1a4fd6;--bd:#e2e5ea;--card:#fff}\n" as *u8) 125 o = px_app(out, o, "@media (prefers-color-scheme:dark){:root{--bg:#0f1115;--fg:#e8eaee;--mut:#98a2b3;--ln:#7aa2ff;--bd:#252a33;--card:#161a21}}\n" as *u8) 126 o = px_app(out, o, ":root[data-theme=\"dark\"]{--bg:#0f1115;--fg:#e8eaee;--mut:#98a2b3;--ln:#7aa2ff;--bd:#252a33;--card:#161a21}\n" as *u8) 127 o = px_app(out, o, ":root[data-theme=\"light\"]{--bg:#fbfbfa;--fg:#16181d;--mut:#5a6472;--ln:#1a4fd6;--bd:#e2e5ea;--card:#fff}\n" as *u8) 128 o = px_app(out, o, "*{box-sizing:border-box}body{margin:0;background:var(--bg);color:var(--fg);font:16px/1.65 -apple-system,BlinkMacSystemFont,\"Segoe UI\",system-ui,sans-serif}\n" as *u8) 129 o = px_app(out, o, "main{max-width:52rem;margin:0 auto;padding:2.5rem 1.15rem 4rem}h1{font-size:1.7rem;margin:.3rem 0 .5rem;letter-spacing:-.01em}\n" as *u8) 130 o = px_app(out, o, ".eyebrow{font-size:.78rem;letter-spacing:.09em;text-transform:uppercase;color:var(--mut);font-weight:600}\n" as *u8) 131 o = px_app(out, o, ".meta{color:var(--mut);font-size:.9rem}a{color:var(--ln)}\n" as *u8) 132 o = px_app(out, o, ".p{background:var(--card);border:1px solid var(--bd);border-radius:10px;padding:1.05rem 1.2rem;margin:1.1rem 0}\n" as *u8) 133 o = px_app(out, o, ".p h2{font-size:1.05rem;margin:0 0 .45rem;letter-spacing:-.005em}\n" as *u8) 134 o = px_app(out, o, ".tag{display:inline-block;font-size:.7rem;letter-spacing:.06em;text-transform:uppercase;border:1px solid var(--bd);border-radius:99px;padding:.1rem .5rem;color:var(--mut);margin-left:.4rem;vertical-align:.1rem}\n" as *u8) 135 o = px_app(out, o, ".res{font-size:.94rem;margin:.55rem 0 .4rem}.gate{color:var(--mut);font-size:.86rem;margin:0}\n" as *u8) 136 o = px_app(out, o, "footer{margin-top:2.5rem;padding-top:1.2rem;border-top:1px solid var(--bd);color:var(--mut);font-size:.86rem}\n" as *u8) 137 o = px_app(out, o, "</style>\n</head>\n<body>\n<main>\n" as *u8) 138 o = px_app(out, o, "<p class=\"eyebrow\">Nishi Research</p>\n<h1>Research Repository</h1>\n" as *u8) 139 o = px_app(out, o, "<p class=\"meta\">Every paper is <em>compiled from measured gates</em>: each quantitative claim cites a re-runnable sovereign gate, no claim exceeds its measurement, and every paper carries an explicit account of where we are behind. This index is generated from a registry, not hand-maintained.</p>\n" as *u8) 140 141 let col: *i64 = sys_mmap(PX_COLS * 2 * 8) as *i64 142 var i: i64 = 0 143 var rows: i64 = 0 144 var pub: i64 = 0 145 while i < rn { 146 let le: i64 = px_eol(reg, rn, i) 147 if le > i { 148 px_cols(reg, i, le, col) 149 if col[1] > col[0] { 150 rows = rows + 1 151 let isPublic: i64 = px_is(reg, col[2], col[3], "public" as *u8) 152 if isPublic == 1 { pub = pub + 1 } 153 o = px_app(out, o, "<section class=\"p\">\n<h2>" as *u8) 154 if isPublic == 1 { 155 o = px_app(out, o, "<a href=\"" as *u8) 156 o = px_appn(out, o, reg, col[4], col[5]) 157 o = px_app(out, o, "\">" as *u8) 158 o = px_appn(out, o, reg, col[0], col[1]) 159 o = px_app(out, o, " &mdash; " as *u8) 160 o = px_appn(out, o, reg, col[6], col[7]) 161 o = px_app(out, o, "</a>" as *u8) 162 } else { 163 o = px_appn(out, o, reg, col[0], col[1]) 164 o = px_app(out, o, " &mdash; " as *u8) 165 o = px_appn(out, o, reg, col[6], col[7]) 166 o = px_app(out, o, "<span class=\"tag\">access-controlled</span>" as *u8) 167 } 168 o = px_app(out, o, "</h2>\n<p>" as *u8) 169 o = px_appn(out, o, reg, col[8], col[9]) 170 o = px_app(out, o, "</p>\n<p class=\"res\"><strong>Headline measured result.</strong> " as *u8) 171 o = px_appn(out, o, reg, col[10], col[11]) 172 o = px_app(out, o, "</p>\n<p class=\"gate\"><strong>Reproducibility.</strong> " as *u8) 173 o = px_appn(out, o, reg, col[12], col[13]) 174 o = px_app(out, o, " &mdash; sovereign gates (nx_cc to nxasm, no gcc); re-run to reproduce every number.</p>\n</section>\n" as *u8) 175 } 176 } 177 i = le + 1 178 } 179 180 o = px_app(out, o, "<footer>\n<p><strong>Doctrine.</strong> Compiled from measured gates; cite-or-refuse; no claim exceeds its gate; honest about where we are behind. For a non-novel capability the bar is stricter: the implementation is fully sovereign <em>and</em> the open step is a head-to-head against an independent reference, named rather than skipped.</p>\n" as *u8) 181 o = px_app(out, o, "<p>Papers marked <em>access-controlled</em> live behind the internal wiki and are listed for completeness; they are not publicly citable until republished.</p>\n" as *u8) 182 o = px_app(out, o, "<p>Generated by <code>nx_papers_index</code> from <code>knowledge/registry/papers_index.tsv</code>. Adding a paper is a data edit, not a code change.</p>\n</footer>\n</main>\n</body>\n</html>\n" as *u8) 183 184 let fd: i64 = sys_openat_wr(argv[2] as *u8, 0x1a4) 185 if fd < 0 { px_puts("PAPERS-INDEX IO: cannot open output\n" as *u8); sys_exit(4); return 4 } 186 sys_write(fd, out, o) 187 sys_close(fd) 188 px_puts("PAPERS-INDEX OK rows=" as *u8); px_num(rows) 189 px_puts(" public=" as *u8); px_num(pub) 190 px_puts(" bytes=" as *u8); px_num(o) 191 px_puts(" -> " as *u8); px_puts(argv[2] as *u8); px_puts("\n" as *u8) 192 sys_exit(0) 193 return 0 194}