code wiki / (root) / xfile_struct_writer.nx

xfile_struct_writer.nx source

↩ module page · 22 lines · 667 B

1import "xfile_struct_types.nx" 2 3// Mirror of ir.nx's ir_add_global_string pattern: cast a raw byte 4// region to *G, then write fields by name. If the C anchor assigns 5// G's fields the same offsets here as in main, the reader sees what 6// we wrote. 7func xfile_writer_fill(base: i64, n: i64) -> i64 { 8 var i: i64 = 0 9 while i < n { 10 let g: *G = (base + i * 80) as *G 11 g.id = i 12 g.name_bytes = 0 as *u8 13 g.name_len = 100 + i 14 g.bytes = 0 as *u8 15 g.len = 200 + i 16 g.is_string = 0 17 g.zero_init = 0 18 g.writable = 0 19 i = i + 1 20 } 21 return 0 22}