A bunch of new allocation related stuff.
This commit is contained in:
35
Lexing.jai
35
Lexing.jai
@@ -565,21 +565,28 @@ scan_next_token :: (lexer : *Lexer) -> *Token {
|
||||
// return error_token(lexer, tprint("Invalid token: %", s));
|
||||
}
|
||||
|
||||
lex :: (result : *Compile_Result) {
|
||||
lex :: (result : *Compile_Result, allocator := temp) {
|
||||
if result.had_error {
|
||||
return;
|
||||
}
|
||||
|
||||
lexer : Lexer;
|
||||
lexer.result = result;
|
||||
lexer.result.tokens.allocator = result.allocator;
|
||||
array_reserve(*lexer.result.tokens, 1024 * 1024);
|
||||
|
||||
init_lexer_from_string(*lexer, result.file.source);
|
||||
lexer.path = result.file.path;
|
||||
token : *Token = scan_next_token(*lexer);
|
||||
while token && token.kind != .TOKEN_EOF {
|
||||
token = scan_next_token(*lexer);
|
||||
new_context := context;
|
||||
new_context.allocator = allocator;
|
||||
push_context new_context {
|
||||
init_context_allocators();
|
||||
defer clear_context_allocators();
|
||||
|
||||
lexer : Lexer;
|
||||
lexer.result = result;
|
||||
lexer.result.tokens.allocator = result.allocator;
|
||||
array_reserve(*lexer.result.tokens, 1024 * 1024);
|
||||
|
||||
init_lexer_from_string(*lexer, result.file.source);
|
||||
lexer.path = result.file.path;
|
||||
token : *Token = scan_next_token(*lexer);
|
||||
while token && token.kind != .TOKEN_EOF {
|
||||
token = scan_next_token(*lexer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -765,9 +772,11 @@ print_from_source_location :: (builder : *String_Builder, source_location : Sour
|
||||
}
|
||||
|
||||
print_from_source_location :: (source_location : Source_Range, allocator := context.allocator, indentation : int = 0) -> string {
|
||||
sc := get_scratch();
|
||||
defer scratch_end(sc);
|
||||
builder : String_Builder;
|
||||
init_string_builder(*builder,, allocator);
|
||||
print_from_source_location(*builder, source_location);
|
||||
init_string_builder(*builder,, sc.allocator);
|
||||
print_from_source_location(*builder, source_location,, sc.allocator);
|
||||
return builder_to_string(*builder,, allocator);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user