Fix adding loads multiple times
This commit is contained in:
5
ast.cpp
5
ast.cpp
@@ -200,6 +200,7 @@ enum Ast_Decl_State{
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Ast_Scope: Ast{
|
struct Ast_Scope: Ast{
|
||||||
|
Intern_String name; // for debugging
|
||||||
Array<Ast_Scope *> implicit_imports;
|
Array<Ast_Scope *> implicit_imports;
|
||||||
Array<Ast_Decl *> decls;
|
Array<Ast_Decl *> decls;
|
||||||
Array<Ast *> stmts;
|
Array<Ast *> stmts;
|
||||||
@@ -210,16 +211,12 @@ struct Ast_Scope: Ast{
|
|||||||
|
|
||||||
|
|
||||||
struct Ast_Module: Ast_Scope{
|
struct Ast_Module: Ast_Scope{
|
||||||
Intern_String name;
|
|
||||||
Array<Ast_File *> all_loaded_files;
|
Array<Ast_File *> all_loaded_files;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Ast_File: Ast_Scope{
|
struct Ast_File: Ast_Scope{
|
||||||
Intern_String filename;
|
Intern_String filename;
|
||||||
|
|
||||||
B32 global_implicit_load;
|
|
||||||
String filecontent;
|
String filecontent;
|
||||||
Intern_String name;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Ast_Decl: Ast{
|
struct Ast_Decl: Ast{
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
lambdas :: #load "lambdas.kl"
|
lambdas :: #load "lambdas.kl"
|
||||||
Memory :: #load "enums.kl"
|
Memory :: #load "enums.kl"
|
||||||
|
#load "lambdas.kl"
|
||||||
|
#load "lambdas.kl"
|
||||||
|
#import "order1.kl"
|
||||||
#import "order1.kl"
|
#import "order1.kl"
|
||||||
order :: #import "order1.kl"
|
order :: #import "order1.kl"
|
||||||
|
|
||||||
|
|||||||
23
parsing.cpp
23
parsing.cpp
@@ -583,6 +583,20 @@ parse_enum(Token *pos){
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function void
|
||||||
|
add_implicit_import(Ast_Scope *scope, Ast_Scope *add){
|
||||||
|
B32 found = false;
|
||||||
|
For(scope->implicit_imports){
|
||||||
|
if(it == add){
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!found){
|
||||||
|
scope->implicit_imports.add(add);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function Ast_File *
|
function Ast_File *
|
||||||
register_ast_file(Intern_String filename, Ast_Module *module, B32 global_implicit_load){
|
register_ast_file(Intern_String filename, Ast_Module *module, B32 global_implicit_load){
|
||||||
Ast_File *file = 0;
|
Ast_File *file = 0;
|
||||||
@@ -593,8 +607,8 @@ register_ast_file(Intern_String filename, Ast_Module *module, B32 global_implici
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!file){
|
if(!file){
|
||||||
file = exp_alloc_type(pctx->perm, Ast_File, AF_ZeroMemory);
|
AST_NEW(File, FILE, 0, 0);
|
||||||
file->kind = AST_FILE;
|
file = result;
|
||||||
file->filename = filename;
|
file->filename = filename;
|
||||||
file->module = module;
|
file->module = module;
|
||||||
file->file = file; // @warning: self referential!
|
file->file = file; // @warning: self referential!
|
||||||
@@ -604,8 +618,7 @@ register_ast_file(Intern_String filename, Ast_Module *module, B32 global_implici
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(global_implicit_load) {
|
if(global_implicit_load) {
|
||||||
file->global_implicit_load = true;
|
add_implicit_import(module, file);
|
||||||
module->implicit_imports.add(file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return file;
|
return file;
|
||||||
@@ -624,7 +637,7 @@ parse_import(B32 global_implicit_import){
|
|||||||
Token *file = token_expect(TK_StringLit);
|
Token *file = token_expect(TK_StringLit);
|
||||||
Ast_Module *result = add_module(file->intern_val);
|
Ast_Module *result = add_module(file->intern_val);
|
||||||
if(global_implicit_import){
|
if(global_implicit_import){
|
||||||
pctx->currently_parsed_file->module->implicit_imports.add(result);
|
add_implicit_import(pctx->currently_parsed_file->module, result);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user