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