code wiki / (root) / xfile_struct_writer.nx

xfile_struct_writer.nx source

↩ module page · 23 lines · 808 B

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