code wiki / _hdl_build / nx_ag_lib.nx
nx_ag_lib.nx source
↩ module page · 17 lines · 1806 B
1// nx_ag_lib.nx -- shared gate helpers (atoi / itoa / strlen / single-read) extracted from nx_gated_edit_gate
2// + nx_consol_apply_gate, which carried byte-identical copies (rule 15: pattern in 2+ -> shared/). Bodies are
3// VERBATIM -> behaviour-preserving by construction; proven by re-running the consumer gate GREEN after delegation.
4// license_tier: ORIGINAL No hw writes (Rule 26). Consumers: nx_gated_edit_gate (+ nx_consol_apply_gate pending NAS sync).
5import "nx_syscalls.nx"
6import "nx_itoa_lib.nx" // THE shared MSB-first emitter -- ag_itoa composes it (see below)
7func ag_atoi(s: *u8) -> i64 { var v: i64 = 0; var i: i64 = 0; while s[i] != (0 as u8) { let c: i64 = s[i] as i64; if c >= 48 { if c <= 57 { v = v * 10 + (c - 48) } } i = i + 1 } return v }
8// ★COMPOSES ccz_cat_num (2026-08-15, found by nx_itoaclone). Contract matches EXACTLY: digits then a
9// NUL, returning the offset BEFORE the NUL -- which is why this one maps to ccz_cat_num and not nxi_buf.
10// ★★THIS FILE IS ITSELF AN EXTRACTION, AND ITS HEADER SAYS THE BODIES WERE COPIED "VERBATIM ->
11// behaviour-preserving by construction". That is exactly how the defect survived consolidation:
12// DE-DUPLICATING A CLONE VERBATIM PRESERVES ITS BUG AND PROMOTES IT TO THE ONE AUTHORITATIVE COPY.
13// Consolidation is only finished when the survivor COMPOSES the canonical primitive rather than
14// re-stating it -- otherwise you have centralised the defect instead of removing it.
15func ag_itoa(dst: *u8, v: i64) -> i64 { return ccz_cat_num(dst, 0, v) }
16func ag_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
17func ag_read(path: *u8, buf: *u8, cap: i64) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 - 1 } let n: i64 = sys_read(fd, buf, cap - 1); sys_close(fd); return n }