code wiki / (root) / _offc_struct_cast.nx

_offc_struct_cast.nx source

↩ module page · 21 lines · 489 B

1// Mirror of the emit_function pattern: 2// let f: *Function = (base + fi * 176) as *Function 3// let name_addr: i64 = f.name_start 4// ... 5// If this pattern produces wrong asm, that's the residual Bar 3 bug. 6 7import "syscalls.nx" 8 9struct F { 10 name: i64, 11 other: i64, 12} 13 14func main() -> i64 { 15 let raw: *u8 = sys_mmap(64) 16 let base: i64 = raw as i64 17 let f: *F = (base + 0) as *F 18 f.name = 42 19 let v: i64 = f.name 20 return v // expect 42 21}