Changed type var children to static array.

This commit is contained in:
2024-09-25 13:01:56 +02:00
parent 243d83663a
commit e365067354
3 changed files with 30 additions and 27 deletions

View File

@@ -71,9 +71,8 @@ Type_Variable :: struct {
typename : string;
is_array : bool;
MAX_TYPE_VARIABLE_CHILDREN :: 16;
children : [MAX_TYPE_VARIABLE_CHILDREN]Type_Variable_Handle;
child_count : int;
MAX_TYPE_VARIABLE_CHILDREN :: 32;
children : Static_Array(Type_Variable_Handle, MAX_TYPE_VARIABLE_CHILDREN);
//@Note(niels): For constant buffers
resource_index : u32;
@@ -362,10 +361,9 @@ no_matching_overload_found :: (checker : *Semantic_Checker, call : *AST_Node, ov
func_var := h2tv(checker, func.type_variable);
if arg_list.children.count != func_var.child_count {
print_to_builder(*builder, "Not enough arguments: Wanted %, got %.\n\n", func_var.child_count, arg_list.children.count);
if arg_list.children.count != func_var.children.count {
print_to_builder(*builder, "Not enough arguments: Wanted %, got %.\n\n", func_var.children.count, arg_list.children.count);
}
}
}
@@ -544,7 +542,7 @@ type_mismatch :: (checker : *Semantic_Checker, usage_site : *AST_Node, expect_no
if got_var.builtin {
print_to_builder(*builder, "% :: (", got_var.name);
for i: 0..got_var.child_count - 1{
for i: 0..got_var.children.count - 1{
child_handle := got_var.children[i];
child := h2tv(checker, child_handle);
@@ -717,16 +715,16 @@ new_type_variable :: (checker : *Semantic_Checker) -> *Type_Variable, Type_Varia
}
add_child :: (variable : *Type_Variable, child : Type_Variable_Handle) {
assert(variable.child_count < Type_Variable.MAX_TYPE_VARIABLE_CHILDREN);
variable.children[variable.child_count] = child;
variable.child_count += 1;
assert(variable.children.count < Type_Variable.MAX_TYPE_VARIABLE_CHILDREN);
array_add(*variable.children, child);
// variable.children[variable.children.count] = child;
// variable.children.count += 1;
}
add_child :: (checker : *Semantic_Checker, handle : Type_Variable_Handle, child : Type_Variable_Handle) {
variable := h2tv(checker, handle);
assert(variable.child_count < Type_Variable.MAX_TYPE_VARIABLE_CHILDREN);
variable.children[variable.child_count] = child;
variable.child_count += 1;
assert(variable.children.count < Type_Variable.MAX_TYPE_VARIABLE_CHILDREN);
array_add(*variable.children, child);
}
init_semantic_checker :: (checker : *Semantic_Checker, root : *AST_Node, path : string) {
@@ -1029,7 +1027,7 @@ declare_function :: (checker : *Semantic_Checker, node : *AST_Node, builtin : bo
}
all_same : bool = true;
for i : 0..func_var.child_count - 1 {
for i : 0..func_var.children.count - 1 {
arg := func_var.children[i];
node_child := field_list.children[i];
@@ -1129,7 +1127,7 @@ create_function_constraint :: (checker : *Semantic_Checker, node : *AST_Node) {
constraint.kind = .Function_Decl;
constraint.function.symbol_variable = function.type_variable;
for i : 0..variable.child_count - 1 {
for i : 0..variable.children.count - 1 {
arg_var := variable.children[i];
if arg_var > 0 {
@@ -1379,11 +1377,11 @@ create_call_constraint :: (checker : *Semantic_Checker, node : *AST_Node, type_v
function := h2tv(checker, func.type_variable);
if arg_count != function.child_count {
if arg_count != function.children.count {
continue;
}
if node.children.count == 0 && function.child_count == 0 {
if node.children.count == 0 && function.children.count == 0 {
overload_found = true;
break;
}
@@ -1630,11 +1628,11 @@ types_compatible :: (checker : *Semantic_Checker, lhs : Type_Variable_Handle, rh
lhs_struct_var := h2tv(checker, lhs_struct.type_variable);
rhs_struct_var := h2tv(checker, rhs_struct.type_variable);
if lhs_struct_var.child_count != rhs_struct_var.child_count {
if lhs_struct_var.children.count != rhs_struct_var.children.count {
return false;
}
for i : 0..lhs_struct_var.child_count - 1 {
for i : 0..lhs_struct_var.children.count - 1 {
lhs_child := lhs_struct_var.children[i];
rhs_child := rhs_struct_var.children[i];
if !types_compatible(checker, lhs_child, rhs_child) {
@@ -1916,14 +1914,14 @@ pretty_print_struct :: (checker : *Semantic_Checker, builder : *String_Builder,
print_key(checker, builder, name);
append(builder, "{");
for 0..struct_type.child_count - 1 {
for 0..struct_type.children.count - 1 {
child_handle := struct_type.children[it];
child := h2tv(checker, child_handle);
print_to_builder(builder, child.name);
append(builder, " : ");
print_to_builder(builder, type_to_string(child));
if it < struct_type.child_count - 1 {
if it < struct_type.children.count - 1 {
append(builder, ", ");
}
}
@@ -2187,14 +2185,14 @@ pretty_print_type_variable :: (checker : *Semantic_Checker, type_variable : *Typ
if type_variable.kind == .Declaration {
append(builder, "{");
for 0..type_variable.child_count - 1 {
for 0..type_variable.children.count - 1 {
child_handle := type_variable.children[it];
child := h2tv(checker, child_handle);
print_to_builder(builder, child.name);
append(builder, " : ");
print_to_builder(builder, type_to_string(child));
if it < type_variable.child_count - 1 {
if it < type_variable.children.count - 1 {
append(builder, ", ");
}
}