The compiler concept is declare/define (comptime type construction); the old "reify" framing is gone from the entire repo. - Rename: PLAN-REIFY → PLAN-METATYPE, CHECKPOINT-REIFY → CHECKPOINT-METATYPE, PLAN-POST-REIFY → PLAN-POST-METATYPE (both rewritten around declare/define); examples 0614/0615/0617 → comptime-metatype-* (+ their expected/ triplets), headers rewritten. - Scrub reify from design/execution-evolution-roadmap.md (§7 step 3 contracts, §8.1, §9 decisions, §10 gates) → declare/define / comptime type construction. - core.sx prelude pointer + parser.test.zig surface lock updated to the declare/define builtins (define(handle, info) -> Type; EnumInfo.name). No behavior change; renamed examples match their renamed snapshots. Full suite green (673), all unit tests pass. Zero `reify` tokens remain in src/docs/sx/examples.
31 lines
1.4 KiB
Plaintext
31 lines
1.4 KiB
Plaintext
// Comptime reflection: `field_type($T, i) -> Type` — the type-only field
|
|
// projection the value-level reflection (`field_value` / `type_of`) couldn't
|
|
// express.
|
|
// Reflect a struct's fields by name (`field_name`) AND by type (`field_type`),
|
|
// and a tagged-union's variant payloads. It folds at lower time, so it composes
|
|
// inside `type_eq` / `type_name` / any type-arg slot.
|
|
#import "modules/std.sx";
|
|
#import "modules/std/meta.sx";
|
|
|
|
Point :: struct { x: i64; y: f64; on: bool; }
|
|
|
|
Msg :: enum { num: i64; tag: bool; quit; }
|
|
|
|
main :: () -> i32 {
|
|
// Struct fields: name + type, position by position.
|
|
print("Point has {} fields\n", field_count(Point));
|
|
print(" 0: {} : {}\n", field_name(Point, 0), type_name(field_type(Point, 0)));
|
|
print(" 1: {} : {}\n", field_name(Point, 1), type_name(field_type(Point, 1)));
|
|
print(" 2: {} : {}\n", field_name(Point, 2), type_name(field_type(Point, 2)));
|
|
|
|
// field_type composes in a type-arg slot (type_eq folds at comptime).
|
|
print("field 0 is i64: {}\n", type_eq(field_type(Point, 0), i64));
|
|
print("field 1 is f64: {}\n", type_eq(field_type(Point, 1), f64));
|
|
|
|
// Tagged-union variant payloads (the tagless `quit` → void).
|
|
print("Msg.num payload: {}\n", type_name(field_type(Msg, 0)));
|
|
print("Msg.tag payload: {}\n", type_name(field_type(Msg, 1)));
|
|
print("Msg.quit payload: {}\n", type_name(field_type(Msg, 2)));
|
|
return 0;
|
|
}
|