Module relative pathing seems to work, managed to get out of having to have the exe where the files are,

Got rid of scope names, now unique names uses scope ids, module folder is in top folder
This commit is contained in:
Krzosa Karol
2022-06-27 10:56:17 +02:00
parent 15d452cae3
commit b4f38caabe
13 changed files with 46 additions and 40 deletions

View File

@@ -715,29 +715,27 @@ add_implicit_import(Ast_Scope *scope, Ast_Scope *add){
enum{ GLOBAL_IMPLICIT_LOAD = 1 };
function Ast_File *
register_ast_file(Token *pos, Intern_String filename, Ast_Module *module, B32 global_implicit_load){
String absolute_path = string_fmt(pctx->perm, "%Q/%Q", module->base_folder, filename);
register_ast_file(Token *pos, String absolute_file_path, Ast_Module *module, B32 global_implicit_load){
Ast_File *file = 0;
For(pctx->files){
if(string_compare(it->absolute_path, absolute_path)){
if(string_compare(it->absolute_file_path, absolute_file_path)){
if(module == it->module){
log_info("%Q :: Returning registered file: %Q\n", module->name, absolute_path);
log_info("%Q :: Returning registered file: %Q\n", module->absolute_file_path, absolute_file_path);
file = it;
break;
}
print_token_context(it->pos);
compiler_error(pos, "This file is already loaded by module: %Q, try importing that module to get access to it", module->name);
compiler_error(pos, "This file is already loaded by module: %Q, try importing that module to get access to it", module->absolute_file_path);
}
}
if(!file){
log_info("%Q :: Registering file: %Q\n", module->name, filename);
log_info("%Q :: Registering file: %Q\n", module->absolute_file_path, absolute_file_path);
AST_NEW(File, FILE, 0, 0);
file = result;
file->absolute_path = absolute_path;
file->filename = filename;
file->absolute_file_path = absolute_file_path;
file->module = module;
file->parent_scope = 0;
file->file = file; // @warning: self referential!
@@ -745,6 +743,7 @@ register_ast_file(Token *pos, Intern_String filename, Ast_Module *module, B32 gl
file->implicit_imports = {pctx->heap};
file->pos = pos;
file->module->all_loaded_files.add(file);
file->scope_id = pctx->scope_ids++;
pctx->files.add(file);
}
@@ -758,7 +757,8 @@ register_ast_file(Token *pos, Intern_String filename, Ast_Module *module, B32 gl
function Ast_File *
parse_load(B32 global_implicit_load){
Token *file = token_expect(TK_StringLit);
Ast_File *result = register_ast_file(file, file->intern_val, pctx->currently_parsed_file->module, global_implicit_load);
String absolute_path = string_fmt(pctx->perm, "%Q/%Q", pctx->currently_parsed_file->module->absolute_base_folder, file->intern_val);
Ast_File *result = register_ast_file(file, absolute_path, pctx->currently_parsed_file->module, global_implicit_load);
return result;
}