ir
This commit is contained in:
@@ -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}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user