Remove compiler ctx allocator
This commit is contained in:
5
Ink.jai
5
Ink.jai
@@ -237,7 +237,7 @@ run_compile_test :: (path : string, output_type : Output_Type = 0) -> Result, Co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result.info_text = builder_to_string(*sb,, ctx.allocator);
|
result.info_text = builder_to_string(*sb);
|
||||||
}
|
}
|
||||||
|
|
||||||
if output_type & .StdOut {
|
if output_type & .StdOut {
|
||||||
@@ -369,8 +369,7 @@ make_test_case :: (path : string, stage_flags : Stage_Flags, allocator := contex
|
|||||||
run_test_new :: (file_path : string, stage_flags : Stage_Flags, results : *[..]Result, output_type : Output_Type = 0) {
|
run_test_new :: (file_path : string, stage_flags : Stage_Flags, results : *[..]Result, output_type : Output_Type = 0) {
|
||||||
ctx : Compiler_Context;
|
ctx : Compiler_Context;
|
||||||
|
|
||||||
ctx.allocator = make_arena(Megabytes(128));
|
ctx.file = make_file(*ctx, file_path);
|
||||||
ctx.file = make_file(*ctx, file_path,, ctx.allocator);
|
|
||||||
|
|
||||||
result : Result;
|
result : Result;
|
||||||
if stage_flags & .Lexer {
|
if stage_flags & .Lexer {
|
||||||
|
|||||||
@@ -367,7 +367,6 @@ make_directive :: (lexer : *Lexer) -> *Token {
|
|||||||
path_tok := scan_next_token(lexer);
|
path_tok := scan_next_token(lexer);
|
||||||
path := path_tok.string_value;
|
path := path_tok.string_value;
|
||||||
ctx : Compiler_Context;
|
ctx : Compiler_Context;
|
||||||
ctx.allocator = lexer.ctx.allocator;
|
|
||||||
ctx.environment = lexer.ctx.environment;
|
ctx.environment = lexer.ctx.environment;
|
||||||
|
|
||||||
ctx.file = make_file(*ctx, path);
|
ctx.file = make_file(*ctx, path);
|
||||||
@@ -578,7 +577,6 @@ lex :: (ctx : *Compiler_Context, allocator := temp) {
|
|||||||
|
|
||||||
lexer : Lexer;
|
lexer : Lexer;
|
||||||
lexer.ctx = ctx;
|
lexer.ctx = ctx;
|
||||||
lexer.ctx.tokens.allocator = ctx.allocator;
|
|
||||||
array_reserve(*lexer.ctx.tokens, 1024 * 1024);
|
array_reserve(*lexer.ctx.tokens, 1024 * 1024);
|
||||||
|
|
||||||
init_lexer_from_string(*lexer, ctx.file.source);
|
init_lexer_from_string(*lexer, ctx.file.source);
|
||||||
|
|||||||
31
Parsing.jai
31
Parsing.jai
@@ -370,19 +370,17 @@ advance_to_sync_point :: (parse_state : *Parse_State) {
|
|||||||
////////////////////////////
|
////////////////////////////
|
||||||
//@nb - Base parsing functions
|
//@nb - Base parsing functions
|
||||||
|
|
||||||
make_node :: (nodes : *[..]AST_Node, kind : AST_Kind, allocator : Allocator) -> *AST_Node {
|
make_node :: (nodes : *[..]AST_Node, kind : AST_Kind) -> *AST_Node {
|
||||||
node : AST_Node;
|
node : AST_Node;
|
||||||
|
|
||||||
node.kind = kind;
|
node.kind = kind;
|
||||||
node.children.allocator = allocator;
|
|
||||||
node.hint_tokens.allocator = allocator;
|
|
||||||
array_add(nodes, node);
|
array_add(nodes, node);
|
||||||
|
|
||||||
return *(nodes.*[nodes.count - 1]);
|
return *(nodes.*[nodes.count - 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
make_node :: (parse_state : *Parse_State, kind : AST_Kind) -> *AST_Node {
|
make_node :: (parse_state : *Parse_State, kind : AST_Kind) -> *AST_Node {
|
||||||
return make_node(*parse_state.ctx.nodes, kind, parse_state.ctx.allocator);
|
return make_node(*parse_state.ctx.nodes, kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
// new_builtin_node :: (nodes : *[..]AST_Node, kind : AST_Kind) -> *AST_Node {
|
// new_builtin_node :: (nodes : *[..]AST_Node, kind : AST_Kind) -> *AST_Node {
|
||||||
@@ -426,13 +424,13 @@ make_builtin_token :: (tokens : *[..]Token, builder : *String_Builder, kind : To
|
|||||||
return *(tokens.*)[tokens.count - 1];
|
return *(tokens.*)[tokens.count - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
new_builtin_struct_node :: (ctx : *Compiler_Context, name : string, members : []Arg, allocator : Allocator) -> *AST_Node {
|
new_builtin_struct_node :: (ctx : *Compiler_Context, name : string, members : []Arg) -> *AST_Node {
|
||||||
sc := get_scratch(allocator);
|
sc := get_scratch(context.allocator);
|
||||||
defer scratch_end(sc);
|
defer scratch_end(sc);
|
||||||
builder : String_Builder;
|
builder : String_Builder;
|
||||||
builder.allocator = sc.allocator; // I want to find a good way to use scratch here...
|
builder.allocator = sc.allocator; // I want to find a good way to use scratch here...
|
||||||
|
|
||||||
node := make_node(*ctx.nodes, .Struct, allocator);
|
node := make_node(*ctx.nodes, .Struct);
|
||||||
|
|
||||||
source_location : Source_Range;
|
source_location : Source_Range;
|
||||||
|
|
||||||
@@ -455,11 +453,11 @@ new_builtin_struct_node :: (ctx : *Compiler_Context, name : string, members : []
|
|||||||
line += 1;
|
line += 1;
|
||||||
col = 0;
|
col = 0;
|
||||||
|
|
||||||
field_list := make_node(*ctx.nodes, .FieldList, allocator);
|
field_list := make_node(*ctx.nodes, .FieldList);
|
||||||
add_child(node, field_list);
|
add_child(node, field_list);
|
||||||
|
|
||||||
for member : members {
|
for member : members {
|
||||||
field := make_node(*ctx.nodes, .Field, allocator);
|
field := make_node(*ctx.nodes, .Field);
|
||||||
field_source_loc : Source_Range;
|
field_source_loc : Source_Range;
|
||||||
|
|
||||||
indent(*builder, 1);
|
indent(*builder, 1);
|
||||||
@@ -488,7 +486,7 @@ new_builtin_struct_node :: (ctx : *Compiler_Context, name : string, members : []
|
|||||||
|
|
||||||
source_location.end = brace_token;
|
source_location.end = brace_token;
|
||||||
|
|
||||||
source := builder_to_string(*builder,, allocator);
|
source := builder_to_string(*builder);
|
||||||
|
|
||||||
source_location.begin.source = *source.data[source_location.begin.column];
|
source_location.begin.source = *source.data[source_location.begin.column];
|
||||||
source_location.end.source = *source.data[source_location.end.column];
|
source_location.end.source = *source.data[source_location.end.column];
|
||||||
@@ -509,13 +507,13 @@ new_builtin_struct_node :: (ctx : *Compiler_Context, name : string, members : []
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_builtin_function_node :: (ctx : *Compiler_Context, name : string, members : []Arg, return_var : Arg, allocator : Allocator) -> *AST_Node {
|
new_builtin_function_node :: (ctx : *Compiler_Context, name : string, members : []Arg, return_var : Arg) -> *AST_Node {
|
||||||
sc := get_scratch(allocator);
|
sc := get_scratch(context.allocator);
|
||||||
defer scratch_end(sc);
|
defer scratch_end(sc);
|
||||||
builder : String_Builder;
|
builder : String_Builder;
|
||||||
builder.allocator = sc.allocator; // I want to find a good way to use scratch here...
|
builder.allocator = sc.allocator; // I want to find a good way to use scratch here...
|
||||||
|
|
||||||
node := make_node(*ctx.nodes, .Function, allocator);
|
node := make_node(*ctx.nodes, .Function);
|
||||||
|
|
||||||
source_location : Source_Range;
|
source_location : Source_Range;
|
||||||
|
|
||||||
@@ -531,11 +529,11 @@ new_builtin_function_node :: (ctx : *Compiler_Context, name : string, members :
|
|||||||
make_builtin_token(*ctx.tokens, *builder, .TOKEN_DOUBLECOLON, "::", *col, *line);
|
make_builtin_token(*ctx.tokens, *builder, .TOKEN_DOUBLECOLON, "::", *col, *line);
|
||||||
append(*builder, " ");
|
append(*builder, " ");
|
||||||
make_builtin_token(*ctx.tokens, *builder, .TOKEN_LEFTPAREN, "(", *col, *line);
|
make_builtin_token(*ctx.tokens, *builder, .TOKEN_LEFTPAREN, "(", *col, *line);
|
||||||
field_list := make_node(*ctx.nodes, .FieldList, allocator);
|
field_list := make_node(*ctx.nodes, .FieldList);
|
||||||
add_child(node, field_list);
|
add_child(node, field_list);
|
||||||
|
|
||||||
for member : members {
|
for member : members {
|
||||||
field := make_node(*ctx.nodes, .Field, allocator);
|
field := make_node(*ctx.nodes, .Field);
|
||||||
field_source_loc : Source_Range;
|
field_source_loc : Source_Range;
|
||||||
|
|
||||||
// field_ident := make_builtin_token(*ctx.tokens, *builder, .TOKEN_IDENTIFIER, tprint("%", member.name), *col, *line);
|
// field_ident := make_builtin_token(*ctx.tokens, *builder, .TOKEN_IDENTIFIER, tprint("%", member.name), *col, *line);
|
||||||
@@ -559,7 +557,7 @@ new_builtin_function_node :: (ctx : *Compiler_Context, name : string, members :
|
|||||||
|
|
||||||
source_location.end = semicolon_tok;
|
source_location.end = semicolon_tok;
|
||||||
|
|
||||||
source := builder_to_string(*builder,, allocator);
|
source := builder_to_string(*builder);
|
||||||
|
|
||||||
source_location.begin.source = *source.data[source_location.begin.column];
|
source_location.begin.source = *source.data[source_location.begin.column];
|
||||||
source_location.end.source = *source.data[source_location.end.column];
|
source_location.end.source = *source.data[source_location.end.column];
|
||||||
@@ -1591,7 +1589,6 @@ parse :: (ctx : *Compiler_Context, allocator := temp) {
|
|||||||
defer clear_context_allocators();
|
defer clear_context_allocators();
|
||||||
|
|
||||||
parse_state : Parse_State;
|
parse_state : Parse_State;
|
||||||
ctx.nodes.allocator = ctx.allocator;
|
|
||||||
array_reserve(*ctx.nodes, 4096);
|
array_reserve(*ctx.nodes, 4096);
|
||||||
parse_state.current_token_index = 0;
|
parse_state.current_token_index = 0;
|
||||||
parse_state.ctx = ctx;
|
parse_state.ctx = ctx;
|
||||||
|
|||||||
@@ -723,7 +723,7 @@ Arg :: struct {
|
|||||||
new_builtin_struct :: (checker : *Semantic_Checker, name : string, members : []Arg) -> *Type_Variable, Type_Variable_Handle {
|
new_builtin_struct :: (checker : *Semantic_Checker, name : string, members : []Arg) -> *Type_Variable, Type_Variable_Handle {
|
||||||
tv, handle := new_builtin_type_variable(checker, .Struct, .Declaration, name, name);
|
tv, handle := new_builtin_type_variable(checker, .Struct, .Declaration, name, name);
|
||||||
|
|
||||||
builtin_node := new_builtin_struct_node(checker.ctx, name, members, checker.ctx.allocator);
|
builtin_node := new_builtin_struct_node(checker.ctx, name, members);
|
||||||
|
|
||||||
symbol : Defined_Symbol;
|
symbol : Defined_Symbol;
|
||||||
symbol.name = name;
|
symbol.name = name;
|
||||||
@@ -765,7 +765,7 @@ new_builtin_struct :: (checker : *Semantic_Checker, name : string, members : []A
|
|||||||
new_builtin_function :: (checker : *Semantic_Checker, name : string, args : []Arg, return_arg : Arg) -> *Type_Variable, Type_Variable_Handle {
|
new_builtin_function :: (checker : *Semantic_Checker, name : string, args : []Arg, return_arg : Arg) -> *Type_Variable, Type_Variable_Handle {
|
||||||
tv, handle := new_builtin_type_variable(checker, .Function, .Declaration, name);
|
tv, handle := new_builtin_type_variable(checker, .Function, .Declaration, name);
|
||||||
|
|
||||||
builtin_node := new_builtin_function_node(checker.ctx, name, args, return_arg, checker.ctx.allocator);
|
builtin_node := new_builtin_function_node(checker.ctx, name, args, return_arg);
|
||||||
|
|
||||||
function : Defined_Symbol;
|
function : Defined_Symbol;
|
||||||
function.name = name;
|
function.name = name;
|
||||||
@@ -836,10 +836,8 @@ init_semantic_checker :: (checker : *Semantic_Checker, root : *AST_Node, path :
|
|||||||
checker.program_root = root;
|
checker.program_root = root;
|
||||||
checker.path = path;
|
checker.path = path;
|
||||||
|
|
||||||
checker.ctx.type_variables.allocator = checker.ctx.allocator;
|
|
||||||
array_reserve(*checker.ctx.type_variables, 2048);
|
array_reserve(*checker.ctx.type_variables, 2048);
|
||||||
|
|
||||||
checker.ctx.scope_stack.allocator = make_arena(Megabytes(8));
|
|
||||||
checker.ctx.scope_stack.stack.allocator = checker.ctx.scope_stack.allocator;
|
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, 256);
|
||||||
|
|
||||||
@@ -2094,7 +2092,6 @@ add_builtins :: (checker : *Semantic_Checker) {
|
|||||||
checker.state = .Adding_Builtins;
|
checker.state = .Adding_Builtins;
|
||||||
|
|
||||||
checker.ctx.file = make_file_from_string(BUILTIN);
|
checker.ctx.file = make_file_from_string(BUILTIN);
|
||||||
checker.ctx.allocator = make_arena(Megabytes(128));
|
|
||||||
|
|
||||||
prev_file := checker.ctx.file;
|
prev_file := checker.ctx.file;
|
||||||
prev_root := checker.ctx.root;
|
prev_root := checker.ctx.root;
|
||||||
|
|||||||
@@ -175,8 +175,6 @@ Compiler_Context :: struct {
|
|||||||
|
|
||||||
had_error : bool;
|
had_error : bool;
|
||||||
messages : [..]Compiler_Message;
|
messages : [..]Compiler_Message;
|
||||||
|
|
||||||
allocator : Allocator;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#add_context scratch_allocators : [2]Allocator;
|
#add_context scratch_allocators : [2]Allocator;
|
||||||
|
|||||||
Reference in New Issue
Block a user