Files
sx/examples/0614-comptime-reify-enum.sx
agra 353109206b green(reify): implement reify(.enum) — mint a flat enum from TypeInfo
REIFY Phase 0.2 (Phase 0 complete). Lowering.reifyType (lower/nominal.zig)
reads the flat-enum TypeInfo literal off the AST, synthesizes an
ast.EnumDecl, and feeds it through the SAME type_bridge.buildEnumInfo
path source enums use — so the minted type is byte-identical to a
hand-written `enum { value: i64; closed; }` and flows through enum
codegen (layout / construct / match) UNMODIFIED (Contract 2).

Wired at the `E :: reify(...)` const-decl hook in lower/decl.zig
(replacing the Phase-0.0 loud bail). Unsupported argument shapes bail
loudly via reifyBail — never a silent default. The generic.zig inline
reify path now reports it's only supported in a `::` binding (Phase 0).

examples/0614 green: reify a {value: i64, closed} enum, construct
.value(3) and .closed, match both -> "value 3" / "closed". Full suite
green (670 examples, 447 unit).
2026-06-16 18:32:05 +03:00

30 lines
920 B
Plaintext

// REIFY Phase 0: mint a NEW nominal enum from a `TypeInfo` value at comptime,
// then construct one of its variants and match on it — exercising that a
// reify'd enum (with NO backing AST decl) flows through enum codegen unmodified
// (layout / construct / match), Contract 2.
//
// The enum has two variants: `value` carrying an i64 payload, and `closed` with
// no payload (`payload = void`).
#import "modules/std.sx";
#import "modules/std/meta.sx";
E :: reify(.enum(.{ variants = .[
EnumVariant.{ name = "value", payload = i64 },
EnumVariant.{ name = "closed", payload = void },
] }));
main :: () -> i32 {
e := E.value(3);
if e == {
case .value: (v) { print("value {}\n", v); }
case .closed: { print("closed\n"); }
}
c : E = .closed;
if c == {
case .value: (v) { print("value {}\n", v); }
case .closed: { print("closed\n"); }
}
return 0;
}