smoke_repro3.nx source
↩ module page · 49 lines · 973 B
1// smoke_repro3.nx -- adds the text[i] = c style write.
2
3import "syscalls.nx"
4
5struct S {
6 src: *u8,
7 pos: i64,
8}
9
10func peek3(L: *S) -> i64 {
11 let s: *u8 = L.src
12 return s[L.pos]
13}
14
15func is_alpha3(c: i64) -> i64 {
16 if c >= 0x41 { if c <= 0x5A { return 1 } }
17 if c >= 0x61 { if c <= 0x7A { return 1 } }
18 return 0
19}
20
21func advance3(L: *S) -> i64 {
22 L.pos = L.pos + 1
23 return 0
24}
25
26func work(L: *S) -> i64 {
27 let buf_raw: *u8 = sys_mmap(96)
28 let text: *u8 = buf_raw + 32
29 var i: i64 = 0
30 while i < 8 {
31 let c: i64 = peek3(L)
32 if is_alpha3(c) {
33 text[i] = c & 0xFF
34 advance3(L)
35 i = i + 1
36 }
37 if is_alpha3(c) == 0 { break }
38 }
39 return i
40}
41
42func main() -> i64 {
43 let raw: *u8 = sys_mmap(64)
44 let L: *S = raw as *S
45 L.src = "abcDEF"
46 L.pos = 0
47 let r: i64 = work(L)
48 return __syscall(93, r, 0, 0, 0, 0, 0)
49}