code wiki / _hdl_build / nx_brand_snap_gate.nx

nx_brand_snap_gate.nx source

↩ module page · 51 lines · 3192 B

1// nx_brand_snap_gate.nx -- grid snapping + alignment guides. 100% sovereign. expect_exit: 0 2// 3// MIGRATED 2026-07-31 onto nx_gate_verdict (D001, ws=gate-dry-d001) in the MINIMAL form -- the shape a 4// mechanical applier can generate. Deliberately NOT a full rewrite: t_row and every check row are left 5// EXACTLY as they were, so the PASS/FAIL vector is unchanged by construction. The only thing replaced is 6// the hand-rolled verdict tail, which is precisely the debt D001 names ("gates roll their own verdict"). 7// The gate's own tot[] counters are handed straight to gv_verdict, so the ecosystem's ONE judge now sees 8// this gate in the canonical "NX-<NAME> passed p/t verdict=..." shape instead of a bespoke line that 9// happened to read "VERDICT=verdict=GREEN". 10// WHY MINIMAL IS THE RIGHT FIRST RUNG: it is mechanically generatable across the ~950 gates that share 11// this counter idiom, it cannot change the check vector, and it still collects the payoff -- canonical 12// verdict shape today, and the gv_journal harness outcome frame for free on trees whose base class has it. 13// Full gv_check adoption is a later, optional rung; it is not required to eat the debt. 14import "nx_syscalls.nx" 15import "nx_brand_snap.nx" 16import "nx_gate_verdict.nx" 17 18func gw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 19func gn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)} let t: *u8=sys_mmap(28); 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{bb[i]=t[k-1-i];i=i+1} sys_write(1,bb,k); return 0 } 20func t_row(name: *u8, ok: i64, tot: *i64) -> i64 { 21 if ok == 1 { gw(" PASS " as *u8); tot[0]=tot[0]+1 } else { gw(" FAIL " as *u8); tot[1]=tot[1]+1 } 22 gw(name); gw("\n" as *u8); return 0 23} 24 25func main() -> i64 { 26 let tot: *i64 = sys_mmap(32) as *i64 27 tot[0]=0; tot[1]=0 28 gw("=== nx_brand_snap_gate -- editor grid-snapping + alignment guides ===\n" as *u8) 29 30 var s1: i64 = 0; if bs_snap(37, 8) == 40 { s1 = 1 } 31 t_row("S1 snap 37 -> 40 (nearest 8px grid line)" as *u8, s1, tot) 32 var s2: i64 = 0; if bs_snap(35, 8) == 32 { s2 = 1 } 33 t_row("S2 snap 35 -> 32 (round to nearer line)" as *u8, s2, tot) 34 var s3: i64 = 0; if bs_snap(40, 8) == 40 { s3 = 1 } 35 t_row("S3 snap 40 -> 40 (already on grid, stable)" as *u8, s3, tot) 36 37 var s4: i64 = 0; if bs_aligned(40, 42, 4) == 1 { if bs_aligned(40, 60, 4) == 0 { s4 = 1 } } 38 t_row("S4 alignment guide: edges within tol align, far edges do not" as *u8, s4, tot) 39 40 let pl: *i64 = sys_mmap(32) as *i64 41 pl[0]=37; pl[1]=11; pl[2]=63 42 bs_snap_place(pl, 8) 43 var s5: i64 = 0; if pl[0]==40 { if pl[1]==8 { if pl[2]==64 { s5 = 1 } } } 44 gw(" place (37,11,63) snapped to (" as *u8); gn(pl[0]); gw("," as *u8); gn(pl[1]); gw("," as *u8); gn(pl[2]); gw(")\n" as *u8) 45 t_row("S5 whole placement (x,y,w) snaps onto the grid" as *u8, s5, tot) 46 47 let ctr: *i64 = gv_ctr() 48 ctr[0] = tot[0] 49 ctr[1] = tot[0] + tot[1] 50 return gv_verdict("BRAND-SNAP-GATE" as *u8, ctr, "engine-level snapping + guides (editor maturity; widget breadth = R6 BEHIND)" as *u8) 51}