New concept of AST_MODULE, Ast_File and Ast_Module are now both scopes.

Concept of loading and importing.
This commit is contained in:
Krzosa Karol
2022-06-13 13:39:31 +02:00
parent 8bd5e9638f
commit bcd825c154
8 changed files with 132 additions and 75 deletions

39
ast.cpp
View File

@@ -6,7 +6,10 @@ enum Ast_Kind: U32{
AST_NONE,
AST_FILE_NAMESPACE,
AST_MODULE_NAMESPACE,
AST_MODULE,
AST_FILE,
AST_SCOPE,
AST_VALUE,
AST_CAST,
@@ -196,11 +199,28 @@ enum Ast_Decl_State{
DECL_RESOLVING,
};
struct Ast_Decl;
struct Ast_Scope: Ast{
Array<Ast_Decl *> decls;
Array<Ast *> stmts;
Ast_File *file;
Array<Ast_Module *> implicit_imports;
Array<Ast_File *> implicit_loads;
Array<Ast_Decl *> decls;
Array<Ast *> stmts;
Ast_File *file; // Null for module scope, file scope
};
struct Ast_Module: Ast_Scope{
Intern_String name;
Array<Ast_File *> all_loaded_files;
};
struct Ast_File: Ast_Scope{
Intern_String filename;
Ast_Module *module;
B32 global_implicit_load;
String filecontent;
Intern_String name;
};
struct Ast_Decl: Ast{
@@ -483,8 +503,15 @@ ast_decl_scope(Token *pos, Allocator *allocator, Ast_File *file){
function Ast_Decl *
ast_file_namespace(Token *pos, Ast_File *file, Intern_String name){
AST_NEW(Decl, FILE_NAMESPACE, pos, AST_DECL);
result->kind = AST_FILE_NAMESPACE;
result->scope = file->scope;
result->scope = file;
result->name = name;
return result;
}
function Ast_Decl *
ast_module_namespace(Token *pos, Ast_Module *module, Intern_String name){
AST_NEW(Decl, MODULE_NAMESPACE, pos, AST_DECL);
result->scope = module;
result->name = name;
return result;
}