code wiki / (root) / smoke_nxc_pipeline6.nx

smoke_nxc_pipeline6.nx source

↩ module page · 23 lines · 647 B

1// Inspect tokens generated by lex_source for `func f() { return 42 }`. 2// Returns: number of tokens (not counting EOF if present) 3 4import "syscalls.nx" 5import "types.nx" 6import "lex_kinds.nx" 7import "lex.nx" 8 9func main() -> i64 { 10 let demo: *u8 = "func f() { return 42 }" 11 12 let toks: *Tok = lex_source(demo, 4096) 13 if toks == (0 as *Tok) { return __syscall(93, 1, 0, 0, 0, 0, 0) } 14 15 var n: i64 = 0 16 let base: i64 = toks as i64 17 while n < 64 { 18 let t: *Tok = (base + n * TOK_BYTES) as *Tok 19 if t.kind == 0 { break } 20 n = n + 1 21 } 22 return __syscall(93, n & 0xFF, 0, 0, 0, 0, 0) 23}