code wiki / _hdl_build / nx_prim_query.nx

nx_prim_query.nx

buildroot/runtime/_hdl_build/nx_prim_query.nx

11288 B167 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tooltopic prim
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_prim_query.nx

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

main pq_w sys_write sys_exit pq_slen sys_mmap nxa_die sys_write ↻ sys_exit ↻ nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_munmap sys_close pq_off pq_b pq_q pq_je pq_has pq_cp pq_bn sys_mmap ↻ sys_munmap ↻ sys_openat_wr sys_write ↻ sys_close ↻ sys_renameat

structs

none

consts

23const 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
24const PQ_HEAD_OVERHEAD: i64 = 512 // the fixed reply header and footer bytes beyond the copied objects and the escaped query (measured under 300)
25const PQ_DIGITS: i64 = 28 // decimal digits an i64 can need, with its sign
26const PQ_QUOTE: i64 = 34
27const PQ_BACKSLASH: i64 = 92
28const PQ_SPACE: i64 = 32
29const PQ_LBRACE: i64 = 123
30const PQ_COMMA: i64 = 44
31const PQ_MINUS: i64 = 45
32const PQ_ZERO: i64 = 48
33const PQ_MODE_RW: i64 = 420
34const PQ_EXIT_USAGE: i64 = 2
35const PQ_EXIT_ABSENT: i64 = 4
36const PQ_EXIT_WINDOW: i64 = 5

functions

40func 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 }
called by 1: main calls 1: sys_write
41func 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
42func 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 }
called by 1: main calls 2: sys_mmapsys_munmap
43func 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
44func pq_je(rep: *u8, pos: i64, src: *u8, s: i64, e: i64) -> i64
called by 1: main
57func 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
58func pq_has(buf: *u8, s: i64, e: i64, pat: *u8, pl: i64) -> i64
called by 1: main
70func pq_off(buf: *u8, s: i64, e: i64, pat: *u8, pl: i64) -> i64
called by 1: main
82func pq_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
called by 1: main
83func main(argc: i64, argv: *i64) -> i64