code wiki / _hdl_build / nx_sprawl_ratchet_gate.nx

nx_sprawl_ratchet_gate.nx source

↩ module page · 59 lines · 4345 B

1import "nx_gate_gn.nx" 2import "nx_gate_base.nx" 3// nx_sprawl_ratchet_gate.nx -- proves the multi-axis keep-it-gone ratchet: each axis holds/falls but never rises. 4// T1 ADOPT : first sight of an axis adopts current as its floor (no regression). 5// T2 RATCHET : held -> ok; rose -> regression (floor holds); fell -> ratchet the floor down. 6// T3 LOCKED : after falling to 80, a later 90 still regresses -> a cleaned level can't be climbed back past. 7// T4 COMPOSITE: all three axes held -> GREEN; one axis (debt) rises -> RED with bit0 set. 8// T5 PER-AXIS: only the axis that rose is flagged (coll rises -> bit1; debt+scratch ratchet down, not flagged). 9// then ESTABLISH the live baseline from the real scorecard (debt+collisions+scratch). 10// expect_exit: 0 license_tier: ORIGINAL 11import "nx_sprawl_ratchet.nx" 12import "nx_syscalls.nx" 13 14func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw(" 15" as *u8); return ok } 16 17func main() -> i64 { 18 gw("=== nx_sprawl_ratchet_gate: multi-axis keep-it-gone (debt + collisions + scratch) ===\n" as *u8) 19 var pass: i64=0; var total: i64=0 20 let r: *i64=sys_mmap(16) as *i64 21 22 // T1 ADOPT 23 let a: i64=spr_one(SPR_NOFLOOR, 100, r) 24 total=total+1; if a==100 { if r[0]==0 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } 25 gw("T1 ADOPT: first sight -> floor=\x00" as *u8); gn(a); gw(" reg=\x00" as *u8); gn(r[0]); gw("\n" as *u8) 26 27 // T2 RATCHET: held, rose, fell 28 let h: i64=spr_one(100,100,r); let hr: i64=r[0] 29 let u: i64=spr_one(100,150,r); let ur: i64=r[0] 30 let d: i64=spr_one(100,80,r); let dr: i64=r[0] 31 total=total+1; if h==100 { if hr==0 { if u==100 { if ur==1 { if d==80 { if dr==0 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } 32 gw("T2 RATCHET: held100(reg\x00" as *u8); gn(hr); gw(") rose150(reg\x00" as *u8); gn(ur); gw(") fell80(reg\x00" as *u8); gn(dr); gw(")\n" as *u8) 33 34 // T3 LOCKED 35 let l: i64=spr_one(80,90,r) 36 total=total+1; if l==80 { if r[0]==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } 37 gw("T3 LOCKED: after floor 80, a later 90 regresses(reg\x00" as *u8); gn(r[0]); gw(") = cleaned level locked\n" as *u8) 38 39 // T4 COMPOSITE: known floors, all-held then debt-up 40 spr_floor_set_all(100, 22, 242) 41 let v1: i64=spr_check_all(100, 22, 242, r); let reg1: i64=r[0] 42 let v2: i64=spr_check_all(150, 22, 242, r); let reg2: i64=r[0] 43 total=total+1; if v1==1 { if reg1==0 { if v2==0 { if reg2==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } 44 gw("T4 COMPOSITE: all-held->GREEN(\x00" as *u8); gn(v1); gw("); debt up->RED(\x00" as *u8); gn(v2); gw(") bitmask=\x00" as *u8); gn(reg2); gw(" (bit0=debt)\n" as *u8) 45 46 // T5 PER-AXIS: only the risen axis flagged (coll up; debt+scratch fall) 47 let v3: i64=spr_check_all(90, 30, 200, r); let reg3: i64=r[0] 48 total=total+1; if v3==0 { if reg3==2 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } 49 gw("T5 PER-AXIS: coll up + debt/scratch down -> RED bitmask=\x00" as *u8); gn(reg3); gw(" (only bit1=coll)\n" as *u8) 50 51 // ESTABLISH the live baseline from the real scorecard 52 let ld: i64=ssc_debt(); let lc: i64=ssc_collisions(); let ls: i64=ssc_scratch() 53 spr_floor_set_all(ld, lc, ls) 54 gw(" LIVE BASELINE locked: debt=\x00" as *u8); gn(ld); gw(" collisions=\x00" as *u8); gn(lc); gw(" scratch=\x00" as *u8); gn(ls); gw(" -- any future RISE on any axis now trips RED\n" as *u8) 55 56 gw("\n=== nx_sprawl_ratchet_gate \x00" as *u8); gn(pass); gw("/\x00" as *u8); gn(total) 57 if pass==total { gw(" GREEN -- multi-axis keep-it-gone: debt + collisions + scratch each locked to a floor; no new sprawl on any axis can creep in without tripping RED. Run standing (conductor pulse) for the comprehensive guard.\n" as *u8); sys_exit(0); return 0 } 58 gw(" RED\n" as *u8); sys_exit(1); return 1 59}