code wiki / _hdl_build / nx_magic.nx
nx_magic.nx
buildroot/runtime/_hdl_build/nx_magic.nx
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
imports: nx_syscalls.nx
imported by: nobody (leaf or entry point)
structs
| none |
consts
| 20 | const MG_MAGIC_1024: i64 = 1024 |
| 21 | const MG_MAGIC_4096: i64 = 4096 |
| 23 | const MG_CAP: i64 = 1048576 |
| 24 | const MG_OUT: i64 = 1048576 |
| 25 | const MG_NL: i64 = 10 |
| 26 | const MG_QU: i64 = 34 |
| 27 | const MG_BSL: i64 = 92 |
| 28 | const MG_SLASH: i64 = 47 |
| 29 | const MG_US: i64 = 95 |
| 30 | const MG_COMMA: i64 = 44 |
| 31 | const MG_COLON: i64 = 58 |
| 32 | const MG_LB: i64 = 123 |
| 33 | const MG_RB: i64 = 125 |
| 34 | const MG_LSQ: i64 = 91 |
| 35 | const MG_RSQ: i64 = 93 |
| 36 | const MG_SP: i64 = 32 |
| 37 | const MG_TAB: i64 = 9 |
| 38 | const MG_DEF_THRESHOLD: i64 = 1024 |
| 39 | const MG_MAXVALS: i64 = 256 |
| 40 | const MG_MAXSITES: i64 = 4096 |
| 41 | const MG_STDERR: i64 = 2 |
| 42 | const MG_EXIT_USAGE: i64 = 2 |
| 43 | const MG_EXIT_ABSENT: i64 = 4 |
| 44 | const MG_FMODE: i64 = 420 |
| 45 | const MG_CTX: i64 = 60 |
functions
| 47 | func mg_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 48 | func mg_werr(s: *u8) -> i64 { sys_write(MG_STDERR, s, mg_slen(s)); return 0 } |
| 49 | func mg_eqs(a: *u8, b: *u8) -> i64 called by 1: mg_skip_line |
| 55 | func mg_b(d: *u8, o: i64, c: i64) -> i64 { d[o] = c as u8; return o + 1 } called by 1: mg_skip_line |
| 56 | func mg_cat(d: *u8, o: i64, s: *u8) -> i64 called by 1: mg_skip_line |
| 62 | func mg_catn(d: *u8, o: i64, v: i64) -> i64 |
| 74 | func mg_atoi(s: *u8) -> i64 |
| 84 | func mg_is_ident(c: i64) -> i64 |
| 91 | func mg_is_digit(c: i64) -> i64 { if c >= 48 { if c <= 57 { return 1 } } return 0 } |
| 93 | func mg_first_ns(q: *u8, ls: i64, le: i64) -> i64 called by 1: mg_starts |
| 103 | func mg_starts(q: *u8, ls: i64, le: i64, lit: *u8) -> i64 |
| 112 | func mg_skip_line(q: *u8, ls: i64, le: i64) -> i64 |
| 118 | func mg_read(path: *u8, b: *u8, cap: i64) -> i64 |
| 133 | func mg_detect_prefix(q: *u8, n: i64, out: *u8) -> i64 |
| 163 | func mg_name_for(pfx: *u8, v: i64, out: *u8) -> i64 |
| 171 | func mg_has_const(q: *u8, n: i64, name: *u8) -> i64 |
| 192 | func mg_cat_json(d: *u8, o: i64, q: *u8, a: i64, b: i64) -> i64 |
| 210 | func mg_scan(q: *u8, n: i64, thr: i64, sline: *i64, scol: *i64, slen: *i64, sval: *i64, sls: *i64, sle: *i64) -> i64 |
| 263 | func main(argc: i64, argv: *i64) -> i64 |