This commit is contained in:
agra
2026-02-28 18:03:38 +02:00
parent 2552882ce6
commit 6a920dbd2c
24 changed files with 14084 additions and 780 deletions

View File

@@ -82,6 +82,8 @@ pub const TypeInfo = union(enum) {
pub const EnumInfo = struct {
name: StringId,
variants: []const StringId,
is_flags: bool = false,
explicit_values: ?[]const i64 = null, // for flags (power-of-2) or custom values
};
pub const UnionInfo = struct {
@@ -350,11 +352,27 @@ pub const TypeTable = struct {
.array => |arr| arr.length * self.sizeOf(arr.element),
.vector => |vec| vec.length * self.sizeOf(vec.element),
.any => 16, // {type_tag, data_ptr}
.@"struct", .@"union", .@"enum", .tuple, .protocol => {
// Sizes of composite types depend on layout — return 0 as placeholder.
// Real size computation needs struct layout info from codegen/sema.
return 0;
.@"struct" => |s| {
var total: u32 = 0;
for (s.fields) |f| total += @max(self.sizeOf(f.ty), 8);
return if (total == 0) 8 else total;
},
.@"union" => |u| {
// Size of union = tag + max(field sizes)
var max_field: u32 = 0;
for (u.fields) |f| {
const sz = self.sizeOf(f.ty);
if (sz > max_field) max_field = sz;
}
return 8 + @max(max_field, 8);
},
.@"enum" => 8, // plain enums are just integer tags
.tuple => |t| {
var total: u32 = 0;
for (t.fields) |f| total += @max(self.sizeOf(f), 8);
return if (total == 0) 8 else total;
},
.protocol => 16, // {ctx, vtable}
};
}