Restructuring

This commit is contained in:
Krzosa Karol
2022-09-29 12:41:04 +02:00
parent 5f11a11f0f
commit cbf6ca8480
5 changed files with 379 additions and 365 deletions

View File

@@ -212,72 +212,9 @@ struct Parse_Ctx:Lexer{
String_Builder gen;
String_Builder helper_builder;
};
thread_local Parse_Ctx *pctx;
global B32 emit_line_directives;
function void init_type();
//-----------------------------------------------------------------------------
// Constructors
//-----------------------------------------------------------------------------
thread_local Parse_Ctx *pctx;
function void
lex_init(Allocator *token_string_arena, Allocator *map_allocator, Lexer *l){
l->arena = token_string_arena;
l->tokens = array_make<Token>(token_string_arena, 1024*2);
l->interns= intern_table_make(token_string_arena, map_allocator, 1024);
keyword_struct= l->intern("struct"_s);
keyword_union = l->intern("union"_s);
keyword_true = l->intern("true"_s);
keyword_default = l->intern("default"_s);
keyword_break = l->intern("break"_s);
keyword_false = l->intern("false"_s);
keyword_return = l->intern("return"_s);
keyword_switch = l->intern("switch"_s);
keyword_assert = l->intern("Assert"_s);
keyword_if = l->intern("if"_s);
keyword_elif = l->intern("elif"_s);
keyword_pass = l->intern("pass"_s);
keyword_else = l->intern("else"_s);
keyword_for = l->intern("for"_s);
keyword_enum = intern_string(&l->interns, "enum"_s);
l->interns.first_keyword = keyword_struct.str;
l->interns.last_keyword = keyword_enum.str;
intern_sizeof = l->intern("SizeOf"_s);
intern_lengthof = l->intern("Length"_s);
intern_alignof = l->intern("AlignOf"_s);
intern_foreign = intern_string(&l->interns, "foreign"_s);
intern_strict = intern_string(&l->interns, "strict"_s);
intern_void = intern_string(&l->interns, "void"_s);
intern_flag = intern_string(&l->interns, "flag"_s);
intern_it = intern_string(&l->interns, "it"_s);
}
function void
parse_init(Parse_Ctx *ctx, Allocator *perm_allocator, Allocator *heap_allocator){
pctx = ctx;
ctx->perm = perm_allocator;
ctx->heap = heap_allocator;
ctx->gen = {ctx->heap};
ctx->ordered_decls = {ctx->heap};
ctx->type_map = {ctx->heap};
ctx->modules = {ctx->heap};
ctx->all_types = {ctx->heap};
ctx->helper_builder= {ctx->heap};
ctx->files = {ctx->heap};
ctx->scope_ids = 1;
bigint_allocator = ctx->perm;
arena_init(&ctx->stage_arena, "Compiler stage arena"_s);
lex_init(ctx->perm, ctx->heap, ctx);
init_type();
// Init paths
ctx->exe_folder = os_get_exe_dir(ctx->perm);
ctx->working_folder = os_get_working_dir(ctx->perm);
ctx->module_folders = {ctx->heap};
String main_module = string_fmt(ctx->perm, "%Q/modules", ctx->exe_folder);
ctx->module_folders.add(main_module);
}
function void lex_init(Allocator *token_string_arena, Allocator *map_allocator, Lexer *l);
function String compile_to_c_code();