diff --git a/ast.cpp b/ast.cpp index fa4792e..9919840 100644 --- a/ast.cpp +++ b/ast.cpp @@ -245,6 +245,7 @@ struct Ast_Module: Ast_Scope{ }; struct Ast_File: Ast_Scope{ + String absolute_path; Intern_String filename; String filecontent; }; diff --git a/compiler.h b/compiler.h index a4b4fae..5286ec3 100644 --- a/compiler.h +++ b/compiler.h @@ -200,6 +200,10 @@ struct Parse_Ctx:Lexer{ Ast_Scope *currently_parsed_scope; Ast_File *currently_parsed_file; + Array module_folders; + String module_folder; + String exe_folder; + S64 indent; String_Builder gen; String_Builder helper_builder; @@ -261,6 +265,16 @@ parse_init(Parse_Ctx *ctx, Allocator *perm_allocator, Allocator *heap_allocator) 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->module_folders = {ctx->heap}; + String main_module = string_fmt(ctx->perm, "%Q/modules", ctx->exe_folder); + ctx->module_folders.add(main_module); + + + + } \ No newline at end of file diff --git a/main.cpp b/main.cpp index 4d9f6d4..5b2cc7f 100644 --- a/main.cpp +++ b/main.cpp @@ -221,12 +221,6 @@ int main(int argument_count, char **arguments){ test_intern_table(); test_bucket_arrays(); - Scratch scratch; - String a = os_get_working_dir(scratch); - String b = os_get_exe_dir(scratch); - Array files = os_list_dir(scratch, ".."_s, LIST_RECURSE_INTO_DIRS); - - emit_line_directives = true; String program_name = "main.kl"_s; if(argument_count > 1){ diff --git a/parsing.cpp b/parsing.cpp index 85eda44..5b3c9e7 100644 --- a/parsing.cpp +++ b/parsing.cpp @@ -719,10 +719,12 @@ enum{ function Ast_File * register_ast_file(Token *pos, Intern_String filename, Ast_Module *module, B32 global_implicit_load){ Ast_File *file = 0; + String absolute_path = os_get_absolute_path(pctx->perm, filename.s); + For(pctx->files){ - if(it->filename == filename){ + if(string_compare(it->absolute_path, absolute_path)){ if(module == it->module){ - log_info("%Q :: Returning registered file: %Q\n", module->name, filename); + log_info("%Q :: Returning registered file: %Q\n", module->name, absolute_path); file = it; break; } @@ -735,16 +737,17 @@ register_ast_file(Token *pos, Intern_String filename, Ast_Module *module, B32 gl if(!file){ log_info("%Q :: Registering file: %Q\n", module->name, filename); AST_NEW(File, FILE, 0, 0); - file = result; - file->filename = filename; - file->module = module; - file->parent_scope = 0; - file->file = file; // @warning: self referential! - file->decls = {pctx->heap}; + file = result; + file->absolute_path = absolute_path; + file->filename = filename; + file->module = module; + file->parent_scope = 0; + file->file = file; // @warning: self referential! + file->decls = {pctx->heap}; file->implicit_imports = {pctx->heap}; + file->pos = pos; file->module->all_loaded_files.add(file); pctx->files.add(file); - file->pos = pos; } if(global_implicit_load) {