code wiki / (root) / smoke_repro4.nx

smoke_repro4.nx source

↩ module page · 76 lines · 1610 B

1// smoke_repro4.nx -- match Tok's 12-field layout + lex_ident_or_kw shape. 2 3import "syscalls.nx" 4 5struct LX { 6 src: *u8, 7 pos: i64, 8 line: i64, 9 col: i64, 10 tokens: *u8, 11 n_tokens: i64, 12 cap: i64, 13} 14 15struct TK { 16 kind: i64, 17 line: i64, 18 col: i64, 19 int_val: i64, 20 text0: i64, text1: i64, text2: i64, text3: i64, 21 text4: i64, text5: i64, text6: i64, text7: i64, 22} 23 24func peek4(L: *LX) -> i64 { 25 let s: *u8 = L.src 26 return s[L.pos] 27} 28 29func is_alpha4(c: i64) -> i64 { 30 if c >= 0x41 { if c <= 0x5A { return 1 } } 31 if c >= 0x61 { if c <= 0x7A { return 1 } } 32 return 0 33} 34 35func advance4(L: *LX) -> i64 { 36 L.pos = L.pos + 1 37 return 0 38} 39 40func work(L: *LX) -> i64 { 41 let tr: *u8 = sys_mmap(96) 42 let t: *TK = tr as *TK 43 t.kind = 2 44 t.line = L.line 45 t.col = L.col 46 t.int_val = 0 47 t.text0 = 0; t.text1 = 0; t.text2 = 0; t.text3 = 0 48 t.text4 = 0; t.text5 = 0; t.text6 = 0; t.text7 = 0 49 let base: i64 = t as i64 50 let text: *u8 = (base + 32) as *u8 51 var i: i64 = 0 52 while i < 8 { 53 let c: i64 = peek4(L) 54 if is_alpha4(c) { 55 text[i] = c & 0xFF 56 advance4(L) 57 i = i + 1 58 } 59 if is_alpha4(c) == 0 { break } 60 } 61 return i 62} 63 64func main() -> i64 { 65 let raw: *u8 = sys_mmap(96) 66 let L: *LX = raw as *LX 67 L.src = "abcDEF" 68 L.pos = 0 69 L.line = 1 70 L.col = 1 71 L.tokens = 0 as *u8 72 L.n_tokens = 0 73 L.cap = 16 74 let r: i64 = work(L) 75 return __syscall(93, r, 0, 0, 0, 0, 0) 76}