// Comptime compiler API — type-kind + enum-value reflection readers (Phase 3). // // Completes the READ side the metatype needs to re-express `type_info(T)` as sx: // // type_kind(t) → a stable kind discriminant, to branch on the shape // (0 other · 1 struct · 2 enum · 3 tagged_union · // 4 tuple · 5 union · 6 array · 7 vector · 8 error_set) // type_field_value(t, i) → enum variant i's integer value (explicit or ordinal) // // Together with find_type / type_field_count / type_field_name / type_field_type // / type_nominal_name (examples 0628–0629), a comptime sx function can now fully // reflect a struct/enum/tuple into data — no `#builtin` needed. All folded at // `#run`, all serviced natively by the flat-memory VM. #import "modules/std.sx"; StringId :: u32; TypeId :: u32; intern :: (s: string) -> StringId abi(.compiler); text_of :: (id: StringId) -> string abi(.compiler); find_type :: (name: StringId) -> TypeId abi(.compiler); type_kind :: (t: TypeId) -> i64 abi(.compiler); type_field_name :: (t: TypeId, idx: i64) -> StringId abi(.compiler); type_field_value :: (t: TypeId, idx: i64) -> i64 abi(.compiler); Color :: enum { red; green; blue; } WindowFlags :: enum flags u32 { vsync :: 64; resizable :: 4; hidden :: 128; } Point :: struct { x: i64; y: i64; } color_kind :: #run type_kind(find_type(intern("Color"))); // 2 = enum point_kind :: #run type_kind(find_type(intern("Point"))); // 1 = struct // Plain enum → ordinal values. green_val :: #run type_field_value(find_type(intern("Color")), 1); // 1 // Flags enum → explicit values, read by name + value. vsync_name :: #run text_of(type_field_name(find_type(intern("WindowFlags")), 0)); // "vsync" vsync_val :: #run type_field_value(find_type(intern("WindowFlags")), 0); // 64 main :: () { print("Color kind = {}, Point kind = {}\n", color_kind, point_kind); print("Color.green = {}\n", green_val); print("WindowFlags.{} = {}\n", vsync_name, vsync_val); }