Files
sx/examples/0614-comptime-reify-enum.sx
agra 5f2419854e green: erase the sx reify sugar — declare/define are the only constructors
Per the directive to strip reify entirely: the sx `reify(info)` one-shot is
removed. `define(handle, info)` now RETURNS the (completed) handle, so the
one-shot constructor chains as a single expression:
    T :: define(declare(), .enum(.{ name = "T", variants = ... }));

- meta.sx: drop reify; RecvResult/TryResult use `define(declare(), …)`.
- interp .define returns the handle type_tag (was void); call.zig lowers it
  with `Type` result and sets the info arg's target type to TypeInfo so the
  intercepted call still infers the `.enum(…)` literal.
- returnExprMintsType: a type-fn body that returns `define(…)` (or a bodied
  non-generic Type-returning sx helper) is comptime-evaluated.
- examples 0614 (direct) + 0615 (type-fn) use `define(declare(), …)`.

Full suite green (673). Files/docs still carry the old reify naming — the
rename sweep is the next commit.
2026-06-16 21:12:32 +03:00

30 lines
944 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 :: define(declare(), .enum(.{ name = "E", 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;
}