code wiki / _hdl_build / nx_scilib_build.nx
nx_scilib_build.nx source
↩ module page · 52 lines · 3208 B
1// nx_scilib_build.nx -- driver: ingest the FOUNDATIONED science documents we have fetched (NIST CODATA,
2// NIST Atomic Weights, IUPAC/CIAAW) into the sovereign Nishi library (nx_library), then print the running
3// index. Each doc is now content-addressed in our own store -> we OWN the bytes -> no link rot. Re-running
4// is idempotent (dedup by CID). license_tier: ORIGINAL
5import "nx_syscalls.nx"
6import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc)
7import "nx_library.nx"
8
9func sb_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
10// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer
11// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the
12// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls).
13// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign.
14func sb_n(v: i64) -> i64 { nxi_out(v); return 0 }
15func sb_pfx(cid: *u8, k: i64) -> i64 { var i: i64=0; while i<k { if cid[i]==(0 as u8){break} let o: *u8=sys_mmap(1); o[0]=cid[i]; sys_write(1,o,1); i=i+1 } return 0 }
16
17func sb_ingest(path: *u8, src: *u8, title: *u8) -> i64 {
18 let cid: *u8 = sys_mmap(128)
19 let st: i64 = lib_ingest(path, src, title, "2026-06-20" as *u8, cid)
20 sb_w(" + "); sb_w(title); sb_w(" -> "); sb_pfx(cid, 20)
21 if st == 1 { sb_w("... [NEW]\n") } else { if st == 0 { sb_w("... [DUP]\n") } else { sb_w("... [ERR/missing-file]\n") } }
22 return st
23}
24
25func main() -> i64 {
26 sb_w("=== NISHI SCIENCE LIBRARY (sovereign, content-addressed, no-link-rot) ===\n")
27 sb_w("ingesting foundationed science documents (we OWN the bytes by CID):\n")
28
29 sb_ingest("knowledge/fetched/nist/codata_allascii.txt" as *u8, "https://physics.nist.gov/cuu/Constants/Table/allascii.txt" as *u8, "NIST CODATA 2022 Fundamental Physical Constants" as *u8)
30 sb_ingest("knowledge/fetched/nist/atomic_weights.raw" as *u8, "https://physics.nist.gov/cgi-bin/Compositions" as *u8, "NIST Atomic Weights and Isotopic Compositions (AME2020)" as *u8)
31 sb_ingest("knowledge/fetched/ciaaw/abridged_atomic_weights.html" as *u8, "https://ciaaw.org/abridged-atomic-weights.htm" as *u8, "IUPAC CIAAW Abridged Standard Atomic Weights" as *u8)
32
33 sb_w("--- running index (the catalog; survives source link-rot) ---\n")
34 let cnt: i64 = lib_count()
35 sb_w("documents="); sb_n(cnt); sb_w("\n")
36
37 let cids: *i64 = sys_mmap(8 * 256) as *i64
38 let nc: i64 = lib_list(cids, 256)
39 let title: *u8 = sys_mmap(256); let src: *u8 = sys_mmap(512); let by: *u8 = sys_mmap(32)
40 var i: i64 = 0
41 while i < nc {
42 let cid: *u8 = cids[i] as *u8
43 sb_w(" ["); sb_pfx(cid, 18); sb_w("...] ")
44 if lib_meta(cid, "title" as *u8, title, 256) == 1 { sb_w(title) }
45 if lib_meta(cid, "bytes" as *u8, by, 32) == 1 { sb_w(" ("); sb_w(by); sb_w(" bytes)") }
46 sb_w("\n")
47 if lib_meta(cid, "source" as *u8, src, 512) == 1 { sb_w(" src="); sb_w(src); sb_w("\n") }
48 i = i + 1
49 }
50 sb_w("=== library built: documents are content-addressed + retrievable by CID forever (no link rot) ===\n")
51 sys_exit(0); return 0
52}