code wiki / _hdl_build / nx_viz_tree_gate.nx

nx_viz_tree_gate.nx source

↩ module page · 52 lines · 2275 B

1// nx_viz_tree_gate.nx -- REFEREE for the tidy-tree layer. Tree: 0=root; 1,2 children of 0; 3,4 children of 1; 2// 5,6 children of 2. Leaves 3,4,5,6 -> x 0,100,200,300; node1=avg(0,100)=50, node2=avg(200,300)=250, 3// root=avg(50,250)=150. depths 0,1,1,2,2,2,2. GREEN iff all + parent centred over children. 4// Sovereign: nx_viz_tree + nx_syscalls. license_tier: ORIGINAL 5import "nx_viz_tree.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_row(name: *u8, ok: i64) -> i64 { 11 if ok == 1 { g_w(" PASS " as *u8) } 12 if ok != 1 { g_w(" FAIL " as *u8) } 13 g_w(name); g_w("\n" as *u8) 14 return ok 15} 16 17func main() -> i64 { 18 g_w("viz-tree gate (tidy tree: parents centred over children)\n" as *u8) 19 let parent: *i64 = sys_mmap(128) as *i64 20 let x: *i64 = sys_mmap(128) as *i64 21 let depth: *i64 = sys_mmap(128) as *i64 22 parent[0] = 0 - 1; parent[1] = 0; parent[2] = 0; parent[3] = 1; parent[4] = 1; parent[5] = 2; parent[6] = 2 23 var pass: i64 = 0 24 25 vt_tree(7, parent, x, depth) 26 27 var t1: i64 = 0 28 if depth[0] == 0 { if depth[1] == 1 { if depth[3] == 2 { t1 = 1 } } } 29 pass = pass + g_row("T1 depths 0/1/2\x00" as *u8, t1) 30 31 var t2: i64 = 0 32 if x[3] == 0 { if x[4] == 100 { if x[5] == 200 { if x[6] == 300 { t2 = 1 } } } } 33 pass = pass + g_row("T2 leaves x = 0,100,200,300\x00" as *u8, t2) 34 35 var t3: i64 = 0 36 if x[1] == 50 { if x[2] == 250 { if x[0] == 150 { t3 = 1 } } } 37 pass = pass + g_row("T3 internals centred: 50,250,root 150\x00" as *u8, t3) 38 39 var t4: i64 = 0 40 if x[0] == (x[1] + x[2]) / 2 { t4 = 1 } 41 pass = pass + g_row("T4 parent centred over children\x00" as *u8, t4) 42 43 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 44 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 45 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 46 let ctr__dry: *i64 = gv_ctr() 47 ctr__dry[0] = pass 48 ctr__dry[1] = 4 49 let rc__dry: i64 = gv_verdict("VIZ-TREE-GATE" as *u8, ctr__dry, "4/4 (tidy tree, parents centred)" as *u8) 50 sys_exit(rc__dry) 51 return rc__dry 52}