anonymous struct payloads

This commit is contained in:
2026-06-30 23:01:18 +02:00
parent eb06b2ee62
commit d6f9c24314
6 changed files with 317 additions and 38 deletions
+36
View File
@@ -306,6 +306,42 @@ union_anonymous :: proc(store: ^Store, fields: []Field, tag: Type) -> Type {
})
}
anonymous_struct_fields_equal :: proc(store: ^Store, item: Node, fields: []Field) -> bool {
if item.field_count != u32(len(fields)) {
return false
}
start := int(item.field_start)
end := start+int(item.field_count)
if start < 0 || end > len(store.fields) {
return false
}
for field, index in fields {
existing := store.fields[start+index]
if existing.name != field.name || existing.type != field.type {
return false
}
}
return true
}
struct_anonymous :: proc(store: ^Store, fields: []Field) -> Type {
for existing, index in store.nodes {
if existing.kind == .Struct && existing.name == 0 && existing.declared &&
!existing.c_layout && !existing.opaque &&
anonymous_struct_fields_equal(store, existing, fields) {
return DYNAMIC_START+Type(index)
}
}
start := u32(len(store.fields))
append(&store.fields, ..fields)
return intern(store, Node{
kind=.Struct,
field_start=start,
field_count=u32(len(fields)),
declared=true,
})
}
variant_id :: proc(store: ^Store, name: u32, payload: Type) -> (u16, bool) {
for variant in store.variants {
if variant.name == name && variant.payload == payload {