feat(metatype): implement type_info($T) reflection (enum round-trip)

type_info reflects an enum / tagged-union INTO a TypeInfo value — the
inverse of define's decode — so define(declare(n), type_info(T)) mints
a byte-identical copy with NO literal variant list.

- inst.zig: new BuiltinId.type_info (comptime-only, like declare/define).
- lower/call.zig: replace the 'not yet implemented' bail. Resolve $T at
  lower time, reject non-enum/non-tagged-union loudly with a good span,
  emit callBuiltin(.type_info, [const_type], TypeInfo).
- interp.zig: reflectTypeInfo builds the exact nested-aggregate Value
  defineEnum decodes — variant {name,payload}, slice {data,len}, EnumInfo
  {variants}, TypeInfo {tag0, EnumInfo}. tagged_union reflects field.ty
  (tagless already void); payloadless `enum` reflects void per variant.
- emit: unchanged — type_info is always comptime-evaluated, the existing
  comptime-only else arm (shared with declare/define) never fires.

0619 turns green: a source enum (circle:f64 / rect:i64 / empty) reflected
and reconstructed, constructs and matches like the original.
This commit is contained in:
agra
2026-06-16 22:52:53 +03:00
parent 3805a051cc
commit 1ffda415c2
6 changed files with 92 additions and 26 deletions

View File

@@ -1,17 +1 @@
error: type_info is not yet implemented
--> examples/0619-comptime-metatype-type-info.sx:19:43
|
19 | ShapeCopy :: define(declare("ShapeCopy"), type_info(Shape));
| ^^^^^^^^^
error: cannot infer enum type for '.circle' — use an explicit type or assign to a typed variable
--> examples/0619-comptime-metatype-type-info.sx:30:14
|
30 | describe(.circle(2.5));
| ^^^^^^^
error: cannot infer enum type for '.rect' — use an explicit type or assign to a typed variable
--> examples/0619-comptime-metatype-type-info.sx:31:14
|
31 | describe(.rect(7));
| ^^^^^

View File

@@ -1 +1,3 @@
circle r=2.500000
rect n=7
empty