_offc_probe_struct.nx source
↩ module page · 30 lines · 707 B
1// Tests nxc.elf codegen for: struct allocation, field write, field read,
2// and a function call. If this works but regalloc_test.nx doesn't, the
3// bug is in nxc.elf's handling of more complex struct constructs.
4
5import "syscalls.nx"
6
7struct Point {
8 x: i64,
9 y: i64,
10 z: i64,
11}
12
13func add_xyz(p: *Point) -> i64 {
14 return p.x + p.y + p.z
15}
16
17func main() -> i64 {
18 let raw: *u8 = sys_mmap(24)
19 let p: *Point = raw as *Point
20 p.x = 10
21 p.y = 20
22 p.z = 12
23 let n: i64 = add_xyz(p) // expects 42
24 let msg: *u8 = sys_mmap(8)
25 msg[0] = 0x30 + (n / 10) // '4'
26 msg[1] = 0x30 + (n - (n/10)*10) // '2'
27 msg[2] = 0x0A // '\n'
28 sys_write(1, msg, 3)
29 return 0
30}