CORE_Static

This commit is contained in:
Krzosa Karol
2022-10-11 13:04:35 +02:00
parent e37bf8b1bc
commit 2c53693754
21 changed files with 446 additions and 447 deletions

View File

@@ -302,7 +302,7 @@ struct Ast_Decl: Ast{
result->di = ++pctx->unique_ids
#define ast_new(T,kind,pos,flags) (T *)_ast_new(sizeof(T), kind, pos, flags)
function Ast *
CORE_Static Ast *
_ast_new(size_t size, Ast_Kind kind, Token *pos, Ast_Flag flags = 0){
Ast *result = (Ast *)arena_push_size(pctx->perm, size, AF_ZeroMemory);
result->flags = flags;
@@ -313,7 +313,7 @@ _ast_new(size_t size, Ast_Kind kind, Token *pos, Ast_Flag flags = 0){
return result;
}
function Ast_Atom *
CORE_Static Ast_Atom *
ast_str(Token *pos, Intern_String string){
AST_NEW(Atom, VALUE, pos, AST_EXPR | AST_ATOM);
result->type = untyped_string;
@@ -321,14 +321,14 @@ ast_str(Token *pos, Intern_String string){
return result;
}
function Ast_Atom *
CORE_Static Ast_Atom *
ast_ident(Token *pos, Intern_String string){
AST_NEW(Atom, IDENT, pos, AST_EXPR | AST_ATOM);
result->intern_val = string;
return result;
}
function Ast_Atom *
CORE_Static Ast_Atom *
ast_bool(Token *pos, B32 bool_val){
AST_NEW(Atom, VALUE, pos, AST_EXPR | AST_ATOM);
result->bool_val = bool_val;
@@ -336,7 +336,7 @@ ast_bool(Token *pos, B32 bool_val){
return result;
}
function Ast_Atom *
CORE_Static Ast_Atom *
ast_float(Token *pos, F64 value){
AST_NEW(Atom, VALUE, pos, AST_EXPR | AST_ATOM);
result->type = untyped_float;
@@ -344,7 +344,7 @@ ast_float(Token *pos, F64 value){
return result;
}
function Ast_Atom *
CORE_Static Ast_Atom *
ast_int(Token *pos, BigInt val){
AST_NEW(Atom, VALUE, pos, AST_EXPR | AST_ATOM);
result->type = untyped_int;
@@ -352,12 +352,12 @@ ast_int(Token *pos, BigInt val){
return result;
}
function Ast_Atom *
CORE_Static Ast_Atom *
ast_int(Token *pos, U64 value){
return ast_int(pos, bigint_u64(value));
}
function Ast_Expr *
CORE_Static Ast_Expr *
ast_expr_binary(Ast_Expr *left, Ast_Expr *right, Token *op){
AST_NEW(Binary, BINARY, op, AST_EXPR);
result->op = op->kind;
@@ -366,7 +366,7 @@ ast_expr_binary(Ast_Expr *left, Ast_Expr *right, Token *op){
return result;
}
function Ast_Call *
CORE_Static Ast_Call *
ast_call(Token *pos, Ast_Expr *name, Array<Ast_Call_Item *> exprs){
// name here specifies also typespec for compound expressions !
AST_NEW(Call, CALL, pos, AST_EXPR);
@@ -375,7 +375,7 @@ ast_call(Token *pos, Ast_Expr *name, Array<Ast_Call_Item *> exprs){
return result;
}
function Ast_Call_Item *
CORE_Static Ast_Call_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;
@@ -384,7 +384,7 @@ ast_call_item(Token *pos, Ast_Atom *name, Ast_Expr *index, Ast_Expr *item){
return result;
}
function Ast_Expr *
CORE_Static Ast_Expr *
ast_expr_unary(Token *pos, Token_Kind op, Ast_Expr *expr){
AST_NEW(Unary, UNARY, pos, AST_EXPR);
result->flags = AST_EXPR;
@@ -393,7 +393,7 @@ ast_expr_unary(Token *pos, Token_Kind op, Ast_Expr *expr){
return result;
}
function Ast_Expr *
CORE_Static Ast_Expr *
ast_expr_index(Token *pos, Ast_Expr *expr, Ast_Expr *index){
AST_NEW(Index, INDEX, pos, AST_EXPR);
result->flags = AST_EXPR;
@@ -402,7 +402,7 @@ ast_expr_index(Token *pos, Ast_Expr *expr, Ast_Expr *index){
return result;
}
function Ast_Lambda *
CORE_Static Ast_Lambda *
ast_lambda(Token *pos, Array<Ast_Decl *> params, Array<Ast_Expr *> ret, Ast_Scope *scope){
AST_NEW(Lambda, LAMBDA_EXPR, pos, AST_EXPR);
result->flags = AST_EXPR;
@@ -412,14 +412,14 @@ ast_lambda(Token *pos, Array<Ast_Decl *> params, Array<Ast_Expr *> ret, Ast_Scop
return result;
}
function Ast_If *
CORE_Static Ast_If *
ast_if(Token *pos, Array<Ast_If_Node *> ifs){
AST_NEW(If, IF, pos, AST_STMT);
result->ifs = ifs.tight_copy(pctx->perm);
return result;
}
function Ast_For *
CORE_Static Ast_For *
ast_for(Token *pos, Ast_Expr *init, Ast_Expr *cond, Ast_Expr *iter, Ast_Scope *scope){
AST_NEW(For, FOR, pos, AST_STMT);
result->init = init;
@@ -429,19 +429,19 @@ ast_for(Token *pos, Ast_Expr *init, Ast_Expr *cond, Ast_Expr *iter, Ast_Scope *s
return result;
}
function Ast_Pass *
CORE_Static Ast_Pass *
ast_pass(Token *pos){
AST_NEW(Pass, PASS, pos, AST_STMT);
return result;
}
function Ast_Break *
CORE_Static Ast_Break *
ast_break(Token *pos){
AST_NEW(Break, BREAK, pos, AST_STMT);
return result;
}
function Ast_Return *
CORE_Static Ast_Return *
ast_return(Token *pos, Array<Ast_Expr *> expr){
AST_NEW(Return, RETURN, pos, AST_STMT);
if(expr.len){
@@ -451,7 +451,7 @@ ast_return(Token *pos, Array<Ast_Expr *> expr){
return result;
}
function Ast_If_Node *
CORE_Static Ast_If_Node *
ast_if_node(Token *pos, Ast_Expr *init, Ast_Expr *expr, Ast_Scope *scope){
AST_NEW(If_Node, IF_NODE, pos, AST_STMT);
result->scope = scope;
@@ -463,14 +463,14 @@ ast_if_node(Token *pos, Ast_Expr *init, Ast_Expr *expr, Ast_Scope *scope){
return result;
}
function Ast_Array *
CORE_Static Ast_Array *
ast_array(Token *pos, Ast_Expr *expr){
AST_NEW(Array, ARRAY, pos, AST_EXPR);
result->expr = expr;
return result;
}
function Ast_Scope *
CORE_Static Ast_Scope *
begin_decl_scope(Arena *scratch, Token *pos){
AST_NEW(Scope, SCOPE, pos, AST_DECL);
result->file = pctx->currently_parsed_file;
@@ -482,12 +482,12 @@ begin_decl_scope(Arena *scratch, Token *pos){
return result;
}
function void
CORE_Static void
finalize_decl_scope(Ast_Scope *scope){
pctx->currently_parsed_scope = scope->parent_scope;
}
function Ast_Scope *
CORE_Static Ast_Scope *
begin_stmt_scope(Arena *scratch, Token *pos){
AST_NEW(Scope, SCOPE, pos, AST_STMT);
result->stmts = {scratch};
@@ -500,20 +500,20 @@ begin_stmt_scope(Arena *scratch, Token *pos){
return result;
}
function void
CORE_Static void
finalize_stmt_scope(Ast_Scope *scope){
scope->stmts = scope->stmts.tight_copy(pctx->perm);
pctx->currently_parsed_scope = scope->parent_scope;
}
function Ast_Decl *
CORE_Static Ast_Decl *
ast_struct(Token *pos, Ast_Scope *scope){
AST_NEW(Decl, STRUCT, pos, AST_DECL | AST_AGGREGATE);
result->scope = scope;
return result;
}
function Ast_Decl *
CORE_Static Ast_Decl *
ast_enum(Token *pos, Ast_Expr *typespec, Ast_Scope *scope){
AST_NEW(Decl, ENUM, pos, AST_DECL | AST_AGGREGATE);
result->scope = scope;
@@ -521,7 +521,7 @@ ast_enum(Token *pos, Ast_Expr *typespec, Ast_Scope *scope){
return result;
}
function Ast_Decl *
CORE_Static Ast_Decl *
ast_var(Token *pos, Ast_Expr *typespec, Intern_String name, Ast_Expr *expr){
AST_NEW(Decl, VAR, pos, AST_DECL);
result->name = name;
@@ -530,7 +530,7 @@ ast_var(Token *pos, Ast_Expr *typespec, Intern_String name, Ast_Expr *expr){
return result;
}
function Ast_Decl *
CORE_Static Ast_Decl *
ast_const(Token *pos, Intern_String name, Value value){
AST_NEW(Decl, CONST, pos, AST_DECL);
result->value = value;
@@ -538,7 +538,7 @@ ast_const(Token *pos, Intern_String name, Value value){
return result;
}
function Ast_Decl *
CORE_Static Ast_Decl *
ast_const(Token *pos, Intern_String name, Ast_Expr *expr){
AST_NEW(Decl, CONST, pos, AST_DECL);
result->expr = expr;
@@ -546,7 +546,7 @@ ast_const(Token *pos, Intern_String name, Ast_Expr *expr){
return result;
}
function Ast_Decl *
CORE_Static Ast_Decl *
ast_type(Token *pos, Intern_String name, Ast_Type *type){
AST_NEW(Decl, TYPE, pos, AST_DECL);
result->type = type_type;
@@ -555,7 +555,7 @@ ast_type(Token *pos, Intern_String name, Ast_Type *type){
return result;
}
function Ast_Scope *
CORE_Static Ast_Scope *
ast_decl_scope(Token *pos, Arena *allocator, Ast_File *file){
AST_NEW(Scope, SCOPE, pos, AST_DECL);
result->file = file;
@@ -565,7 +565,7 @@ ast_decl_scope(Token *pos, Arena *allocator, Ast_File *file){
return result;
}
function Ast_Decl *
CORE_Static Ast_Decl *
ast_namespace(Token *pos, Ast_Scope *module, Intern_String name){
AST_NEW(Decl, NAMESPACE, pos, AST_DECL);
result->scope = module;
@@ -573,7 +573,7 @@ ast_namespace(Token *pos, Ast_Scope *module, Intern_String name){
return result;
}
function Ast_Builtin *
CORE_Static Ast_Builtin *
ast_runtime_assert(Token *pos, Ast_Expr *expr, Intern_String message){
AST_NEW(Builtin, RUNTIME_ASSERT, pos, AST_EXPR);
result->expr = expr;
@@ -581,7 +581,7 @@ ast_runtime_assert(Token *pos, Ast_Expr *expr, Intern_String message){
return result;
}
function Ast_Builtin *
CORE_Static Ast_Builtin *
ast_constant_assert(Token *pos, Ast_Expr *expr, Intern_String message){
AST_NEW(Builtin, CONSTANT_ASSERT, pos, AST_EXPR);
result->expr = expr;
@@ -589,28 +589,28 @@ ast_constant_assert(Token *pos, Ast_Expr *expr, Intern_String message){
return result;
}
function Ast_Builtin *
CORE_Static Ast_Builtin *
ast_sizeof(Token *pos, Ast_Expr *expr){
AST_NEW(Builtin, SIZE_OF, pos, AST_EXPR);
result->expr = expr;
return result;
}
function Ast_Builtin *
CORE_Static Ast_Builtin *
ast_len(Token *pos, Ast_Expr *expr){
AST_NEW(Builtin, LENGTH_OF, pos, AST_EXPR);
result->expr = expr;
return result;
}
function Ast_Builtin *
CORE_Static Ast_Builtin *
ast_alignof(Token *pos, Ast_Expr *expr){
AST_NEW(Builtin, ALIGN_OF, pos, AST_EXPR);
result->expr = expr;
return result;
}
function Ast_Var_Unpack *
CORE_Static Ast_Var_Unpack *
ast_var_unpack(Token *pos, Array<Ast_Decl *> vars, Ast_Expr *expr){
AST_NEW(Var_Unpack, VAR_UNPACK, pos, AST_STMT);
result->vars = vars.tight_copy(pctx->perm);
@@ -621,7 +621,7 @@ ast_var_unpack(Token *pos, Array<Ast_Decl *> vars, Ast_Expr *expr){
//-----------------------------------------------------------------------------
// Value
//-----------------------------------------------------------------------------
function Value
CORE_Static Value
value_bool(B32 v){
Value value;
value.bool_val = v;
@@ -629,7 +629,7 @@ value_bool(B32 v){
return value;
}
function Value
CORE_Static Value
value_int(BigInt b){
Value value;
value.big_int_val = b;
@@ -637,7 +637,7 @@ value_int(BigInt b){
return value;
}
function Value
CORE_Static Value
value_int(S64 s64){
Value value;
value.type = untyped_int;
@@ -645,7 +645,7 @@ value_int(S64 s64){
return value;
}
function Value
CORE_Static Value
value_float(F64 b){
Value value;
value.f64_val = b;
@@ -653,7 +653,7 @@ value_float(F64 b){
return value;
}
function Value
CORE_Static Value
value_float(BigInt a){
Value value;
value.f64_val = bigint_as_float(&a);
@@ -661,19 +661,19 @@ value_float(BigInt a){
return value;
}
function B32
CORE_Static B32
is_ident(Ast *ast){
B32 result = ast->kind == AST_IDENT;
return result;
}
function B32
CORE_Static B32
is_binary(Ast *ast){
B32 result = ast->kind == AST_BINARY;
return result;
}
function B32
CORE_Static B32
is_atom(Ast *ast){
B32 result = is_flag_set(ast->flags, AST_ATOM);
return result;