Unify call and compound but have different kinds

This commit is contained in:
Krzosa Karol
2022-06-10 23:45:02 +02:00
parent 7365d6aa88
commit bcddf7f721
3 changed files with 27 additions and 72 deletions

41
ast.cpp
View File

@@ -18,7 +18,6 @@ enum Ast_Kind: U32{
AST_CALL,
AST_COMPOUND,
AST_COMPOUND_ITEM,
AST_TYPE,
AST_VAR,
AST_CONST,
@@ -82,27 +81,19 @@ struct Ast_Atom: Ast_Expr{
INLINE_VALUE_FIELDS;
};
struct Ast_Compound_Item: Ast_Expr{
Ast_Atom *name;
Ast_Expr *index;
Ast_Expr *item;
};
struct Ast_Compound: Ast_Expr{
Ast_Resolved_Type *type;
Ast_Expr *typespec;
Array<Ast_Compound_Item *> exprs;
};
struct Ast_Call_Item: Ast_Expr{
Ast_Atom *name;
Ast_Expr *item;
Ast_Expr *index;
};
struct Ast_Call: Ast_Expr{
Ast_Resolved_Type *type;
Ast_Expr *name;
union{
Ast_Expr *name;
Ast_Expr *typespec;
};
Array<Ast_Call_Item *> exprs;
Ast_Resolved_Type *type;
};
struct Ast_Unary: Ast_Expr{
@@ -297,23 +288,6 @@ ast_expr_binary(Ast_Expr *left, Ast_Expr *right, Token *op){
return result;
}
function Ast_Compound *
ast_compound(Token *pos, Ast_Expr *typespec, Array<Ast_Compound_Item *> exprs){
AST_NEW(Compound, COMPOUND, pos, AST_EXPR);
result->typespec = typespec;
result->exprs = exprs.tight_copy(pctx->perm);
return result;
}
function Ast_Compound_Item *
ast_compound_item(Token *pos, Ast_Atom *name, Ast_Expr *index, Ast_Expr *item){
AST_NEW(Compound_Item, COMPOUND_ITEM, pos, AST_EXPR);
result->name = name;
result->index = index;
result->item = item;
return result;
}
function Ast_Call *
ast_call(Token *pos, Ast_Expr *name, Array<Ast_Call_Item *> exprs){
AST_NEW(Call, CALL, pos, AST_EXPR);
@@ -323,10 +297,11 @@ ast_call(Token *pos, Ast_Expr *name, Array<Ast_Call_Item *> exprs){
}
function Ast_Call_Item *
ast_call_item(Token *pos, Ast_Atom *name, Ast_Expr *item){
ast_call_item(Token *pos, Ast_Atom *name, Ast_Expr *index, Ast_Expr *item){
AST_NEW(Call_Item, CALL_ITEM, pos, AST_EXPR);
result->name = name;
result->item = item;
result->index = index;
return result;
}