code wiki / _hdl_build / nx_prim_query.nx
nx_prim_query.nx
buildroot/runtime/_hdl_build/nx_prim_query.nx
about
nx_prim_query.nx -- prim lane F782 (query_primitives: the 'what do I have' half of meet-in-the-middle).
Reads the F781 manifest knowledge/store/prim_registry.json and returns every primitive object whose
text matches the query (substring facet over domain/capabilities/signature/output/id) -- the sovereign
query the top-down orchestrator (F783) calls to find matching blocks. Objects copied VERBATIM (already
valid JSON). Result to stdout AND an atomic out-file (verifiable). READ-ONLY. Empty query = match-all.
Object boundaries found via PLAIN-WORD anchors + byte confirm ({" before primitive_id) so the
match logic carries NO string-escape dependency (cannot silently 0-match).
ENVELOPES ARE DERIVED, NOT PICKED (2026-09-14, search rung E7; operator: the estate-wide magic numbers go).
Three caps used to live here and every one failed in silence or was one generation from it: the manifest
was read through a 1 MiB window (the manifest is 957 KB today and grows with every registered tool), the
object table held 2048 boundaries and DROPPED the rest without a word, and the reply buffer was bounded at
262100 bytes -- a match-all query over a 957 KB manifest was being cut to invalid JSON silently. Now the
manifest is read WHOLE by sys_read_file (sized from the file), the object table is sized from the input
(no object can be shorter than its own primitive_id key, PQ_OBJ_MIN bytes), and the reply window is the
input plus the fixed header (every matched object is a verbatim copy of input bytes). The only bound left
refuses LOUDLY and cannot fire by construction.
nx_prim_query <query> [manifest.json] [out.json]
exit: 0 GREEN | 4 ABSENT/MALFORMED | 5 WINDOW (cannot happen by construction; kept loud) | 2 usage.
license_tier: ORIGINAL expect_exit: 0
dependencies 1 imports · 0 importers
imports: nx_syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 23 | const PQ_OBJ_MIN: i64 = 16 // a primitive object is never shorter than its {"primitive_id":" key, so input/PQ_OBJ_MIN bounds the object count |
| 24 | const PQ_HEAD_OVERHEAD: i64 = 512 // the fixed reply header and footer bytes beyond the copied objects and the escaped query (measured under 300) |
| 25 | const PQ_DIGITS: i64 = 28 // decimal digits an i64 can need, with its sign |
| 26 | const PQ_QUOTE: i64 = 34 |
| 27 | const PQ_BACKSLASH: i64 = 92 |
| 28 | const PQ_SPACE: i64 = 32 |
| 29 | const PQ_LBRACE: i64 = 123 |
| 30 | const PQ_COMMA: i64 = 44 |
| 31 | const PQ_MINUS: i64 = 45 |
| 32 | const PQ_ZERO: i64 = 48 |
| 33 | const PQ_MODE_RW: i64 = 420 |
| 34 | const PQ_EXIT_USAGE: i64 = 2 |
| 35 | const PQ_EXIT_ABSENT: i64 = 4 |
| 36 | const PQ_EXIT_WINDOW: i64 = 5 |
functions
| 40 | func pq_w(fd: i64, s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(fd, s, n); return 0 } |
| 41 | func pq_b(rep: *u8, pos: i64, s: *u8) -> i64 { var p: i64 = pos; var i: i64 = 0; while s[i] != (0 as u8) { if p < pq_cap_g { rep[p] = s[i]; p = p + 1 } i = i + 1 } return p } called by 1: main |
| 42 | func pq_bn(rep: *u8, pos: i64, v: i64) -> i64 { var p: i64 = pos; var m: i64 = v; if m < 0 { if p < pq_cap_g { rep[p] = PQ_MINUS as u8; p = p + 1 } m = 0 - m } let t: *u8 = sys_mmap(PQ_DIGITS); var k: i64 = 0; if m == 0 { t[0] = PQ_ZERO as u8; k = 1 } while m > 0 { t[k] = (PQ_ZERO + (m % 10)) as u8; m = m / 10; k = k + 1 } var i: i64 = 0; while i < k { if p < pq_cap_g { rep[p] = t[k - 1 - i]; p = p + 1 } i = i + 1 } sys_munmap(t, PQ_DIGITS); return p } |
| 43 | func pq_q(rep: *u8, pos: i64) -> i64 { var p: i64 = pos; if p < pq_cap_g { rep[p] = PQ_QUOTE as u8; p = p + 1 } return p } called by 1: main |
| 44 | func pq_je(rep: *u8, pos: i64, src: *u8, s: i64, e: i64) -> i64 called by 1: main |
| 57 | func pq_cp(rep: *u8, pos: i64, src: *u8, s: i64, e: i64) -> i64 { var p: i64 = pos; var i: i64 = s; while i < e { if p < pq_cap_g { rep[p] = src[i]; p = p + 1 } i = i + 1 } return p } called by 1: main |
| 58 | func pq_has(buf: *u8, s: i64, e: i64, pat: *u8, pl: i64) -> i64 called by 1: main |
| 70 | func pq_off(buf: *u8, s: i64, e: i64, pat: *u8, pl: i64) -> i64 called by 1: main |
| 82 | func pq_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } called by 1: main |
| 83 | func main(argc: i64, argv: *i64) -> i64 |