code wiki / _hdl_build / nx_callsig_gate.nx
nx_callsig_gate.nx source
↩ module page · 62 lines · 3260 B
1// nx_callsig_gate.nx -- proves the sovereign telephone-call signaling FSM (nx_callsig). Native, fast.
2import "nx_syscalls.nx"
3import "nx_callsig.nx"
4import "nx_gate_verdict.nx"
5
6func g_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
7func g_pn(v: i64) -> i64 {
8 let b: *u8 = sys_mmap(28); var x: i64 = v
9 if x == 0 { b[0]=48; sys_write(1,b,1); return 0 }
10 var d: i64=0; var y: i64=x
11 while y>0 { d=d+1; y=y/10 }
12 var i: i64=d-1; y=x
13 while i>=0 { b[i]=(48+(y%10)) as u8; y=y/10; i=i-1 }
14 sys_write(1,b,d); return 0
15}
16func g_check(name: *u8, cond: i64) -> i64 {
17 if cond==1 { g_puts(" PASS " as *u8) } else { g_puts(" FAIL " as *u8) }
18 g_puts(name); g_puts("\n" as *u8); return cond
19}
20
21func main() -> i64 {
22 g_puts("nx_callsig gate (telephone-style ring/accept/reject)\n" as *u8)
23 var pass: i64 = 0; var total: i64 = 0
24
25 // ring on invite + the callee is actively notified
26 let ring: i64 = cs_step(CS_IDLE, EV_INVITE)
27 pass = pass + g_check("invite -> RINGING (callee notified)" as *u8, (ring == CS_RINGING) & (cs_is_ringing(ring) == 1)); total=total+1
28
29 // NO accidental connect: accept only works from RINGING; stray taps don't dismiss the ring
30 var r2: i64 = 1
31 if cs_step(CS_IDLE, EV_ACCEPT) != CS_IDLE { r2 = 0 } // can't accept a call that isn't ringing
32 if cs_step(CS_RINGING, 99) != CS_RINGING { r2 = 0 } // a stray/fat-finger event keeps it ringing
33 if cs_step(CS_RINGING, 0) != CS_RINGING { r2 = 0 }
34 pass = pass + g_check("no accidental connect / stray tap can't dismiss the ring" as *u8, r2); total=total+1
35
36 // explicit accept -> connected; explicit reject -> rejected
37 var r3: i64 = 1
38 if cs_is_connected(cs_step(CS_RINGING, EV_ACCEPT)) != 1 { r3 = 0 }
39 if cs_step(CS_RINGING, EV_REJECT) != CS_REJECTED { r3 = 0 }
40 pass = pass + g_check("explicit accept->connected, reject->rejected" as *u8, r3); total=total+1
41
42 // unanswered -> MISSED (persistent record, notification not silently lost)
43 let miss: i64 = cs_step(CS_RINGING, EV_TIMEOUT)
44 pass = pass + g_check("unanswered ring -> MISSED (persistent, never silently ignored)" as *u8, (miss == CS_MISSED) & (cs_is_missed(miss) == 1)); total=total+1
45
46 // hangup ends a connected call; terminal states are sticky
47 var r5: i64 = 1
48 if cs_step(CS_CONNECTED, EV_HANGUP) != CS_ENDED { r5 = 0 }
49 if cs_step(CS_REJECTED, EV_INVITE) != CS_REJECTED { r5 = 0 } // terminal sticky
50 pass = pass + g_check("hangup->ended; terminal states sticky" as *u8, r5); total=total+1
51
52 g_puts("---- callsig gate: passed " as *u8); g_pn(pass); g_puts(" / " as *u8); g_pn(total); g_puts(" ----\n" as *u8)
53 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
54 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
55 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
56 let ctr__dry: *i64 = gv_ctr()
57 ctr__dry[0] = pass
58 ctr__dry[1] = total
59 let rc__dry: i64 = gv_verdict("CALLSIG-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8)
60 sys_exit(rc__dry)
61 return rc__dry
62}