code wiki / _hdl_build / nx_magic.nx

nx_magic.nx

buildroot/runtime/_hdl_build/nx_magic.nx

33446 B615 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tool
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): comments -- BOTH whole-line and TRAILING-after-code (the trailing case was unhandled until 2026-08-14; this line said "comment lines" and meant it), const/static DECLARATION lines, bytes inside string literals, digits that are part of an identifier (x2048), and any value below the threshold. BOTH BASES SINCE 2026-08-25: decimal AND 0x/0X hex. This line used to read "Decimal only -- hex is DECLARED out of envelope (nearly all hex here is < 1024)", and a declared blind spot is still a blind spot when the number it produces is published as a rule-11 count. MEASURED on buildroot/runtime/_hdl_build/nx_activities_gate.nx at floor 2: 41 sites / 26 distinct INCLUDING a decimal 420 -- and NOT the four `0x1ed` literals four lines away in the same file, which are the same number. The scanner itself now lives in nx_magic_lib.nx so it can be mutation-proven in-process (nx_magic_gate); its header carries the mechanism and the scope of what this does NOT change. 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 2 imports · 0 importers

nx_syscalls.nx nx_magic_lib.nx nx_magic.nx

imports: nx_syscalls.nxnx_magic_lib.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main mg_werr sys_write mg_slen sys_exit mg_atoi sys_mmap nxa_die sys_write ↻ sys_exit ↻ nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ mg_detect_prefix mg_starts mg_first_ns mg_slen ↻ mg_first_ns ↻ mg_is_ident mg_cat mg_name_for mg_cat ↻ mg_catn sys_mmap ↻ mg_eqs mg_b mg_catn ↻ mg_cat_json mg_slen ↻ sys_write ↻ mg_has_const mg_slen ↻

structs

none

consts

29const MG_MAGIC_1024: i64 = 1024
30const MG_MAGIC_4096: i64 = 4096
32const MG_OUT: i64 = 1048576
33const MG_COMMA: i64 = 44
34const MG_COLON: i64 = 58
35const MG_LB: i64 = 123
36const MG_RB: i64 = 125
37const MG_DEF_THRESHOLD: i64 = 1024
44const MG_STDERR: i64 = 2
45const MG_EXIT_USAGE: i64 = 2
46const MG_EXIT_ABSENT: i64 = 4
47const MG_FMODE: i64 = MODE_0644

functions

51func mg_werr(s: *u8) -> i64 { sys_write(MG_STDERR, s, mg_slen(s)); return 0 }
called by 1: main calls 2: sys_writemg_slen
52func mg_eqs(a: *u8, b: *u8) -> i64
called by 1: main
58func mg_b(d: *u8, o: i64, c: i64) -> i64 { d[o] = c as u8; return o + 1 }
called by 1: main
59func mg_cat(d: *u8, o: i64, s: *u8) -> i64
called by 2: mg_name_formain
65func mg_catn(d: *u8, o: i64, v: i64) -> i64
called by 2: mg_name_formain calls 1: sys_mmap
77func mg_atoi(s: *u8) -> i64
called by 1: main
91func mg_detect_prefix(q: *u8, n: i64, out: *u8) -> i64
121func mg_name_for(pfx: *u8, v: i64, out: *u8) -> i64
called by 1: main calls 2: mg_catmg_catn
129func mg_has_const(q: *u8, n: i64, name: *u8) -> i64
150func mg_cat_json(d: *u8, o: i64, q: *u8, a: i64, b: i64) -> i64
called by 1: main
169func main(argc: i64, argv: *i64) -> i64