code wiki / _hdl_build / nx_citation_registry.nx

nx_citation_registry.nx source

↩ module page · 97 lines · 4972 B

1// nx_citation_registry.nx -- the LIBRARIAN's external-reference rot guard. 2// 3// nx_librarian audits INTERNAL [[X]] doc links. This guards the EXTERNAL research 4// references we ground the roadmap in (the rb_citation entries + module-header 5// citations) as we build up from the hardware. The link-rot defence is structural: 6// cite a STABLE scholarly anchor -- venue + year (POPL 2021), a DOI, an ISBN/book, 7// a vendor doc number (Intel SDM), a datasheet, or an in-tree kernel doc path -- 8// NOT a bare URL, which rots when the page moves. A reference with a permanent 9// identifier is findable forever; a URL is not. The librarian ingests every roadmap 10// reference and FAILS if any lacks a stable anchor. 11// 12// Cardinal #4 (verified facts) + the operator's standing rule: keep what we 13// reference from rotting as the system grows bottom-up. 14 15import "nx_syscalls.nx" 16 17func cr_strlen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 18 19// substring search: 1 if needle occurs in hay. 20func cr_contains(hay: *u8, needle: *u8) -> i64 { 21 let hn: i64 = cr_strlen(hay) 22 let nn: i64 = cr_strlen(needle) 23 if nn == 0 { return 1 } 24 var i: i64 = 0 25 while i + nn <= hn { 26 var j: i64 = 0 27 var ok: i64 = 1 28 while j < nn { if hay[i + j] != needle[j] { ok = 0; j = nn } else { j = j + 1 } } 29 if ok == 1 { return 1 } 30 i = i + 1 31 } 32 return 0 33} 34 35// a publication year "19dd" or "20dd" -- the hallmark of a permanent scholarly cite. 36func cr_has_year(s: *u8) -> i64 { 37 let n: i64 = cr_strlen(s) 38 var i: i64 = 0 39 while i + 4 <= n { 40 let a: i64 = s[i] as i64 41 let b: i64 = s[i + 1] as i64 42 let c: i64 = s[i + 2] as i64 43 let d: i64 = s[i + 3] as i64 44 if ((a == 49) & (b == 57)) | ((a == 50) & (b == 48)) { // "19" or "20" 45 if (c >= 48) & (c <= 57) & (d >= 48) & (d <= 57) { return 1 } 46 } 47 i = i + 1 48 } 49 return 0 50} 51 52// STABLE (rot-proof) iff it carries a permanent anchor; a bare URL or an unanchored 53// claim is ROT-RISK. Returns 1 stable, 0 rot-risk. 54func cr_is_stable(cite: *u8) -> i64 { 55 if cr_has_year(cite) == 1 { return 1 } // venue + year -> permanent 56 if cr_contains(cite, "Hacker's Delight" as *u8) == 1 { return 1 } // canonical book 57 if cr_contains(cite, "ISBN" as *u8) == 1 { return 1 } 58 if cr_contains(cite, "DOI" as *u8) == 1 { return 1 } 59 if cr_contains(cite, "datasheet" as *u8) == 1 { return 1 } // part# anchored 60 if cr_contains(cite, "Documentation/" as *u8) == 1 { return 1 } // in-tree kernel doc path 61 if cr_contains(cite, "SDM" as *u8) == 1 { return 1 } // vendor manual (versioned) 62 return 0 // URL-only / vague -> ROT-RISK 63} 64 65// ---- license-gated INGEST: don't just cite, hold a local copy WHERE LICENSE ALLOWS ---- 66// 67// The strongest rot defence is a local copy -- but only where redistribution is 68// permitted. So the librarian classifies each reference's license and either 69// INGESTS the content (open) or keeps METADATA-ONLY (restricted). Conservative by 70// default: unless a reference is clearly open, it is metadata-only (we never mirror 71// what we may not -- defensive at the license boundary). 72const CR_LIC_OPEN: i64 = 1 // arXiv / CC / public-domain / GPL in-tree / open blog -> may ingest content 73const CR_LIC_RESTRICTED: i64 = 2 // copyrighted book / paywalled journal / vendor spec -> metadata only 74 75func cr_license_class(cite: *u8) -> i64 { 76 if cr_contains(cite, "arXiv" as *u8) == 1 { return CR_LIC_OPEN } 77 if cr_contains(cite, "CC-" as *u8) == 1 { return CR_LIC_OPEN } 78 if cr_contains(cite, "CC0" as *u8) == 1 { return CR_LIC_OPEN } 79 if cr_contains(cite, "public domain" as *u8) == 1 { return CR_LIC_OPEN } 80 if cr_contains(cite, " GPL" as *u8) == 1 { return CR_LIC_OPEN } // leading space: avoid SIGPLAN false-match 81 if cr_contains(cite, "Documentation/" as *u8) == 1 { return CR_LIC_OPEN } // in-tree kernel doc (GPL) 82 if cr_contains(cite, "open access" as *u8) == 1 { return CR_LIC_OPEN } 83 if cr_contains(cite, "Google Research" as *u8) == 1 { return CR_LIC_OPEN } // public engineering blog 84 return CR_LIC_RESTRICTED // conservative default 85} 86func cr_may_ingest_content(cite: *u8) -> i64 { if cr_license_class(cite) == CR_LIC_OPEN { return 1 } return 0 } 87 88// FNV-1a over content bytes -> the rot-proof local STORE KEY (same hash the seed 89// germination + docstore use; an ingested copy is addressable + integrity-checkable). 90const CR_FNV_OFFSET: i64 = 0 - 3750763034362895579 91const CR_FNV_PRIME: i64 = 1099511628211 92func cr_hash(s: *u8, len: i64) -> i64 { 93 var h: i64 = CR_FNV_OFFSET 94 var i: i64 = 0 95 while i < len { h = h ^ (s[i] as i64); h = h * CR_FNV_PRIME; i = i + 1 } 96 return h 97}