New module scheme

This commit is contained in:
Krzosa Karol
2022-06-13 10:49:10 +02:00
parent cdaf85438e
commit b0553c38cf
12 changed files with 247 additions and 165 deletions

View File

@@ -582,6 +582,34 @@ parse_enum(Token *pos){
return result;
}
function Ast_File *
register_ast_file(Intern_String filename, Ast_Module *module, B32 global_implicit_load){
Ast_File *file = 0;
For(module->files){
if(it->filename == filename){
file = it;
break;
}
}
if(!file){
file = exp_alloc_type(pctx->perm, Ast_File, AF_ZeroMemory);
file->filename = filename;
file->module = module;
file->module->files.add(file);
}
if(global_implicit_load) file->global_implicit_load = true;
return file;
}
function Ast_File *
parse_load(B32 global_implicit_load){
Token *file = token_expect(TK_StringLit);
Ast_File *result = register_ast_file(file->intern_val, pctx->currently_parsed_file->module, global_implicit_load);
return result;
}
/*
Needs peeking only because I didn't want to duplicate code
for parsing statements and it makes code nicer.
@@ -614,6 +642,11 @@ parse_decl(B32 is_global){
result = parse_enum(tname);
}
else if(token_match_pound(pctx->intern("load"_s))){
Ast_File *file = parse_load(false);
result = ast_file_namespace(tname, file, tname->intern_val);
}
else{
Ast_Expr *expr = parse_expr();
result = ast_const(tname, tname->intern_val, expr);