More order independent globals

This commit is contained in:
Krzosa Karol
2022-05-29 22:07:08 +02:00
parent 2ad3131dba
commit 4434ad1fb5
6 changed files with 39 additions and 11 deletions

View File

@@ -211,9 +211,11 @@ struct Ast_Array: Ast_Expr{
Ast_Expr *expr;
};
struct Ast_Resolved_Type;
struct Ast_Struct: Ast_Expr{
// Required to be Ast_Struct or Ast_Var or Ast_Const
Array<Ast *> members;
Ast_Resolved_Type *type;
};
struct Ast_Named:Ast{
@@ -469,11 +471,20 @@ ast_package(Token *pos, String name, Array<Ast_Named *> decls){
// Utillities
//-----------------------------------------------------------------------------
function Ast_Struct *
const_get_struct(Ast *ast){
const_try_getting_struct(Ast *ast){
assert(ast->kind == AST_CONST);
Ast_Const *constant = (Ast_Const *)ast;
assert(constant->value->kind == AST_STRUCT);
return (Ast_Struct *)constant->value;
if(constant->value->kind == AST_STRUCT){
return (Ast_Struct *)constant->value;
}
return 0;
}
function Ast_Struct *
const_get_struct(Ast *ast){
auto result = const_try_getting_struct(ast);
assert(result);
return result;
}
function Intern_String
@@ -482,3 +493,13 @@ ast_get_name(Ast *ast){
auto constant = (Ast_Named *)ast;
return constant->name;
}
function B32
ast_is_struct(Ast *ast){
if(ast->kind == AST_CONST){
auto a = (Ast_Const *)ast;
B32 result = a->agg->kind == AST_STRUCT;
return result;
}
return false;
}