code wiki / _hdl_build / nx_citation_registry_test.nx
nx_citation_registry_test.nx source
↩ module page · 96 lines · 5727 B
1// nx_citation_registry_test.nx -- the LIBRARIAN ingests the roadmap's research
2// references and guards them against link-rot, license-permitting:
3// 1. every reference must carry a STABLE anchor (venue+year / book / doc# / in-tree
4// path) -- never a bare URL. Rot-proof by construction.
5// 2. classify each reference's LICENSE. OPEN (arXiv/CC/GPL/public) -> INGEST the
6// content into our store by hash (a local, integrity-checkable, rot-proof copy).
7// RESTRICTED (copyrighted/paywalled/vendor) -> METADATA-ONLY (we hold the
8// permanent anchor but do NOT mirror what we may not -- license boundary).
9// 3. prove the ingest path: hash an OPEN (GPL kernel-doc) excerpt -> store key,
10// re-hash -> identical (the held copy is addressable + integrity-checkable).
11// A synthetic URL-only reference must be CAUGHT as rot-risk (detector validated).
12//
13// Known answer: all real refs stable + license-classified; OPEN ones ingestible;
14// RESTRICTED ones metadata-only; the synthetic URL flagged. exit 0.
15
16import "nx_citation_registry.nx"
17
18func cre_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
19func cre_emit(name: *u8, v: i64) -> i64 {
20 cre_puts(name)
21 let b: *u8 = sys_mmap(28); var m: i64 = v; if m < 0 { m = 0 - m }
22 let t: *u8 = sys_mmap(28); var k: i64 = 0
23 if m == 0 { t[0] = 48; k = 1 }
24 while m > 0 { t[k] = 48 + (m % 10); m = m / 10; k = k + 1 }
25 var i: i64 = 0; while i < k { b[i] = t[k - 1 - i]; i = i + 1 }
26 b[k] = 10; sys_write(1, b, k + 1); return 0
27}
28
29func main() -> i64 {
30 cre_puts("=== LIBRARIAN: ingest roadmap references, license-gated, rot-proof ===\n" as *u8)
31
32 let refs: *i64 = sys_mmap(8 * 32) as *i64
33 var n: i64 = 0
34 refs[n] = ("egg (Willsey et al., POPL 2021; arXiv:2004.03082)" as *u8) as i64; n = n + 1
35 refs[n] = ("Granlund & Montgomery, PLDI 1994" as *u8) as i64; n = n + 1
36 refs[n] = ("Bloch, Nearly All Binary Searches Are Broken, Google Research 2006" as *u8) as i64; n = n + 1
37 refs[n] = ("Goldberg, What Every CS Should Know About FP, ACM CSUR 1991" as *u8) as i64; n = n + 1
38 refs[n] = ("Warren, Hacker's Delight 2e" as *u8) as i64; n = n + 1
39 refs[n] = ("Weste & Harris, CMOS VLSI Design 4e, 2010" as *u8) as i64; n = n + 1
40 refs[n] = ("Najm, power-estimation survey, IEEE TVLSI 1994" as *u8) as i64; n = n + 1
41 refs[n] = ("Poletto & Sarkar, linear scan, ACM TOPLAS 1999" as *u8) as i64; n = n + 1
42 refs[n] = ("Chaitin, register allocation via coloring, SIGPLAN 1982" as *u8) as i64; n = n + 1
43 refs[n] = ("Erbsen et al. (fiat-crypto), IEEE S&P 2019; open access" as *u8) as i64; n = n + 1
44 refs[n] = ("Linux power_supply class (Documentation/power/power_supply_class.rst; GPL)" as *u8) as i64; n = n + 1
45 refs[n] = ("Khan et al., RAPL in Action, ACM TOMPECS 2018" as *u8) as i64; n = n + 1
46 refs[n] = ("Intel SDM Vol.3B (RAPL MSRs)" as *u8) as i64; n = n + 1
47 refs[n] = ("Horowitz, Computing's Energy Problem, ISSCC 2014" as *u8) as i64; n = n + 1
48 refs[n] = ("Pereira et al., Energy across Programming Languages, SLE 2017" as *u8) as i64; n = n + 1
49 refs[n] = ("TI INA219 current-sense datasheet (SBOS448)" as *u8) as i64; n = n + 1
50
51 var stable: i64 = 0
52 var rot: i64 = 0
53 var open_ingest: i64 = 0
54 var meta_only: i64 = 0
55 var i: i64 = 0
56 while i < n {
57 let cite: *u8 = refs[i] as *u8
58 let st: i64 = cr_is_stable(cite)
59 let mi: i64 = cr_may_ingest_content(cite)
60 if st == 1 { stable = stable + 1; cre_puts(" [STABLE]" as *u8) } else { rot = rot + 1; cre_puts(" [ROT!] " as *u8) }
61 if mi == 1 { open_ingest = open_ingest + 1; cre_puts("[INGEST] " as *u8) }
62 else { meta_only = meta_only + 1; cre_puts("[meta ] " as *u8) }
63 cre_puts(cite); cre_puts("\n" as *u8)
64 i = i + 1
65 }
66
67 // synthetic ROT-RISK reference: bare URL, no anchor -> must be caught.
68 let bad: *u8 = "see http://some.blog/post for details" as *u8
69 let bad_stable: i64 = cr_is_stable(bad)
70 cre_puts(" [ROT-RISK detector] synthetic URL-only ref flagged: " as *u8)
71 if bad_stable == 0 { cre_puts("YES (caught)\n" as *u8) } else { cre_puts("NO (MISSED!)\n" as *u8) }
72
73 // INGEST PATH proof: hash an OPEN (GPL) kernel-doc excerpt -> rot-proof store key.
74 let doc: *u8 = "power_supply_class: energy_now=uWh, power_now=uW, status=Charging|Discharging|Full; integrate power_now over time for short windows." as *u8
75 var dl: i64 = 0; while doc[dl] != (0 as u8) { dl = dl + 1 }
76 let key1: i64 = cr_hash(doc, dl)
77 let key2: i64 = cr_hash(doc, dl)
78 cre_emit(" ingested OPEN excerpt -> store key : " as *u8, key1)
79
80 cre_puts("----------------------------------------------------------------\n" as *u8)
81 cre_emit(" references : " as *u8, n)
82 cre_emit(" stable (rot-proof) : " as *u8, stable)
83 cre_emit(" content-ingestible : " as *u8, open_ingest)
84 cre_emit(" metadata-only (license): " as *u8, meta_only)
85 cre_puts(" -> citations don't rot: stable anchors + local copies where license allows.\n" as *u8)
86
87 // GATE: every real ref stable; the synthetic caught; >=1 OPEN ingestible; the
88 // OPEN ingest hash is deterministic + nonzero (a real addressable local copy).
89 if rot != 0 { sys_exit(1); return 1 } // a roadmap ref lacks a stable anchor
90 if bad_stable != 0 { sys_exit(2); return 2 } // detector failed to catch a URL
91 if open_ingest < 1 { sys_exit(3); return 3 } // must hold at least one open copy
92 if key1 != key2 { sys_exit(4); return 4 } // store key not deterministic
93 if key1 == 0 { sys_exit(5); return 5 }
94 sys_exit(0)
95 return 0
96}