feat(metatype): widen type_info/define to struct types
TypeInfo gains a `struct(StructInfo) variant (StructField{name,type});
the metatype system now reflects AND constructs structs, not just enums.
- meta.sx: StructField / StructInfo / `struct TypeInfo variant.
- interp: reflectTypeInfo builds .struct (tag 1) for a source @"struct";
define dispatches on the TypeInfo tag (defineType) -> defineEnum (0) /
defineStruct (1). defineStruct mirrors defineEnum (dup-field-name check
included) but completes the declare slot AS a struct via replaceKeyedInfo
(a kind change re-keys the intern map; updatePreservingKey asserts no
key change, true only for the enum path).
- call.zig: the lower-time type_info guard now admits @"struct".
define(declare("P"), .struct(.{ fields = .[ … ] })) builds a struct, and
define(declare("C"), type_info(SrcStruct)) round-trips one. Suite green
(682); enum path (0619) unchanged.
This commit is contained in:
@@ -23,12 +23,26 @@ EnumInfo :: struct {
|
||||
variants: []EnumVariant;
|
||||
}
|
||||
|
||||
// One field of a constructed struct: a name plus its type.
|
||||
StructField :: struct {
|
||||
name: string;
|
||||
type: Type;
|
||||
}
|
||||
|
||||
// The shape of a struct being reflected or constructed. As with `EnumInfo`, the
|
||||
// type's NAME travels in `declare(name)`, not here.
|
||||
StructInfo :: struct {
|
||||
fields: []StructField;
|
||||
}
|
||||
|
||||
// The reflected/constructed type shape. A tagged union over the kinds of type
|
||||
// that can be minted. Only `` .`enum `` ships today; struct/tuple land later.
|
||||
// The variant uses the backtick raw-identifier escape so it reads as the
|
||||
// keyword `enum` (`` .`enum(...) ``) rather than a mangled `enum_`.
|
||||
// that can be minted — `` .`enum `` and `` .`struct `` ship today (tuple later).
|
||||
// The variants use the backtick raw-identifier escape so they read as the
|
||||
// keywords `enum` / `struct` (`` .`enum(...) `` / `` .`struct(...) ``) rather than
|
||||
// mangled `enum_` / `struct_`.
|
||||
TypeInfo :: enum {
|
||||
`enum: EnumInfo;
|
||||
`struct: StructInfo;
|
||||
}
|
||||
|
||||
// The compiler's ONLY type-construction primitives (comptime-only #builtins):
|
||||
|
||||
Reference in New Issue
Block a user