New concept of AST_MODULE, Ast_File and Ast_Module are now both scopes.
Concept of loading and importing.
This commit is contained in:
31
parsing.cpp
31
parsing.cpp
@@ -585,7 +585,7 @@ parse_enum(Token *pos){
|
||||
function Ast_File *
|
||||
register_ast_file(Intern_String filename, Ast_Module *module, B32 global_implicit_load){
|
||||
Ast_File *file = 0;
|
||||
For(module->files){
|
||||
For(module->all_loaded_files){
|
||||
if(it->filename == filename){
|
||||
file = it;
|
||||
break;
|
||||
@@ -593,13 +593,20 @@ register_ast_file(Intern_String filename, Ast_Module *module, B32 global_implici
|
||||
}
|
||||
if(!file){
|
||||
file = exp_alloc_type(pctx->perm, Ast_File, AF_ZeroMemory);
|
||||
file->kind = AST_FILE;
|
||||
file->filename = filename;
|
||||
file->module = module;
|
||||
file->scope = ast_decl_scope(0, pctx->heap, file);
|
||||
file->module->files.add(file);
|
||||
file->file = file; // @warning: self referential!
|
||||
file->decls = {pctx->heap};
|
||||
file->implicit_loads = {pctx->heap};
|
||||
file->implicit_imports = {pctx->heap};
|
||||
file->module->all_loaded_files.add(file);
|
||||
}
|
||||
|
||||
if(global_implicit_load) file->global_implicit_load = true;
|
||||
if(global_implicit_load) {
|
||||
file->global_implicit_load = true;
|
||||
module->implicit_loads.add(file);
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
@@ -611,6 +618,17 @@ parse_load(B32 global_implicit_load){
|
||||
return result;
|
||||
}
|
||||
|
||||
function Ast_Module *add_module(Intern_String filename);
|
||||
function Ast_Module *
|
||||
parse_import(B32 global_implicit_import){
|
||||
Token *file = token_expect(TK_StringLit);
|
||||
Ast_Module *result = add_module(file->intern_val);
|
||||
if(global_implicit_import){
|
||||
pctx->currently_parsed_file->module->implicit_imports.add(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
Needs peeking only because I didn't want to duplicate code
|
||||
for parsing statements and it makes code nicer.
|
||||
@@ -648,6 +666,11 @@ parse_decl(B32 is_global){
|
||||
result = ast_file_namespace(tname, file, tname->intern_val);
|
||||
}
|
||||
|
||||
else if(token_match_pound(pctx->intern("import"_s))){
|
||||
Ast_Module *module = parse_import(false);
|
||||
result = ast_module_namespace(tname, module, tname->intern_val);
|
||||
}
|
||||
|
||||
else{
|
||||
Ast_Expr *expr = parse_expr();
|
||||
result = ast_const(tname, tname->intern_val, expr);
|
||||
|
||||
Reference in New Issue
Block a user