code wiki / _hdl_build / nx_pattern_emit16.nx
nx_pattern_emit16.nx
buildroot/runtime/_hdl_build/nx_pattern_emit16.nx
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
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
| 32 | const K_MAGIC_65536: i64 = 65536 |
| 33 | const K_MAGIC_4096: i64 = 4096 |
| 34 | const K_MAGIC_8192: i64 = 8192 |
| 35 | const K_MAGIC_8191: i64 = 8191 |
functions
| 37 | func 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 } |
| 38 | func 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 } |
| 39 | func q_catn(d: *u8, o: i64, v: i64) -> i64 |
| 51 | func q_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 52 | func 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 |
| 54 | func pe16_spec_val(buf: *u8, n: i64, key: *u8, out: *u8, outcap: i64) -> i64 |
| 77 | func pe16_spec_int(buf: *u8, n: i64, key: *u8) -> i64 |
| 85 | func pe16_emit_gate(fd: i64, name: *u8, impmod: *u8, pfx: *u8, mode: i64, dims: *i64) -> i64 |
| 129 | func pe16_emit_test(fd: i64, name: *u8) -> i64 |
| 141 | func main(argc: i64, argv: *i64) -> i64 |