code wiki / _hdl_build / nx_pattern_emit16.nx

nx_pattern_emit16.nx

buildroot/runtime/_hdl_build/nx_pattern_emit16.nx

11268 B183 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tooltopic pattern
docsdependenciesstructsconstsfunctions

about

nx_pattern_emit16.nx -- PATTERN EMITTER: GATE_HARNESS (round-trip / inverse-pair gate). ===================================================================================== DECLARED-SCAFFOLD (operator-authorized 2026-06-13 via AskUserQuestion "do the scaffold (pe16)"; pe15 precedent; X-AUT-GATE-001). HAND-WRITTEN generic gate-compose primitive. DEBITED vs autonomy: register row author=tutor, counted in A2 auth_all but NEVER auth_emit. BOOTSTRAP-PROVISIONAL until >=2 downstream gates ride it hands-off FROM A DATA SPEC (X-AUT-NCF-BOOT). WHY A NEW SHAPE: existing emitters author ONE leaf parser/FSM over ONE buffer (no cross-organ calls). A GATE must CALL TWO organs (encode + decode) + assert a ROUND-TRIP + a TAMPER arm = the new compose control flow the transducer cannot synthesize. HONEST SCOPE (the oracle problem): a generic gate needs an ORACLE for "expected" -- that is WHY gates are the frontier. Only SELF-VALIDATING inverse-pair (round-trip) gates need none (decode(encode(x))==x; X-AUT-006f). pe16 authors ONLY those (codecs/serializers), NOT arbitrary integration/benchmark gates (those still need per-gate oracles). ABI MODES (match the real Nishi codec ABI, verified vs nv1_lpc / frame_codec). The IMPORT module and the FUNCTION PREFIX differ (nx_nv1_lpc exports nv1l_*; nx_frame_codec exports fc_*), so the spec carries both: mode 1 (1D, audio): <pfx>_encode(src, NSAMPLES, out, cap) ; <pfx>_decode(enc, m, out, cap) -> NSAMPLES buffer bytes = NSAMPLES * bytes_per_sample. (nv1l: 16-bit -> bps=2) mode 2 (2D, frame): <pfx>_encode(src, W, H, out, cap) ; <pfx>_decode(enc, m, out, cap) -> W*H buffer bytes = W*H. (frame_codec: 8-bit pixels) Authors <name>.nx :: <name>_check() -> i64 (1 iff round-trip bit-exact AND tamper-detected). <name>_test.nx asserts <name>_check()==1. Test buffer = deterministic pattern (i*7+3)&255 (lossless codecs round-trip ANY bytes). Tamper flips a payload byte (m/2, 255-x, no XOR) -> decode MUST differ or change length, else RED. Usage (scratch argv): nx_pattern_emit16 <name> <impmod> <fnpfx> <mode> <p1> <p2> mode1: p1=nsamples p2=bytes_per_sample | mode2: p1=w p2=h LAWS: struct-free, integer-only, flat ifs, no &&/||, <=6 args. license_tier: ORIGINAL (scaffold)

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_pattern_emit16.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 sys_mmap sys_openat_rd sys_write q_len sys_read sys_close pe16_spec_val q_len ↻ pe16_spec_int sys_mmap ↻ pe16_spec_val ↻ q_atoi q_strcpy q_atoi ↻ q_cat sys_openat_wr pe16_emit_gate sys_mmap ↻ q_cat ↻ q_catn sys_mmap ↻ sys_write ↻ pe16_emit_test sys_mmap ↻ q_cat ↻ sys_write ↻

structs

none

consts

32const K_MAGIC_65536: i64 = 65536
33const K_MAGIC_4096: i64 = 4096
34const K_MAGIC_8192: i64 = 8192
35const K_MAGIC_8191: i64 = 8191

functions

37func q_atoi(s: *u8) -> i64 { var n: i64 = 0; var i: i64 = 0; while s[i] != (0 as u8) { if s[i] >= (48 as u8) { if s[i] <= (57 as u8) { n = n * 10 + ((s[i] as i64) - 48) } } i = i + 1 } return n }
called by 2: pe16_spec_intmain
38func q_cat(d: *u8, o: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { d[o + i] = s[i]; i = i + 1 } return o + i }
39func q_catn(d: *u8, o: i64, v: i64) -> i64
called by 1: pe16_emit_gate calls 1: sys_mmap
51func q_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
called by 2: pe16_spec_valmain
52func q_strcpy(d: *u8, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { d[i] = s[i]; i = i + 1 } d[i] = 0 as u8; return 0 }
called by 1: main
54func pe16_spec_val(buf: *u8, n: i64, key: *u8, out: *u8, outcap: i64) -> i64
called by 2: pe16_spec_intmain calls 1: q_len
77func pe16_spec_int(buf: *u8, n: i64, key: *u8) -> i64
called by 1: main calls 3: sys_mmappe16_spec_valq_atoi
85func pe16_emit_gate(fd: i64, name: *u8, impmod: *u8, pfx: *u8, mode: i64, dims: *i64) -> i64
called by 1: main calls 4: sys_mmapq_catq_catnsys_write
129func pe16_emit_test(fd: i64, name: *u8) -> i64
141func main(argc: i64, argv: *i64) -> i64