code wiki / _hdl_build / _pe_peerwire_fsm.nx

_pe_peerwire_fsm.nx source

↩ module page · 55 lines · 2029 B

1// AUTHORED BY THE NISHI BUILDER (pattern: STATE_MACHINE) -- baked transition walk, no Claude logic 2import "nx_syscalls.nx" 3func _pe_peerwire_fsm_step(s: i64, e: i64) -> i64 { 4 if s < 0 { return 0 - 1 } 5 if s >= 6 { return 0 - 1 } 6 if e < 0 { return 0 - 1 } 7 if e >= 6 { return 0 - 1 } 8 if s == 0 { if e == 0 { return 1 } } 9 if s == 0 { if e == 1 { return 0 } } 10 if s == 0 { if e == 2 { return 0 } } 11 if s == 0 { if e == 3 { return 0 } } 12 if s == 0 { if e == 4 { return 0 } } 13 if s == 0 { if e == 5 { return 5 } } 14 if s == 1 { if e == 0 { return 1 } } 15 if s == 1 { if e == 1 { return 2 } } 16 if s == 1 { if e == 2 { return 1 } } 17 if s == 1 { if e == 3 { return 3 } } 18 if s == 1 { if e == 4 { return 1 } } 19 if s == 1 { if e == 5 { return 5 } } 20 if s == 2 { if e == 0 { return 2 } } 21 if s == 2 { if e == 1 { return 2 } } 22 if s == 2 { if e == 2 { return 1 } } 23 if s == 2 { if e == 3 { return 4 } } 24 if s == 2 { if e == 4 { return 2 } } 25 if s == 2 { if e == 5 { return 5 } } 26 if s == 3 { if e == 0 { return 3 } } 27 if s == 3 { if e == 1 { return 4 } } 28 if s == 3 { if e == 2 { return 3 } } 29 if s == 3 { if e == 3 { return 3 } } 30 if s == 3 { if e == 4 { return 1 } } 31 if s == 3 { if e == 5 { return 5 } } 32 if s == 4 { if e == 0 { return 4 } } 33 if s == 4 { if e == 1 { return 4 } } 34 if s == 4 { if e == 2 { return 3 } } 35 if s == 4 { if e == 3 { return 4 } } 36 if s == 4 { if e == 4 { return 2 } } 37 if s == 4 { if e == 5 { return 5 } } 38 if s == 5 { if e == 0 { return 5 } } 39 if s == 5 { if e == 1 { return 5 } } 40 if s == 5 { if e == 2 { return 5 } } 41 if s == 5 { if e == 3 { return 5 } } 42 if s == 5 { if e == 4 { return 5 } } 43 if s == 5 { if e == 5 { return 5 } } 44 return 0 - 1 45} 46func _pe_peerwire_fsm_run(ev: *i64, n: i64, s0: i64) -> i64 { 47 var s: i64 = s0 48 var i: i64 = 0 49 while i < n { 50 s = _pe_peerwire_fsm_step(s, ev[i]) 51 if s < 0 { return 0 - 1 } 52 i = i + 1 53 } 54 return s 55}