code wiki / _hdl_build / nx_breakprobe.nx

nx_breakprobe.nx source

↩ module page · 64 lines · 2081 B

1import "nx_syscalls.nx" 2 3func bp_p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 4 5func bp_is_ws(c: i64) -> i64 { if c == 32 { return 1 } if c == 9 { return 1 } return 0 } 6func bp_is_name(c: i64) -> i64 { 7 if c >= 97 { if c <= 122 { return 1 } } 8 if c >= 48 { if c <= 57 { return 1 } } 9 return 0 10} 11 12func main() -> i64 { 13 let s: *u8 = "ab cd=e\x00" as *u8 14 let end: i64 = 7 15 16 // P0: plain while, no break (sanity) 17 var a: i64 = 0 18 while a < end { a = a + 1 } 19 bp_p("P0\x0a\x00" as *u8) 20 21 // P1: top-level while with else-break (dt_parse_attrs:644 form) 22 var i1: i64 = 0 23 while i1 < end { if bp_is_name(s[i1] & 0xff) == 1 { i1 = i1 + 1 } else { break } } 24 bp_p("P1\x0a\x00" as *u8) 25 26 // P2: nested while, inner else-break (dt_parse_attrs:647 form) 27 var j2: i64 = 0 28 while j2 < 2 { 29 var i2: i64 = 0 30 while i2 < end { if bp_is_name(s[i2] & 0xff) == 1 { i2 = i2 + 1 } else { break } } 31 j2 = j2 + 1 32 } 33 bp_p("P2\x0a\x00" as *u8) 34 35 // P3: nested while, if-break AFTER inner loop (dt_parse_attrs:648 form) 36 var j3: i64 = 0 37 while j3 < 5 { 38 var i3: i64 = 0 39 while i3 < end { if bp_is_name(s[i3] & 0xff) == 1 { i3 = i3 + 1 } else { break } } 40 if j3 >= 1 { break } 41 j3 = j3 + 1 42 } 43 bp_p("P3\x0a\x00" as *u8) 44 45 // P4: outer while with TWO sequential inner scan loops, else-breaks (656/659 form) 46 var i4: i64 = 0 47 var rounds: i64 = 0 48 while i4 < end { 49 while i4 < end { if bp_is_name(s[i4] & 0xff) == 1 { i4 = i4 + 1 } else { break } } 50 while i4 < end { if bp_is_ws(s[i4] & 0xff) == 1 { i4 = i4 + 1 } else { break } } 51 if i4 < end { if (s[i4] & 0xff) == 61 { i4 = i4 + 1 } } 52 rounds = rounds + 1 53 if rounds > 20 { break } 54 } 55 bp_p("P4\x0a\x00" as *u8) 56 57 // P5: break in then-arm (single level) 58 var i5: i64 = 0 59 while i5 < end { if (s[i5] & 0xff) == 32 { break } i5 = i5 + 1 } 60 bp_p("P5\x0a\x00" as *u8) 61 62 bp_p("ALL-DONE\x0a\x00" as *u8) 63 return 0 64}