reflection foundation, tuples, debug.print

This commit is contained in:
2026-07-14 23:45:30 +02:00
parent 267947e79d
commit 0b2055d64b
24 changed files with 126598 additions and 115394 deletions
+8 -3
View File
@@ -101,6 +101,7 @@ Node :: struct {
c_abi: bool,
variadic: bool,
c_layout: bool,
tuple: bool,
opaque: bool,
declared: bool,
file_hidden: bool,
@@ -273,6 +274,7 @@ define_record :: proc(
explicit_alignment: u32 = 0,
tag: Type = INVALID,
declared_tag: Type = INVALID,
tuple := false,
) -> bool {
existing, ok := node(store, id)
if !ok || (existing.kind != .Named && existing.kind != .Struct && existing.kind != .Union) ||
@@ -282,6 +284,7 @@ define_record :: proc(
index := int(id-DYNAMIC_START)
store.nodes[index].kind = .Union if is_union else .Struct
store.nodes[index].c_layout = c_layout
store.nodes[index].tuple = tuple
store.nodes[index].opaque = opaque
store.nodes[index].declared = true
store.nodes[index].explicit_size = explicit_size
@@ -342,10 +345,10 @@ anonymous_struct_fields_equal :: proc(store: ^Store, item: Node, fields: []Field
return true
}
struct_anonymous :: proc(store: ^Store, fields: []Field) -> Type {
struct_anonymous :: proc(store: ^Store, fields: []Field, tuple := false) -> Type {
for existing, index in store.nodes {
if existing.kind == .Struct && existing.name == 0 && existing.declared &&
!existing.c_layout && !existing.opaque &&
!existing.c_layout && existing.tuple == tuple && !existing.opaque &&
anonymous_struct_fields_equal(store, existing, fields) {
return DYNAMIC_START+Type(index)
}
@@ -356,13 +359,14 @@ struct_anonymous :: proc(store: ^Store, fields: []Field) -> Type {
kind=.Struct,
field_start=start,
field_count=u32(len(fields)),
tuple=tuple,
declared=true,
})
}
// Generated structs are nominal per comptime type-expression specialization.
// The checker owns canonicalization; this routine deliberately creates a fresh node.
struct_generated :: proc(store: ^Store, fields: []Field) -> Type {
struct_generated :: proc(store: ^Store, fields: []Field, tuple := false) -> Type {
start := u32(len(store.fields))
append(&store.fields, ..fields)
id := DYNAMIC_START+Type(len(store.nodes))
@@ -370,6 +374,7 @@ struct_generated :: proc(store: ^Store, fields: []Field) -> Type {
kind=.Struct,
field_start=start,
field_count=u32(len(fields)),
tuple=tuple,
declared=true,
})
return id