code wiki / (root) / nx_macroprobe.nx

nx_macroprobe.nx source

↩ module page · 30 lines · 1470 B

1// nx_macroprobe.nx -- does @ifdef TARGET_X86_64 resolve CONSISTENTLY across imported files? 2// nx_fcntl.nx compiled NX_SYS_FCNTL=25 (the @ifndef branch) while nx_syscalls.nx's numbers work. 3// Both use the identical @ifdef TARGET_X86_64 / @ifndef pattern. If one file takes the x86 branch 4// and another takes the riscv branch IN THE SAME BINARY, the macro is not applying uniformly. 5// expect_exit: 0 license_tier: ORIGINAL 6import "nx_syscalls.nx" 7import "nx_fcntl.nx" 8 9func mp_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 10func mp_puts(s: *u8) -> i64 { sys_write(1, s, mp_len(s)); return 0 } 11func mp_putn(v: i64) -> i64 { 12 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 } 13 var m: i64 = v 14 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 15 let d: *u8 = sys_mmap(24) 16 var k: i64 = 0 17 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 18 var j: i64 = k - 1 19 while j >= 0 { sys_write(1, ((d as i64)+j) as *u8, 1); j = j - 1 } 20 return 0 21} 22func main() -> i64 { 23 mp_puts("nx_syscalls.nx SYS_OPENAT = " as *u8); mp_putn(SYS_OPENAT) 24 mp_puts(" (x86 branch=257, riscv branch=56)\n" as *u8) 25 mp_puts("nx_syscalls.nx SYS_WRITE = " as *u8); mp_putn(SYS_WRITE) 26 mp_puts(" (x86 branch=1, riscv branch=64)\n" as *u8) 27 mp_puts("nx_fcntl.nx NX_SYS_OPENAT = " as *u8); mp_putn(NX_SYS_OPENAT) 28 mp_puts(" (x86 branch=257, riscv branch=56)\n" as *u8) 29 return 0 30}