// Comptime compiler API — a welded struct mirrors the compiler's real Zig type // byte-for-byte by declaring its fields in the compiler type's MEMORY order. // // `StructInfo` is the real `types.TypeInfo.StructInfo`, which Zig reorders from // source order to (fields, name, nominal_id, is_protocol). The sx header declares // the fields in that memory order; the compiler reflects the bound Zig type // (@offsetOf/@sizeOf) and validates the header matches — so the struct is laid // out identically and a pointer to it can be cast to the compiler's own type and // dereferenced. Nothing is maintained by hand: a types.zig change re-reflects. #import "modules/std.sx"; compiler :: #library "compiler"; Field :: struct abi(.zig) extern compiler { name: u32; ty: u32; } StructInfo :: struct abi(.zig) extern compiler { fields: []Field; name: u32; nominal_id: u32; is_protocol: bool; } main :: () { si : StructInfo = ---; si.name = 42; si.nominal_id = 7; si.is_protocol = true; print("name={} nominal={} proto={}\n", si.name, si.nominal_id, si.is_protocol); }