Change name Scratch_Scope to Scoped_Arena
This commit is contained in:
@@ -130,12 +130,12 @@ arena_from_buffer(void *buffer, size_t size) {
|
||||
return result;
|
||||
}
|
||||
|
||||
struct Scratch_Scope {
|
||||
struct Scoped_Arena {
|
||||
Arena *arena;
|
||||
int pos;
|
||||
Scratch_Scope(Arena *arena) {
|
||||
Scoped_Arena(Arena *arena) {
|
||||
this->arena = arena;
|
||||
this->pos = arena->len;
|
||||
}
|
||||
~Scratch_Scope() { this->arena->len = this->pos; }
|
||||
~Scoped_Arena() { this->arena->len = this->pos; }
|
||||
};
|
||||
|
||||
@@ -459,7 +459,7 @@ struct String_Replace {
|
||||
|
||||
CORE_Static String
|
||||
string_replace(Arena *scratch, Allocator *allocator, String string, Array<String_Replace> pairs) {
|
||||
Scratch_Scope _scope(scratch);
|
||||
Scoped_Arena _scope(scratch);
|
||||
String_Builder builder = {scratch};
|
||||
for (S64 i = 0; i < string.len; i++) {
|
||||
For(pairs) {
|
||||
|
||||
@@ -219,7 +219,7 @@ gen_value(Token *pos, Value a) {
|
||||
|
||||
switch (type->kind) {
|
||||
CASE_INT : {
|
||||
Scratch_Scope scratch(pctx->scratch);
|
||||
Scoped_Arena scratch(pctx->scratch);
|
||||
String postfix = get_type_postfix(type);
|
||||
const char *string = bigint_to_error_string(scratch.arena, &a.big_int_val, 10);
|
||||
gen("%s%Q", string, postfix);
|
||||
@@ -560,7 +560,7 @@ gen_ast(Ast *ast) {
|
||||
|
||||
CASE(RETURN, Return) {
|
||||
if (is_tuple(node->resolved_type)) {
|
||||
Scratch_Scope scratch(pctx->scratch);
|
||||
Scoped_Arena scratch(pctx->scratch);
|
||||
|
||||
Intern_String tuple_name = get_unique_name(node);
|
||||
gen_simple_decl(node->resolved_type, tuple_name);
|
||||
@@ -799,7 +799,7 @@ gen_ast(Ast *ast) {
|
||||
For(node->vars)
|
||||
gen_ast(it);
|
||||
|
||||
Scratch_Scope scratch(pctx->scratch);
|
||||
Scoped_Arena scratch(pctx->scratch);
|
||||
|
||||
Intern_String var_name = get_unique_name(node);
|
||||
gen_simple_decl(node->resolved_type, var_name);
|
||||
@@ -1034,7 +1034,7 @@ compile_to_c_code() {
|
||||
|
||||
// Generate slice and tuple types
|
||||
For_Named(pctx->all_types, type) {
|
||||
Scratch_Scope scratch(pctx->scratch);
|
||||
Scoped_Arena scratch(pctx->scratch);
|
||||
|
||||
if (type->kind == TYPE_SLICE) {
|
||||
genln("typedef struct Slice%llu{", type->type_id);
|
||||
|
||||
@@ -211,7 +211,7 @@ parse_all_modules() {
|
||||
CORE_Static Ast_Module *
|
||||
add_module(Token *pos, Intern_String filename, B32 command_line_module, bool string_only_module) {
|
||||
Arena *scratch = pctx->scratch;
|
||||
Scratch_Scope _scope(scratch);
|
||||
Scoped_Arena _scope(scratch);
|
||||
String absolute_file_path = {};
|
||||
String absolute_base_folder = {};
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ token_error(Token *t, String error_val) {
|
||||
|
||||
CORE_Static void
|
||||
lex_parse_u64(Core_Ctx *lexer, Token *t, S64 base) {
|
||||
Scratch_Scope _scope(lexer->scratch);
|
||||
Scoped_Arena _scope(lexer->scratch);
|
||||
Set_BigInt_Arena(lexer->scratch);
|
||||
|
||||
t->kind = TK_Integer;
|
||||
@@ -692,7 +692,7 @@ lex_restream(Core_Ctx *lexer, String istream, String file) {
|
||||
lexer->stream.line_begin = istream.str;
|
||||
lexer->stream.file = lexer->intern(file);
|
||||
|
||||
Scratch_Scope _scope(lexer->scratch);
|
||||
Scoped_Arena _scope(lexer->scratch);
|
||||
lexer->stream.indent_stack.allocator = lexer->scratch;
|
||||
lexer->stream.indent_stack.add(&lexer->same_scope_token);
|
||||
lex__stream(lexer);
|
||||
|
||||
@@ -109,7 +109,7 @@ static void compile_file(Allocator *allocator, String filename, U32 compile_flag
|
||||
printf("%f - ", total_compiler_time);
|
||||
|
||||
Arena *scratch = pctx->scratch;
|
||||
Scratch_Scope _scope(scratch);
|
||||
Scoped_Arena _scope(scratch);
|
||||
|
||||
F64 begin = os_time();
|
||||
String_Builder builder = {scratch};
|
||||
@@ -175,7 +175,7 @@ int main(int argument_count, char **arguments) {
|
||||
For(args) {
|
||||
|
||||
if (it == "-testing"_s) {
|
||||
Scratch_Scope _scope(&scratch);
|
||||
Scoped_Arena _scope(&scratch);
|
||||
Array<OS_File_Info> examples = os_list_dir(&scratch, &scratch, "examples"_s);
|
||||
Array<OS_File_Info> tests = os_list_dir(&scratch, &scratch, "tests"_s);
|
||||
For(examples) {
|
||||
|
||||
@@ -225,7 +225,7 @@ parse_init_stmt(Ast_Expr *expr) {
|
||||
|
||||
CORE_Static Ast_Call *
|
||||
parse_expr_call(Ast_Expr *left, Token_Kind close_kind) {
|
||||
Scratch_Scope scratch(pctx->scratch);
|
||||
Scoped_Arena scratch(pctx->scratch);
|
||||
Token *pos = token_get();
|
||||
Array<Ast_Call_Item *> exprs = {scratch.arena};
|
||||
|
||||
@@ -279,7 +279,7 @@ parse_stmt_scope(Ast_Scope *scope_defined_outside = 0) {
|
||||
if (token_expect(OPEN_SCOPE)) { // @todo: Fix error message here, it doesn't show proper token context
|
||||
Token *token_block = token_get();
|
||||
|
||||
Scratch_Scope scratch(pctx->scratch);
|
||||
Scoped_Arena scratch(pctx->scratch);
|
||||
if (!scope_defined_outside) scope = begin_stmt_scope(scratch.arena, token_block);
|
||||
do {
|
||||
Token *token = token_get();
|
||||
@@ -499,7 +499,7 @@ parse_parameter_list(Arena *arena) {
|
||||
|
||||
CORE_Static Ast_Lambda *
|
||||
parse_lambda(Token *token) {
|
||||
Scratch_Scope scratch(pctx->scratch);
|
||||
Scoped_Arena scratch(pctx->scratch);
|
||||
|
||||
Array<Ast_Decl *> params = parse_parameter_list(scratch.arena);
|
||||
Array<Ast_Expr *> ret = {scratch.arena};
|
||||
@@ -723,7 +723,7 @@ parse_assign_expr() {
|
||||
|
||||
CORE_Static Ast_Decl *
|
||||
parse_struct(Token *pos, Ast_Kind kind) {
|
||||
Scratch_Scope scratch(pctx->scratch);
|
||||
Scoped_Arena scratch(pctx->scratch);
|
||||
|
||||
Array<Ast_Decl *> params = {};
|
||||
if (token_match(TK_OpenParen)) {
|
||||
@@ -758,7 +758,7 @@ parse_struct(Token *pos, Ast_Kind kind) {
|
||||
|
||||
CORE_Static Ast_Decl *
|
||||
parse_enum(Token *pos) {
|
||||
Scratch_Scope scratch(pctx->scratch);
|
||||
Scoped_Arena scratch(pctx->scratch);
|
||||
Ast_Expr *typespec = parse_optional_type();
|
||||
Token *flag = token_match_pound(pctx->intern_flag);
|
||||
|
||||
@@ -836,7 +836,7 @@ register_ast_file(Token *pos, String absolute_file_path, Ast_Module *module, B32
|
||||
|
||||
CORE_Static Intern_String
|
||||
preprocess_filename(Token *token_filename) {
|
||||
Scratch_Scope _scope(pctx->scratch);
|
||||
Scoped_Arena _scope(pctx->scratch);
|
||||
String filename = token_filename->intern_val.s;
|
||||
Array<String_Replace> replace = {pctx->scratch};
|
||||
replace.add({"$OS"_s, OS_NAME});
|
||||
@@ -994,7 +994,7 @@ parse_decl(B32 is_global) {
|
||||
CORE_Static void
|
||||
parse_file(Ast_File *file) {
|
||||
assert(file);
|
||||
Scratch_Scope scratch(pctx->scratch);
|
||||
Scoped_Arena scratch(pctx->scratch);
|
||||
|
||||
if (!file->filecontent.len) {
|
||||
file->filecontent = os_read_file(pctx->perm, file->absolute_file_path);
|
||||
|
||||
@@ -40,6 +40,7 @@ void next(Ast_Iter *iter) {
|
||||
Ast_Scope *node = (Ast_Scope *)ast;
|
||||
iter->stack.add(node);
|
||||
For(node->stmts) iter->stack.add(it);
|
||||
For(node->decls) iter->stack.add(it);
|
||||
} break;
|
||||
|
||||
case AST_MODULE: invalid_codepath; break;
|
||||
|
||||
@@ -114,7 +114,7 @@ CORE_Static void
|
||||
check_value_bounds(Token *pos, Value *a) {
|
||||
if (!is_int(a->type)) return;
|
||||
|
||||
Scratch_Scope scratch(pctx->scratch);
|
||||
Scoped_Arena scratch(pctx->scratch);
|
||||
if (!bigint_fits_in_bits(&a->big_int_val, a->type->size * 8, is_signed_int(a->type))) {
|
||||
const char *string = bigint_to_error_string(scratch.arena, &a->big_int_val, 10);
|
||||
compiler_error(pos, "Value %s doesn't fit in type %Q", string, typestring(a->type));
|
||||
@@ -518,7 +518,7 @@ make_scope_search(Allocator *arena, Ast_Scope *scope, Intern_String name) {
|
||||
|
||||
CORE_Static Ast_Decl *
|
||||
search_for_single_decl(Ast_Scope *scope, Intern_String name, bool error_if_no_matches = true) {
|
||||
Scratch_Scope scratch(pctx->scratch);
|
||||
Scoped_Arena scratch(pctx->scratch);
|
||||
|
||||
Scope_Search search = make_scope_search(scratch.arena, scope, name);
|
||||
scope_search(&search);
|
||||
@@ -536,7 +536,7 @@ search_for_single_decl(Ast_Scope *scope, Intern_String name, bool error_if_no_ma
|
||||
|
||||
CORE_Static Ast_Decl *
|
||||
resolve_name(Ast_Scope *scope, Token *pos, Intern_String name, Search_Flag search_flags) {
|
||||
Scratch_Scope scratch(pctx->scratch);
|
||||
Scoped_Arena scratch(pctx->scratch);
|
||||
Scope_Search search = make_scope_search(scratch.arena, scope, name);
|
||||
search.search_only_current_scope = search_flags & SEARCH_ONLY_CURRENT_SCOPE;
|
||||
scope_search(&search);
|
||||
@@ -569,7 +569,7 @@ resolve_operator_overload(Ast_Scope *scope, Ast_Type *left, Ast_Type *right, Tok
|
||||
|
||||
// Search for all possible candidates in three scopes
|
||||
// The current module, left type definition module, right type definition module
|
||||
Scratch_Scope scratch(pctx->scratch);
|
||||
Scoped_Arena scratch(pctx->scratch);
|
||||
Scope_Search search = make_scope_search(scratch.arena, scope, op_info->op);
|
||||
if (left->ast && left->ast->parent_scope) search.scopes.add(left->ast->parent_scope);
|
||||
if (right && right->ast && right->ast->parent_scope) search.scopes.add(right->ast->parent_scope);
|
||||
@@ -603,7 +603,7 @@ insert_into_scope(Ast_Scope *scope, Ast_Decl *decl) {
|
||||
//
|
||||
// It's also called when scanning top level declarations of a module
|
||||
// as such we probably don't want to call any resolve stuff here
|
||||
Scratch_Scope scratch(pctx->scratch);
|
||||
Scoped_Arena scratch(pctx->scratch);
|
||||
Scope_Search search = make_scope_search(scratch.arena, scope, decl->name);
|
||||
search.search_only_current_scope = true;
|
||||
scope_search(&search);
|
||||
@@ -739,7 +739,7 @@ resolve_stmt(Ast *ast, Ast_Type *ret) {
|
||||
|
||||
switch (ast->kind) {
|
||||
CASE(RETURN, Return) { // @todo: need to check if all paths return a value
|
||||
Scratch_Scope scratch(pctx->scratch);
|
||||
Scoped_Arena scratch(pctx->scratch);
|
||||
Array<Ast_Type *> types = {scratch.arena};
|
||||
|
||||
int i = 0;
|
||||
@@ -905,7 +905,7 @@ resolve_stmt(Ast *ast, Ast_Type *ret) {
|
||||
|
||||
CORE_Static Ast_Type *
|
||||
resolve_lambda_type(Ast_Lambda *lambda) {
|
||||
Scratch_Scope scratch(pctx->scratch);
|
||||
Scoped_Arena scratch(pctx->scratch);
|
||||
Array<Ast_Type *> args = {scratch.arena};
|
||||
Array<Ast_Type *> ret = {scratch.arena};
|
||||
For(lambda->ret) {
|
||||
@@ -1582,7 +1582,7 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_and_const_str
|
||||
}
|
||||
node->resolved_decl = name.resolved_decl;
|
||||
|
||||
Scratch_Scope scratch(pctx->scratch);
|
||||
Scoped_Arena scratch(pctx->scratch);
|
||||
Array<Ast_Call_Item *> items = {scratch.arena};
|
||||
S64 default_iter = 0;
|
||||
|
||||
@@ -1705,7 +1705,7 @@ resolve_decl(Ast_Decl *ast) {
|
||||
try_resolving_lambda_scope(&result, lambda, node->type);
|
||||
node->value = result.value;
|
||||
|
||||
Scratch_Scope scratch(pctx->scratch);
|
||||
Scoped_Arena scratch(pctx->scratch);
|
||||
|
||||
node->unique_name = node->name;
|
||||
if (!is_flag_set(node->expr->flags, AST_FOREIGN)) {
|
||||
|
||||
@@ -230,7 +230,7 @@ CORE_Static void type_complete(Ast_Type *type);
|
||||
CORE_Static void
|
||||
type_struct_complete(Ast_Type *type, Ast_Decl *node) {
|
||||
assert(node->kind == AST_STRUCT || node->kind == AST_UNION);
|
||||
Scratch_Scope scratch(pctx->scratch);
|
||||
Scoped_Arena scratch(pctx->scratch);
|
||||
|
||||
if (node->kind == AST_STRUCT) {
|
||||
// First resolve and compute sizes of struct members
|
||||
|
||||
@@ -82,7 +82,7 @@ os_get_working_dir(Allocator *allocator) {
|
||||
|
||||
CORE_Static Array<OS_File_Info>
|
||||
os_list_dir(Scratch_Arena *scratch, Allocator *a, String dir, U32 flags = LIST_RECURSE_INTO_DIRS) {
|
||||
Scratch_Scope _scope(scratch);
|
||||
Scoped_Arena _scope(scratch);
|
||||
Array<String> dirs_to_read = {scratch};
|
||||
dirs_to_read.add(dir);
|
||||
|
||||
|
||||
@@ -159,7 +159,7 @@ os_does_file_exist(String path) {
|
||||
|
||||
CORE_Static Array<OS_File_Info>
|
||||
os_list_dir(Arena *scratch, Allocator *a, String dir, U32 flags = LIST_NO_FLAGS) {
|
||||
Scratch_Scope _scope(scratch);
|
||||
Scoped_Arena _scope(scratch);
|
||||
Array<String> dirs_to_read = {scratch};
|
||||
dirs_to_read.add(dir);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user