A bunch of allocator stuff

This commit is contained in:
2024-09-10 07:21:27 +02:00
parent d01fca146c
commit 517209c886
3 changed files with 74 additions and 10 deletions

View File

@@ -126,6 +126,7 @@ Type_Constraint :: struct {
Scope_Stack :: struct {
allocator : Allocator;
arena : Arena;
stack : [..]Scope;
}
@@ -166,8 +167,10 @@ Scope :: struct {
Scope_Handle :: #type, distinct u32;
Semantic_Check_Result :: struct {
messages : [..]Compiler_Message;
had_error : bool;
messages : [..]Compiler_Message;
message_arena : Arena;
message_allocator : Allocator;
had_error : bool;
vertex_entry_point : *AST_Node;
pixel_entry_point : *AST_Node;
@@ -176,6 +179,8 @@ Semantic_Check_Result :: struct {
scope_stack : Scope_Stack;
type_variables : [..]Type_Variable;
type_var_arena : Arena;
type_var_allocator : Allocator;
property_name : string;
}
@@ -600,7 +605,7 @@ record_error :: (checker : *Semantic_Checker, error_string : string, locations :
error.message = error_string;
checker.result.had_error = true;
array_add(*checker.result.messages, error);
array_add(*checker.result.messages, error);
}
is_proper :: (var : Type_Variable) -> bool {
@@ -636,6 +641,8 @@ push_scope :: (checker : *Semantic_Checker, name := "", kind : Scope_Kind = .Glo
scope.builtin = true;
}
scope.children.allocator = checker.result.scope_stack.allocator;
if checker.current_scope {
scope := get_current_scope(checker);
array_add(*scope.children, xx count);
@@ -726,7 +733,10 @@ init_semantic_checker :: (checker : *Semantic_Checker, root : *AST_Node, path :
checker.path = path;
// @Incomplete(niels): Use other allocator and/or add static array with convenience functions
checker.result.type_var_allocator = make_arena(*checker.result.type_var_arena);
array_reserve(*checker.result.type_variables, 2048);
checker.result.scope_stack.allocator = make_arena(*checker.result.scope_stack.arena);
array_reserve(*checker.result.scope_stack.stack, 256);
global_scope, global_handle := push_scope(checker, kind = .Global);
@@ -1605,7 +1615,9 @@ types_compatible :: (checker : *Semantic_Checker, lhs : Type_Variable_Handle, rh
for i : 0..lhs_struct_var.child_count - 1 {
lhs_child := lhs_struct_var.children[i];
rhs_child := rhs_struct_var.children[i];
if !types_compatible(checker, lhs_child, rhs_child) return false;
if !types_compatible(checker, lhs_child, rhs_child) {
return false;
}
}
return true;
@@ -1625,6 +1637,7 @@ union_terms :: (checker : *Semantic_Checker, lhs_handle : Type_Variable_Handle,
lhs_var := h2tv(checker, lhs_handle);
rhs_var := h2tv(checker, rhs_handle);
print("% %\n", type_to_string(h2tv(checker, lhs_handle)), type_to_string(h2tv(checker, rhs_handle)));
if usage_site {
type_mismatch(checker, usage_site, rhs_var.source_node.parent, rhs_handle, lhs_handle);
} else {
@@ -1818,11 +1831,14 @@ type_to_string :: (type_variable : Type_Variable) -> string {
return Typenames[type_variable.type];
}
case .Function; #through;
case .Struct;
return type_variable.typename;
case .Struct; {
print("%\n", type_variable);
return type_variable.typename;
}
case .Array;
return "array";
}
return "";
}