code wiki / _hdl_build / nx_ag_lib.nx

nx_ag_lib.nx source

↩ module page · 9 lines · 1249 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" 6func 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 } 7func ag_itoa(dst: *u8, v: i64) -> i64 { var m: i64 = v; let t: *u8 = sys_mmap(24); var k: i64 = 0; if m == 0 { t[0] = 48 as u8; 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[i] = t[k - 1 - i]; i = i + 1 } dst[k] = 0 as u8; return k } 8func ag_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 9func 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 }