diff --git a/check.jai b/check.jai index b900e4c..8350aa1 100644 --- a/check.jai +++ b/check.jai @@ -892,13 +892,13 @@ init_semantic_checker :: (checker : *Checker, root : *AST_Node, path : string) { checker.program_root = root; checker.path = path; - array_reserve(*checker.ctx.type_variables, 2048); + array_reserve(*checker.ctx.type_variables, 1024); checker.ctx.scope_stack.stack.allocator = checker.ctx.scope_stack.allocator; - array_reserve(*checker.ctx.scope_stack.stack, 256); + array_reserve(*checker.ctx.scope_stack.stack, 32); global_scope, global_handle := push_scope(checker, kind = .Global); - array_reserve(*global_scope.children, 2048); + array_reserve(*global_scope.children, 32); } find_symbol :: (scope_stack : Scope_Stack, name : string, current_scope : Scope_Handle, containing_scope : *Scope_Handle = null) -> *Defined_Symbol { @@ -1198,7 +1198,6 @@ declare_function :: (checker : *Checker, node : *AST_Node, builtin : bool = fals symbol.source_node = node; symbol.type_variable = 0; symbol.functions.allocator = get_current_scope(checker).allocator; - array_reserve(*symbol.functions, 4); array_add(*symbol.functions, function); add_symbol_to_scope(checker.state, *checker.ctx.scope_stack, checker.current_scope, name_to_check, symbol); @@ -2026,7 +2025,7 @@ types_compatible :: (checker : *Checker, lhs : Type_Variable_Handle, rhs : Type_ return false; } -add_builtins_new :: (checker : *Checker) { +add_builtins :: (checker : *Checker) { checker.state = .Adding_Builtins; float_name := Typenames[Type_Kind.Float]; @@ -2294,64 +2293,6 @@ add_builtins_new :: (checker : *Checker) { checker.state = .Type_Checking; } -add_builtins :: (checker : *Checker) { - source_location := #location().fully_pathed_filename; - path_array := split(source_location, "/"); - - sb : String_Builder; - for i : 0..path_array.count - 2 { - print_to_builder(*sb, path_array[i]); - append(*sb, "/"); - } - - append(*sb, "builtins.ink"); - - path := builder_to_string(*sb); - - BUILTIN, ok := read_entire_file(path); - - if !ok { - messages : [..]Compiler_Message; - internal_error_message(*messages, "Error loading builtin functions.", checker.path); - print("%\n", report_messages(checker.ctx, messages)); - assert(false); - return; - } - - checker.state = .Adding_Builtins; - - checker.ctx.file = make_file_from_string(BUILTIN); - - prev_file := checker.ctx.file; - prev_root := checker.ctx.root; - prev_tokens := checker.ctx.tokens; - - checker.ctx.root = null; - - tokens : [..]Token; - scratch := get_scratch(); - defer scratch_end(scratch); - tokens.allocator = scratch.allocator; - array_reserve(*tokens, 1024 * 1024); - checker.ctx.tokens = tokens; - - checker.ctx.tokens.count = 0; - - lex(checker.ctx); - parse(checker.ctx); - type_check(checker, checker.ctx.root); - - for *type_var : checker.ctx.type_variables { - type_var.builtin = true; - } - - checker.state = .Type_Checking; - - checker.ctx.file = prev_file; - checker.ctx.root = prev_root; - checker.ctx.tokens = prev_tokens; -} - type_check :: (checker : *Checker, root : *AST_Node) { traverse(checker, root); } @@ -2373,15 +2314,12 @@ check :: (ctx : *Compiler_Context, allocator : Allocator = temp) { init_semantic_checker(*checker, ctx.root, ctx.file.path); - add_builtins_new(*checker); - // add_builtins(*checker); + add_builtins(*checker); type_check(*checker, ctx.root); ctx.had_error |= checker.had_error; } - - } // =========================================================== diff --git a/lexing.jai b/lexing.jai index 69c78cd..dde1193 100644 --- a/lexing.jai +++ b/lexing.jai @@ -569,7 +569,6 @@ scan_next_token :: (lexer : *Lexer) -> *Token { s : string = .{ count = 1, data = *c }; record_error(lexer, tprint("Invalid token: %", s)); return null; - // return error_token(lexer, tprint("Invalid token: %", s)); } lex :: (ctx : *Compiler_Context, allocator := temp) { @@ -585,7 +584,7 @@ lex :: (ctx : *Compiler_Context, allocator := temp) { lexer : Lexer; lexer.ctx = ctx; - array_reserve(*lexer.ctx.tokens, 1024); + array_reserve(*lexer.ctx.tokens, 128); init_lexer_from_string(*lexer, ctx.file.source); lexer.path = ctx.file.path;