code wiki / (root) / _offc_out_i64.nx

_offc_out_i64.nx source

↩ module page · 31 lines · 724 B

1// Reduced repro of T#selfhost-001. Same shape as outbuf.nx::out_i64: 2// pointer-typed local, if-then early-return, two while loops doing 3// REM/DIV. Compiles with stage 1; nxc.elf hangs/SIGSEGVs. 4import "syscalls.nx" 5 6func out_i64(n: i64) -> i64 { 7 if n == 0 { 8 return 0 9 } 10 var v: i64 = n 11 if v < 0 { 12 v = 0 - v 13 } 14 let buf_raw: *u8 = sys_mmap(32) 15 let buf: *u8 = buf_raw 16 var k: i64 = 0 17 while v > 0 { 18 buf[k] = 0x30 + (v - (v / 10) * 10) 19 v = v / 10 20 k = k + 1 21 } 22 while k > 0 { 23 k = k - 1 24 sys_write(1, (((buf as i64) + k) as *u8), 1) 25 } 26 return 0 27} 28 29func main() -> i64 { 30 return out_i64(123) 31}