code wiki / _hdl_build / nx_pattern_emit15.nx
nx_pattern_emit15.nx
buildroot/runtime/_hdl_build/nx_pattern_emit15.nx
about
nx_pattern_emit15.nx -- PATTERN EMITTER: PNG_INGEST (shape 19 -- the COMPOSE-shape).
====================================================================================
DECLARED-SCAFFOLD (operator-authorized R3, X-AUT-NCF-001 / spec 2026-06-13-keystone-
newcontrolflow-route-decision.md, which names "the 5-stage ingest compose" VERBATIM
as the gap no existing data-driven shape emits). This emitter is HAND-WRITTEN -- it is
the GENERIC compose primitive. It is DEBITED vs autonomy: its register row is tagged
author=tutor (cl_register_dual), counted in A2 auth_all but NEVER in auth_emit.
Tagging it author=emitter to inflate A2 would be the cheat and is REFUSED.
BOOTSTRAP-PROVISIONAL: it stays a scaffold until >=2 distinct downstream organs ride it
hands-off (X-AUT-NCF-BOOT). The first rider -- nx_store_ingest -- is authored BY
nx_auto_builder hands-off from a DATA spec (author=emitter), NOT hand-written.
WHY THIS IS A NEW SHAPE, NOT A VARIATION: every existing emitter authors ONE leaf
function over ONE buffer (e.g. pe8 STRUCT_WALK authors <name>_locate(b,n,out) -- a
straight-line field walk; NO loop over repeating records, NO calls into other organs,
NO store side-effects, NO idempotency control flow). The ingest organ must (a) LOOP over
ALL PNG chunks, (b) CALL _pe_pngchunk/_pe_pngtext per chunk, (c) CALL canon_encode+cid_of,
(d) CALL ss_get (idempotency) then ss_begin/ss_add/ss_commit. That cross-organ composition
+ per-chunk loop is precisely the new control flow the transducer cannot synthesize.
WHAT IT AUTHORS (GENERIC, data-driven from the spec param vector):
<name>_ingest(buf: *u8, flen: i64, prefix: *u8) -> i64
Walks every PNG chunk in buf[8..flen) (skips the 8-byte signature), and for each
chunk whose FourCC is in the spec's CHUNK-TYPE set, reads its keyword/value via the
green _pe_pngtext_locate. If the keyword is one of the spec's GENREC keys, the (key,
value) pair joins the canonical record. The assembled vector is canon_encode'd, the
CID computed (cid_of), the record key built ("img:"+CID). ss_get probes for the key:
FOUND -> return 0 (idempotent skip, rule 10, no dup); ABSENT -> ss_begin/ss_add(kind
1=put, key, canonbytes)/ss_commit -> return 1 (new record stored).
Return: 1 = stored a NEW record; 0 = idempotent skip (already present); -1 = no GENREC
fields found / malformed PNG (REFUSED, never a clipped store).
DATA-DRIVEN (the spec is the config, rule 11): the GENREC key STRINGS to harvest, the
chunk FourCC(s) to walk, the record-key prefix, and the segid are all carried in the
param vector -- the scaffold is reusable for any image-metadata ingest, not a PNG one-off.
THE KAT (emitter-computed, no-fake-green): the test builds a REAL multi-tEXt PNG in
memory (one tEXt chunk per GENREC key, each with the EMITTER-COMPUTED crc32), ingests it
to a temp store prefix, then asserts: (1) CID round-trip -- ss_get returns the stored
canonical bytes and re-hashing them yields the SAME CID the emitter computed off-line;
dependencies 2 imports · 1 importers
imports: nx_syscalls.nxnx_sha256.nx
imported by: nx_auto_builder.nx
structs
| none |
consts
| 51 | const K_MAGIC_8192: i64 = 8192 |
| 52 | const K_MAGIC_1229472850: i64 = 1229472850 |
| 53 | const K_MAGIC_1229278788: i64 = 1229278788 |
functions
| 55 | func p15_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 } |
| 56 | func p15_wn(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m; sys_write(fd,"-" as *u8,1)}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48;k=1}; while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(fd,bb,k); return 0 } |
| 65 | func p15_spec_ok(p: *i64, np: i64) -> i64 called by 1: pe15_author_png_ingest |
| 87 | func p15_emit_keybytes(fd: i64, p: *i64, base: i64, varname: *u8) -> i64 |
| 101 | func pe15_emit_ingest(fd: i64, name: *u8, p: *i64, np: i64) -> i64 |
| 219 | func p15_cat(dst: *u8, o: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { dst[o + i] = s[i]; i = i + 1 } return i } |
| 220 | func p15_catn(dst: *u8, o: i64, v: i64) -> i64 { var m: i64 = v; let t: *u8 = sys_mmap(28); var k: i64 = 0; if m == 0 { t[0] = 48; k = 1 } while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } var i: i64 = 0; while i < k { dst[o + i] = t[k - 1 - i]; i = i + 1 } return k } |
| 223 | func p15_keybase_off(p: *i64, target: i64) -> i64 |
| 237 | func p15_kcmp(a: *u8, al: i64, b: *u8, bl: i64) -> i64 |
| 249 | func p15_w32(p: *u8, off: i64, v: i64) -> i64 |
| 257 | func p15_canon(kp: *i64, kl: *i64, vp: *i64, vl: *i64, n: i64, out: *u8) -> i64 |
| 298 | func p15_cid(bytes: *u8, n: i64, cid: *u8) -> i64 |
| 320 | func p15_crc32(img: *u8, s: i64, e: i64) -> i64 |
| 342 | func p15_chunk_emit(img: *u8, off: i64, fourcc: i64, key: *u8, klen: i64, val: *u8, vlen: i64) -> i64 |
| 369 | func p15_testval(ki: i64, v: *u8) -> i64 |
| 376 | func pe15_emit_ingest_test(fd: i64, name: *u8, p: *i64, np: i64) -> i64 |
| 547 | func p15_first_kw_pos(img: *u8, total: i64, fourcc: i64) -> i64 |
| 558 | func p15_chunk_of_pos(img: *u8, total: i64, pos: i64) -> i64 |
| 570 | func pe15_author_png_ingest(name: *u8, modpath: *u8, testpath: *u8, p: *i64, np: i64) -> i64 |