New module scheme
This commit is contained in:
35
ast.cpp
35
ast.cpp
@@ -5,7 +5,7 @@
|
||||
enum Ast_Kind: U32{
|
||||
AST_NONE,
|
||||
|
||||
AST_PACKAGE,
|
||||
AST_FILE_NAMESPACE,
|
||||
|
||||
AST_SCOPE,
|
||||
AST_VALUE,
|
||||
@@ -48,7 +48,7 @@ enum{
|
||||
AST_ATOM = bit_flag(7),
|
||||
AST_FOREIGN = bit_flag(8),
|
||||
AST_DECL = bit_flag(9),
|
||||
AST_PACKAGE_LEVEL = bit_flag(10),
|
||||
AST_FILE_NAMESPACE_LEVEL = bit_flag(10),
|
||||
AST_FLAG = bit_flag(11),
|
||||
};
|
||||
|
||||
@@ -104,6 +104,10 @@ struct Ast_Unary: Ast_Expr{
|
||||
U64 padding[2]; // For folding constants into atoms
|
||||
};
|
||||
|
||||
struct Ast_Load: Ast{
|
||||
String string;
|
||||
};
|
||||
|
||||
struct Ast_Cast: Ast_Expr{
|
||||
Ast_Expr *expr;
|
||||
Ast_Expr *typespec;
|
||||
@@ -196,6 +200,7 @@ struct Ast_Decl;
|
||||
struct Ast_Scope: Ast{
|
||||
Array<Ast_Decl *> decls;
|
||||
Array<Ast *> stmts;
|
||||
Ast_File *file;
|
||||
};
|
||||
|
||||
struct Ast_Decl: Ast{
|
||||
@@ -213,16 +218,10 @@ struct Ast_Decl: Ast{
|
||||
INLINE_VALUE_FIELDS;
|
||||
};
|
||||
|
||||
struct Ast_File{
|
||||
String filename;
|
||||
String filecontent;
|
||||
|
||||
Intern_String name;
|
||||
Array<Ast_Decl *> decls;
|
||||
struct Ast_File_Namespace : Ast_Decl{
|
||||
Ast_File *file;
|
||||
};
|
||||
|
||||
struct Ast_Package : Ast_Decl{};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// AST Constructors beginning with expressions
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -399,6 +398,8 @@ function Ast_Scope *
|
||||
begin_decl_scope(Allocator *scratch, Token *pos){
|
||||
AST_NEW(Scope, SCOPE, pos, AST_DECL);
|
||||
result->decls = {scratch};
|
||||
result->file = pctx->currently_parsed_file;
|
||||
assert(result->file);
|
||||
pctx->currently_parsed_scope = result;
|
||||
return result;
|
||||
}
|
||||
@@ -414,6 +415,8 @@ begin_stmt_scope(Allocator *scratch, Token *pos){
|
||||
AST_NEW(Scope, SCOPE, pos, AST_STMT);
|
||||
result->stmts = {scratch};
|
||||
result->decls = {pctx->heap};
|
||||
result->file = pctx->currently_parsed_file;
|
||||
assert(result->file);
|
||||
pctx->currently_parsed_scope = result;
|
||||
return result;
|
||||
}
|
||||
@@ -477,14 +480,16 @@ function Ast_Scope *
|
||||
ast_decl_scope(Token *pos, Allocator *allocator){
|
||||
AST_NEW(Scope, SCOPE, pos, AST_DECL);
|
||||
result->decls = {allocator};
|
||||
result->file = pctx->currently_parsed_file;
|
||||
assert(result->file);
|
||||
return result;
|
||||
}
|
||||
|
||||
function Ast_Package *
|
||||
ast_package(Token *pos, Allocator *allocator, Intern_String name){
|
||||
AST_NEW(Package, PACKAGE, pos, 0);
|
||||
result->kind = AST_PACKAGE;
|
||||
result->scope = ast_decl_scope(pos, allocator);
|
||||
function Ast_File_Namespace *
|
||||
ast_file_namespace(Token *pos, Ast_File *file, Intern_String name){
|
||||
AST_NEW(File_Namespace, FILE_NAMESPACE, pos, 0);
|
||||
result->kind = AST_FILE_NAMESPACE;
|
||||
result->file = file;
|
||||
result->name = name;
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user