From d5179bb5962e4f715009610be1cf47c34d4f794c Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Sat, 31 Dec 2022 21:05:13 +0100 Subject: [PATCH] Small allocator changes, fix crash --- core_compiler.cpp | 19 +++++++++++-------- core_compiler.h | 5 ++++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/core_compiler.cpp b/core_compiler.cpp index 8fc314c..f079e52 100644 --- a/core_compiler.cpp +++ b/core_compiler.cpp @@ -1,19 +1,19 @@ CORE_Static void -core_init_compiler(Parse_Ctx *ctx, Allocator *allocator) { +core_init_compiler(Parse_Ctx *ctx, Arena *perm, Allocator *heap) { ctx->init_ctx_time_begin = os_time(); pctx = ctx; - Allocator *heap_allocator = allocator; - ctx->perm = (Arena *)allocator; - ctx->type_map = map_make(heap_allocator, 2048); + ctx->perm = perm; + ctx->heap = heap; + ctx->type_map = map_make(heap, 2048); ctx->gen = {ctx->perm}; ctx->helper_builder = {ctx->perm}; ctx->scope_ids = 1; bigint_allocator = ctx->perm; arena_init(&ctx->stage_arena, "Compiler stage arena"_s); - ctx->tokens = array_make(heap_allocator, 4096 * 4); - ctx->interns = intern_table_make(ctx->perm, heap_allocator, 2048); + ctx->tokens = array_make(heap, 4096 * 4); + ctx->interns = intern_table_make(ctx->perm, heap, 2048); /*#import meta for i in meta.keywords: @@ -96,7 +96,9 @@ core_init_compiler(Parse_Ctx *ctx, Allocator *allocator) { CORE_Static void core_bootstrap_compiler(Allocator *allocator) { Parse_Ctx *ctx = allocate_struct(allocator, Parse_Ctx); - core_init_compiler(ctx, allocator); + + assert((uintptr_t)allocator->allocate == (uintptr_t)arena_push_size); + core_init_compiler(ctx, (Arena *)allocator, allocator); } CORE_Static void @@ -212,8 +214,9 @@ resolve_everything_in_module(Ast_Module *module) { CORE_Static String compile_file_to_string(Arena *arena, String filename) { - pctx->total_time = os_time(); + F64 total_time = os_time(); core_bootstrap_compiler(arena); + pctx->total_time = total_time; { Ast_Module *module = add_module(0, pctx->intern("Language.core"_s)); { diff --git a/core_compiler.h b/core_compiler.h index b46192a..06259ec 100644 --- a/core_compiler.h +++ b/core_compiler.h @@ -22,8 +22,11 @@ struct Lex_Stream{ struct Parse_Ctx{ Arena *perm; // Stores: AST, tokens, interns + Allocator *heap; + Arena stage_arena; - Arena scratch; + Arena _scratch; + Arena *scratch; // Lexer stuff Lex_Stream stream;