Add if statements

This commit is contained in:
Krzosa Karol
2022-05-26 18:13:37 +02:00
parent 3cd79040bc
commit 3d9a38494c
7 changed files with 134 additions and 15 deletions

View File

@@ -89,6 +89,8 @@ enum Ast_Kind{
AST_COMPOUND_ITEM,
AST_COMPOUND,
AST_IF,
AST_IF_NODE,
AST_RETURN,
AST_BLOCK,
AST_LAMBDA,
@@ -104,8 +106,12 @@ enum Ast_Kind{
struct Ast{
U64 id;
Ast_Kind kind;
Token *pos;
Ast_Kind kind;
bool is_stmt: 1;
bool is_expr: 1;
bool is_decl: 1;
};
struct Ast_Resolved_Type;
@@ -161,6 +167,15 @@ struct Ast_Return: Ast{
Ast_Expr *expr;
};
struct Ast_If_Node: Ast{
Ast_Expr *expr ;
Ast_Block *block;
};
struct Ast_If: Ast{
Array<Ast_If_Node *> ifs;
};
struct Ast_Lambda_Arg: Ast_Expr{
Intern_String name;
Ast_Typespec *typespec;
@@ -315,6 +330,21 @@ ast_block(Token *pos, Array<Ast *> stmts){
return result;
}
function Ast_If *
ast_if(Token *pos, Array<Ast_If_Node *> ifs){
AST_NEW(If, AST_IF, pos);
result->ifs = ifs.tight_copy(pctx->perm);
return result;
}
function Ast_If_Node *
ast_if_node(Token *pos, Ast_Expr *expr, Ast_Block *block){
AST_NEW(If_Node, AST_IF_NODE, pos);
result->block = block;
result->expr = expr;
return result;
}
//-----------------------------------------------------------------------------
// Typespecs
//-----------------------------------------------------------------------------