diff --git a/base_arena.cpp b/base_arena.cpp index 9bb4faa..1133cbe 100644 --- a/base_arena.cpp +++ b/base_arena.cpp @@ -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; } }; diff --git a/base_string.cpp b/base_string.cpp index 02d3df6..6dc723c 100644 --- a/base_string.cpp +++ b/base_string.cpp @@ -459,7 +459,7 @@ struct String_Replace { CORE_Static String string_replace(Arena *scratch, Allocator *allocator, String string, Array pairs) { - Scratch_Scope _scope(scratch); + Scoped_Arena _scope(scratch); String_Builder builder = {scratch}; for (S64 i = 0; i < string.len; i++) { For(pairs) { diff --git a/core_codegen_c_language.cpp b/core_codegen_c_language.cpp index ae3cb47..bd06838 100644 --- a/core_codegen_c_language.cpp +++ b/core_codegen_c_language.cpp @@ -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); diff --git a/core_compiler.cpp b/core_compiler.cpp index 207cfeb..9d42cc1 100644 --- a/core_compiler.cpp +++ b/core_compiler.cpp @@ -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 = {}; diff --git a/core_lexing.cpp b/core_lexing.cpp index 576e099..a37efb1 100644 --- a/core_lexing.cpp +++ b/core_lexing.cpp @@ -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); diff --git a/core_main.cpp b/core_main.cpp index 2f30f5d..ac2a307 100644 --- a/core_main.cpp +++ b/core_main.cpp @@ -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 examples = os_list_dir(&scratch, &scratch, "examples"_s); Array tests = os_list_dir(&scratch, &scratch, "tests"_s); For(examples) { diff --git a/core_parsing.cpp b/core_parsing.cpp index f1f0c82..d89da6b 100644 --- a/core_parsing.cpp +++ b/core_parsing.cpp @@ -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 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 params = parse_parameter_list(scratch.arena); Array 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 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 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); diff --git a/core_polymorph.cpp b/core_polymorph.cpp index e21f23b..f191e93 100644 --- a/core_polymorph.cpp +++ b/core_polymorph.cpp @@ -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; diff --git a/core_typechecking.cpp b/core_typechecking.cpp index 018936a..af00248 100644 --- a/core_typechecking.cpp +++ b/core_typechecking.cpp @@ -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 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 args = {scratch.arena}; Array 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 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)) { diff --git a/core_types.cpp b/core_types.cpp index 35b6908..1d9081d 100644 --- a/core_types.cpp +++ b/core_types.cpp @@ -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 diff --git a/os_linux.cpp b/os_linux.cpp index 68a0aad..80b94f6 100644 --- a/os_linux.cpp +++ b/os_linux.cpp @@ -82,7 +82,7 @@ os_get_working_dir(Allocator *allocator) { CORE_Static Array 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 dirs_to_read = {scratch}; dirs_to_read.add(dir); diff --git a/os_windows.cpp b/os_windows.cpp index 9f6412a..b37f3be 100644 --- a/os_windows.cpp +++ b/os_windows.cpp @@ -159,7 +159,7 @@ os_does_file_exist(String path) { CORE_Static Array os_list_dir(Arena *scratch, Allocator *a, String dir, U32 flags = LIST_NO_FLAGS) { - Scratch_Scope _scope(scratch); + Scoped_Arena _scope(scratch); Array dirs_to_read = {scratch}; dirs_to_read.add(dir);