Skip to content

Commit

Permalink
Use arena for scoped Obj objects
Browse files Browse the repository at this point in the history
  • Loading branch information
fuhsnn committed Dec 21, 2024
1 parent 2664afa commit ed82490
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,7 @@ static void new_initializer(Initializer *init, Type *ty, bool is_flexible) {
}
}

static Obj *new_var(char *name, Type *ty) {
Obj *var = calloc(1, sizeof(Obj));
static Obj *new_var(char *name, Type *ty, Obj *var) {
var->name = name;
var->ty = ty;
var->align = ty->align;
Expand All @@ -394,15 +393,15 @@ static Obj *new_var(char *name, Type *ty) {
}

Obj *new_lvar(char *name, Type *ty) {
Obj *var = new_var(name, ty);
Obj *var = new_var(name, ty, ast_arena_calloc(sizeof(Obj)));
var->is_local = true;
var->next = scope->locals;
scope->locals = var;
return var;
}

static Obj *new_gvar(char *name, Type *ty) {
Obj *var = new_var(name, ty);
Obj *var = new_var(name, ty, calloc(1, sizeof(Obj)));
var->next = globals;
globals = var;
return var;
Expand All @@ -422,7 +421,7 @@ static Obj *new_anon_gvar(Type *ty) {
}

static Obj *new_static_lvar(Type *ty) {
Obj *var = new_var(NULL, ty);
Obj *var = new_var(NULL, ty, ast_arena_calloc(sizeof(Obj)));
var->name = new_unique_name();
var->is_definition = true;
var->is_static = true;
Expand Down Expand Up @@ -1333,7 +1332,7 @@ static void defr_cleanup(Obj *var, Obj *fn, Token *tok) {
Node *arg = new_unary(ND_ADDR, new_var_node(var, tok), tok);
add_type(arg);

n->args = new_var(NULL, arg->ty);
n->args = new_var(NULL, arg->ty, ast_arena_calloc(sizeof(Obj)));
n->args->arg_expr = arg;
prepare_funcall(n, scope);

Expand Down Expand Up @@ -3951,7 +3950,7 @@ static Node *funcall(Token **rest, Token *tok, Node *fn) {
else if (arg->ty->kind == TY_FUNC)
arg = new_cast(arg, pointer_to(arg->ty));
}
cur = cur->param_next = new_var(NULL, arg->ty);
cur = cur->param_next = new_var(NULL, arg->ty, ast_arena_calloc(sizeof(Obj)));
cur->arg_expr = arg;
}
if (param)
Expand Down Expand Up @@ -4053,7 +4052,7 @@ static Node *primary(Token **rest, Token *tok) {
while (sc->is_temporary)
sc = sc->parent;

Obj *var = new_var(NULL, ty);
Obj *var = new_var(NULL, ty, ast_arena_calloc(sizeof(Obj)));
var->is_compound_lit = true;
var->is_local = true;
var->next = sc->locals;
Expand Down

0 comments on commit ed82490

Please sign in to comment.