code wiki / _hdl_build / nx_magic.nx

nx_magic.nx

buildroot/runtime/_hdl_build/nx_magic.nx

19113 B465 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind orphan library
docsdependenciesstructsconstsfunctions

about

nx_magic.nx -- the MISSING FIXER for law L001 (CLAUDE rule 11, debt seq274 sev8). nx_law_warden DETECTS the breach (2348 inline literals over 600 organs) and cap-autonomy FILES it, but nothing turned a breach into a one-step SAFE edit -- so the operator kept watching workstreams "hit these as bugs and just give them a NEW NUMBER". This organ closes that half. nx_magic map <file.nx> [threshold] -> JSON: every offending line+col+value+context, UNCAPPED nx_magic propose <file.nx> [threshold] -> JSON: the const block + per-value site counts nx_magic apply <file.nx> [threshold] -> ATOMIC rewrite: hoist each distinct value to a named const inserted AFTER the last import and BEFORE the first func (the forward-ref law: a const must be declared above every reader), then replace the sites. SEMANTIC-NEUTRALITY IS PROVABLE, NOT ASSERTED: hoisting a literal to a const must compile to the SAME code, so the caller's proof is a BYTE-IDENTICAL elf on rebuild. Not identical => the transform is NOT neutral => revert. (nx_magic never builds; it stays a pure, reviewable text transform.) SKIPPED BY CONSTRUCTION (false-positive control): comment lines, const/static DECLARATION lines, bytes inside string literals, digits that are part of an identifier (x2048), and any value below the threshold. Decimal only -- hex is DECLARED out of envelope (nearly all hex here is < 1024). IDEMPOTENT: a value whose const already exists is not re-hoisted, so a second apply is a no-op. license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_magic.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

structs

none

consts

20const MG_MAGIC_1024: i64 = 1024
21const MG_MAGIC_4096: i64 = 4096
23const MG_CAP: i64 = 1048576
24const MG_OUT: i64 = 1048576
25const MG_NL: i64 = 10
26const MG_QU: i64 = 34
27const MG_BSL: i64 = 92
28const MG_SLASH: i64 = 47
29const MG_US: i64 = 95
30const MG_COMMA: i64 = 44
31const MG_COLON: i64 = 58
32const MG_LB: i64 = 123
33const MG_RB: i64 = 125
34const MG_LSQ: i64 = 91
35const MG_RSQ: i64 = 93
36const MG_SP: i64 = 32
37const MG_TAB: i64 = 9
38const MG_DEF_THRESHOLD: i64 = 1024
39const MG_MAXVALS: i64 = 256
40const MG_MAXSITES: i64 = 4096
41const MG_STDERR: i64 = 2
42const MG_EXIT_USAGE: i64 = 2
43const MG_EXIT_ABSENT: i64 = 4
44const MG_FMODE: i64 = 420
45const MG_CTX: i64 = 60

functions

47func mg_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
called by 2: mg_werrmg_starts
48func mg_werr(s: *u8) -> i64 { sys_write(MG_STDERR, s, mg_slen(s)); return 0 }
called by 1: mg_skip_line calls 2: sys_writemg_slen
49func mg_eqs(a: *u8, b: *u8) -> i64
called by 1: mg_skip_line
55func mg_b(d: *u8, o: i64, c: i64) -> i64 { d[o] = c as u8; return o + 1 }
called by 1: mg_skip_line
56func mg_cat(d: *u8, o: i64, s: *u8) -> i64
called by 1: mg_skip_line
62func mg_catn(d: *u8, o: i64, v: i64) -> i64
called by 1: mg_skip_line calls 1: sys_mmap
74func mg_atoi(s: *u8) -> i64
84func mg_is_ident(c: i64) -> i64
91func mg_is_digit(c: i64) -> i64 { if c >= 48 { if c <= 57 { return 1 } } return 0 }
93func mg_first_ns(q: *u8, ls: i64, le: i64) -> i64
called by 1: mg_starts
103func mg_starts(q: *u8, ls: i64, le: i64, lit: *u8) -> i64
called by 1: mg_skip_line calls 2: mg_first_nsmg_slen
112func mg_skip_line(q: *u8, ls: i64, le: i64) -> i64
118func mg_read(path: *u8, b: *u8, cap: i64) -> i64
133func mg_detect_prefix(q: *u8, n: i64, out: *u8) -> i64
163func mg_name_for(pfx: *u8, v: i64, out: *u8) -> i64
171func mg_has_const(q: *u8, n: i64, name: *u8) -> i64
192func mg_cat_json(d: *u8, o: i64, q: *u8, a: i64, b: i64) -> i64
210func mg_scan(q: *u8, n: i64, thr: i64, sline: *i64, scol: *i64, slen: *i64, sval: *i64, sls: *i64, sle: *i64) -> i64
263func main(argc: i64, argv: *i64) -> i64