code wiki / _hdl_build / nx_viz_shape_gate.nx

nx_viz_shape_gate.nx source

↩ module page · 61 lines · 2882 B

1// nx_viz_shape_gate.nx -- REFEREE for the shapes layer (KAT for the d3-shape/d3-path equivalent path strings). 2// T1 line -> "M 0 0 L 10 5 L 20 0" 3// T2 area -> "M 0 5 L 10 8 L 10 0 L 0 0 Z" (line across top, down to baseline, back, closed) 4// GREEN iff T1+T2. Sovereign: nx_viz_shape + nx_syscalls. license_tier: ORIGINAL 5import "nx_viz_shape.nx" 6import "nx_syscalls.nx" 7import "nx_gate_verdict.nx" 8 9func g_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 10func g_streq(a: *u8, b: *u8) -> i64 { var i: i64 = 0; while 1 == 1 { if a[i] != b[i] { return 0 } if a[i] == (0 as u8) { return 1 } i = i + 1 } return 1 } 11func g_row(name: *u8, ok: i64) -> i64 { 12 if ok == 1 { g_w(" PASS " as *u8) } 13 if ok != 1 { g_w(" FAIL " as *u8) } 14 g_w(name); g_w("\n" as *u8) 15 return ok 16} 17 18func main() -> i64 { 19 g_w("viz-shape gate (d3-shape: line + area -> SVG path strings)\n" as *u8) 20 let xs: *i64 = sys_mmap(64) as *i64 21 let ys: *i64 = sys_mmap(64) as *i64 22 let out: *u8 = sys_mmap(512) 23 var pass: i64 = 0 24 25 xs[0] = 0; xs[1] = 10; xs[2] = 20; ys[0] = 0; ys[1] = 5; ys[2] = 0 26 vs_line(xs, ys, 3, out) 27 var t1: i64 = 0 28 if g_streq(out, "M 0 0 L 10 5 L 20 0" as *u8) == 1 { t1 = 1 } 29 pass = pass + g_row("T1 line -> M 0 0 L 10 5 L 20 0\x00" as *u8, t1) 30 31 xs[0] = 0; xs[1] = 10; ys[0] = 5; ys[1] = 8 32 vs_area(xs, ys, 2, 0, out) 33 var t2: i64 = 0 34 if g_streq(out, "M 0 5 L 10 8 L 10 0 L 0 0 Z" as *u8) == 1 { t2 = 1 } 35 pass = pass + g_row("T2 area -> M 0 5 L 10 8 L 10 0 L 0 0 Z\x00" as *u8, t2) 36 37 vs_arc(100, 100, 50, 0, 90, out) 38 var t3: i64 = 0 39 if g_streq(out, "M 100 100 L 150 100 A 50 50 0 0 1 100 150 Z" as *u8) == 1 { t3 = 1 } 40 pass = pass + g_row("T3 arc(c=100,100 r=50 0->90) -> M 100 100 L 150 100 A 50 50 0 0 1 100 150 Z\x00" as *u8, t3) 41 42 vs_symbol(0, 100, 100, 10, out) 43 var t4: i64 = 0 44 if g_streq(out, "M 90 90 L 110 90 L 110 110 L 90 110 Z" as *u8) == 1 { t4 = 1 } 45 pass = pass + g_row("T4 symbol square(100,100,10) -> M 90 90 L 110 90 L 110 110 L 90 110 Z\x00" as *u8, t4) 46 47 vs_link(0, 0, 100, 100, out) 48 var t5: i64 = 0 49 if g_streq(out, "M 0 0 C 50 0 50 100 100 100" as *u8) == 1 { t5 = 1 } 50 pass = pass + g_row("T5 link(0,0->100,100) -> M 0 0 C 50 0 50 100 100 100\x00" as *u8, t5) 51 52 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 53 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 54 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 55 let ctr__dry: *i64 = gv_ctr() 56 ctr__dry[0] = pass 57 ctr__dry[1] = 5 58 let rc__dry: i64 = gv_verdict("VIZ-SHAPE-GATE" as *u8, ctr__dry, "5/5 (line + area + arc + symbol + link -> SVG path, bits-up)" as *u8) 59 sys_exit(rc__dry) 60 return rc__dry 61}