Removed resolved pointer from Ast_Typespec, it's accessed using a map now
This commit is contained in:
50
new_ast.cpp
50
new_ast.cpp
@@ -113,6 +113,7 @@ struct Ast{
|
||||
|
||||
Ast_Kind kind;
|
||||
// @todo?
|
||||
// bool is_atom: 1;
|
||||
// bool is_stmt: 1;
|
||||
// bool is_expr: 1;
|
||||
// bool is_decl: 1;
|
||||
@@ -200,7 +201,6 @@ struct Ast_Lambda : Ast_Expr {
|
||||
|
||||
struct Ast_Resolved_Type;
|
||||
struct Ast_Typespec:Ast{
|
||||
Ast_Resolved_Type *resolved_type;
|
||||
union{
|
||||
Ast_Typespec *base;
|
||||
Intern_String name;
|
||||
@@ -237,34 +237,34 @@ function Ast_Typespec *ast_typespec_name(Token *pos, Intern_String name);
|
||||
//-----------------------------------------------------------------------------
|
||||
#define AST_NEW(T,ikind,ipos) \
|
||||
Ast_##T *result = exp_alloc_type(pctx->perm, Ast_##T, AF_ZeroMemory);\
|
||||
result->kind = ikind; \
|
||||
result->kind = AST_##ikind; \
|
||||
result->pos = ipos; \
|
||||
result->id = ++pctx->unique_ids
|
||||
|
||||
function Ast_Atom *
|
||||
ast_expr_string(Token *pos, Intern_String string){
|
||||
AST_NEW(Atom, AST_STR, pos);
|
||||
AST_NEW(Atom, STR, pos);
|
||||
result->intern_val = string;
|
||||
return result;
|
||||
}
|
||||
|
||||
function Ast_Atom *
|
||||
ast_expr_identifier(Token *pos, Intern_String string){
|
||||
AST_NEW(Atom, AST_IDENT, pos);
|
||||
AST_NEW(Atom, IDENT, pos);
|
||||
result->intern_val = string;
|
||||
return result;
|
||||
}
|
||||
|
||||
function Ast_Atom *
|
||||
ast_expr_integer(Token *pos, S64 integer){
|
||||
AST_NEW(Atom, AST_INT, pos);
|
||||
AST_NEW(Atom, INT, pos);
|
||||
result->int_val = integer;
|
||||
return result;
|
||||
}
|
||||
|
||||
function Ast_Expr *
|
||||
ast_expr_binary(Ast_Expr *left, Ast_Expr *right, Token *op){
|
||||
AST_NEW(Binary, AST_BINARY, op);
|
||||
AST_NEW(Binary, BINARY, op);
|
||||
result->op = op->kind;
|
||||
result->left = left;
|
||||
result->right = right;
|
||||
@@ -273,7 +273,7 @@ ast_expr_binary(Ast_Expr *left, Ast_Expr *right, Token *op){
|
||||
|
||||
function Ast_Compound *
|
||||
ast_expr_compound(Token *pos, Ast_Typespec *typespec, Array<Ast_Compound_Item *> exprs){
|
||||
AST_NEW(Compound, AST_COMPOUND, pos);
|
||||
AST_NEW(Compound, COMPOUND, pos);
|
||||
result->typespec = typespec;
|
||||
result->exprs = exprs.tight_copy(pctx->perm);
|
||||
return result;
|
||||
@@ -281,7 +281,7 @@ ast_expr_compound(Token *pos, Ast_Typespec *typespec, Array<Ast_Compound_Item *>
|
||||
|
||||
function Ast_Compound_Item *
|
||||
ast_expr_compound_item(Token *pos, Ast_Expr *index, Ast_Atom *name, Ast_Expr *item){
|
||||
AST_NEW(Compound_Item, AST_COMPOUND_ITEM, pos);
|
||||
AST_NEW(Compound_Item, COMPOUND_ITEM, pos);
|
||||
result->name = name;
|
||||
result->index = index;
|
||||
result->item = item;
|
||||
@@ -290,7 +290,7 @@ ast_expr_compound_item(Token *pos, Ast_Expr *index, Ast_Atom *name, Ast_Expr *it
|
||||
|
||||
function Ast_Expr *
|
||||
ast_expr_cast(Token *pos, Ast_Expr *expr, Ast_Typespec *typespec){
|
||||
AST_NEW(Cast, AST_CAST, pos);
|
||||
AST_NEW(Cast, CAST, pos);
|
||||
result->expr = expr;
|
||||
result->typespec = typespec;
|
||||
return result;
|
||||
@@ -298,7 +298,7 @@ ast_expr_cast(Token *pos, Ast_Expr *expr, Ast_Typespec *typespec){
|
||||
|
||||
function Ast_Expr *
|
||||
ast_expr_unary(Token *pos, Token_Kind op, Ast_Expr *expr){
|
||||
AST_NEW(Unary, AST_UNARY, pos);
|
||||
AST_NEW(Unary, UNARY, pos);
|
||||
result->expr = expr;
|
||||
result->op = op;
|
||||
return result;
|
||||
@@ -306,7 +306,7 @@ ast_expr_unary(Token *pos, Token_Kind op, Ast_Expr *expr){
|
||||
|
||||
function Ast_Expr *
|
||||
ast_expr_index(Token *pos, Ast_Expr *expr, Ast_Expr *index){
|
||||
AST_NEW(Index, AST_INDEX, pos);
|
||||
AST_NEW(Index, INDEX, pos);
|
||||
result->expr = expr;
|
||||
result->index = index;
|
||||
return result;
|
||||
@@ -314,7 +314,7 @@ ast_expr_index(Token *pos, Ast_Expr *expr, Ast_Expr *index){
|
||||
|
||||
function Ast_Lambda *
|
||||
ast_lambda(Token *pos, Array<Ast_Lambda_Arg *> params, Ast_Typespec *ret, Ast_Block *block){
|
||||
AST_NEW(Lambda, AST_LAMBDA, pos);
|
||||
AST_NEW(Lambda, LAMBDA, pos);
|
||||
result->args = params.tight_copy(pctx->perm);
|
||||
result->ret = ret;
|
||||
result->block = block;
|
||||
@@ -326,13 +326,13 @@ ast_lambda(Token *pos, Array<Ast_Lambda_Arg *> params, Ast_Typespec *ret, Ast_Bl
|
||||
|
||||
function Ast_Expr *
|
||||
ast_expr_lambda_empty(Token *pos){
|
||||
AST_NEW(Expr, AST_LAMBDA, pos);
|
||||
AST_NEW(Expr, LAMBDA, pos);
|
||||
return result;
|
||||
}
|
||||
|
||||
function Ast_Lambda_Arg *
|
||||
ast_expr_lambda_arg(Token *pos, Intern_String name, Ast_Typespec *typespec){
|
||||
AST_NEW(Lambda_Arg, AST_LAMBDA_ARG, pos);
|
||||
AST_NEW(Lambda_Arg, LAMBDA_ARG, pos);
|
||||
result->name = name;
|
||||
result->typespec = typespec;
|
||||
return result;
|
||||
@@ -340,21 +340,21 @@ ast_expr_lambda_arg(Token *pos, Intern_String name, Ast_Typespec *typespec){
|
||||
|
||||
function Ast_Block *
|
||||
ast_block(Token *pos, Array<Ast *> stmts){
|
||||
AST_NEW(Block, AST_BLOCK, pos);
|
||||
AST_NEW(Block, BLOCK, pos);
|
||||
result->stmts = stmts.tight_copy(pctx->perm);
|
||||
return result;
|
||||
}
|
||||
|
||||
function Ast_If *
|
||||
ast_if(Token *pos, Array<Ast_If_Node *> ifs){
|
||||
AST_NEW(If, AST_IF, pos);
|
||||
AST_NEW(If, IF, pos);
|
||||
result->ifs = ifs.tight_copy(pctx->perm);
|
||||
return result;
|
||||
}
|
||||
|
||||
function Ast_If_Node *
|
||||
ast_if_node(Token *pos, Ast_Init *init, Ast_Expr *expr, Ast_Block *block){
|
||||
AST_NEW(If_Node, AST_IF_NODE, pos);
|
||||
AST_NEW(If_Node, IF_NODE, pos);
|
||||
result->block = block;
|
||||
result->expr = expr;
|
||||
result->init = init;
|
||||
@@ -363,7 +363,7 @@ ast_if_node(Token *pos, Ast_Init *init, Ast_Expr *expr, Ast_Block *block){
|
||||
|
||||
function Ast_Init *
|
||||
ast_init(Token *pos, Token_Kind op, Ast_Atom *ident, Ast_Expr *expr){
|
||||
AST_NEW(Init, AST_INIT, pos);
|
||||
AST_NEW(Init, INIT, pos);
|
||||
result->op = op;
|
||||
result->ident = ident;
|
||||
result->expr = expr;
|
||||
@@ -375,21 +375,21 @@ ast_init(Token *pos, Token_Kind op, Ast_Atom *ident, Ast_Expr *expr){
|
||||
//-----------------------------------------------------------------------------
|
||||
function Ast_Typespec *
|
||||
ast_typespec_name(Token *pos, Intern_String name){
|
||||
AST_NEW(Typespec, AST_TYPESPEC_IDENT, pos);
|
||||
AST_NEW(Typespec, TYPESPEC_IDENT, pos);
|
||||
result->name = name;
|
||||
return result;
|
||||
}
|
||||
|
||||
function Ast_Typespec *
|
||||
ast_typespec_pointer(Token *pos, Ast_Typespec *base){
|
||||
AST_NEW(Typespec, AST_TYPESPEC_POINTER, pos);
|
||||
AST_NEW(Typespec, TYPESPEC_POINTER, pos);
|
||||
result->base = base;
|
||||
return result;
|
||||
}
|
||||
|
||||
function Ast_Typespec *
|
||||
ast_typespec_array(Token *pos, Ast_Typespec *base, Ast_Expr *expr){
|
||||
AST_NEW(Typespec, AST_TYPESPEC_ARRAY, pos);
|
||||
AST_NEW(Typespec, TYPESPEC_ARRAY, pos);
|
||||
result->arr.base = base;
|
||||
result->arr.expr = expr;
|
||||
return result;
|
||||
@@ -397,7 +397,7 @@ ast_typespec_array(Token *pos, Ast_Typespec *base, Ast_Expr *expr){
|
||||
|
||||
function Ast_Typespec *
|
||||
ast_typespec_lambda(Token *pos, Ast_Lambda *lambda){
|
||||
AST_NEW(Typespec, AST_TYPESPEC_LAMBDA, pos);
|
||||
AST_NEW(Typespec, TYPESPEC_LAMBDA, pos);
|
||||
result->lambda = lambda;
|
||||
return result;
|
||||
}
|
||||
@@ -408,7 +408,7 @@ ast_typespec_lambda(Token *pos, Ast_Lambda *lambda){
|
||||
|
||||
function Ast_Var *
|
||||
ast_var(Token *pos, Ast_Typespec *typespec, Intern_String name, Ast_Expr *expr){
|
||||
AST_NEW(Var, AST_VAR, pos);
|
||||
AST_NEW(Var, VAR, pos);
|
||||
result->expr = expr;
|
||||
result->typespec = typespec;
|
||||
result->name = name;
|
||||
@@ -417,7 +417,7 @@ ast_var(Token *pos, Ast_Typespec *typespec, Intern_String name, Ast_Expr *expr){
|
||||
|
||||
function Ast_Const *
|
||||
ast_const(Token *pos, Intern_String name, Ast_Expr *expr){
|
||||
AST_NEW(Const, AST_CONST, pos);
|
||||
AST_NEW(Const, CONST, pos);
|
||||
result->expr = expr;
|
||||
result->name = name;
|
||||
return result;
|
||||
@@ -425,7 +425,7 @@ ast_const(Token *pos, Intern_String name, Ast_Expr *expr){
|
||||
|
||||
function Ast_Package *
|
||||
ast_package(Token *pos, String name, Array<Ast_Named *> decls){
|
||||
AST_NEW(Package, AST_PACKAGE, pos);
|
||||
AST_NEW(Package, PACKAGE, pos);
|
||||
result->decls = decls.tight_copy(pctx->perm);
|
||||
result->ordered = array_make<Ast_Named *>(pctx->perm, decls.len);
|
||||
result->name = intern_string(&pctx->interns, name);
|
||||
|
||||
Reference in New Issue
Block a user