diff options
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 41 |
1 files changed, 21 insertions, 20 deletions
@@ -75,7 +75,7 @@ Type parse_type(Lexer *l, Proc *proc) { if (l->tok == TOK_DEREF) { lex_next(l); t.t = T_PTR; - t.next = new(&proc->arena, Type); + t.next = new(&proc->perm, Type); *t.next = parse_type(l, proc); return t; } @@ -125,13 +125,14 @@ void parse_stmt(Lexer *l, Proc *p); /* TODO: return node from this! */ void parse_block(Lexer *l, Proc *p, ScopeNameList *nl) { lex_next(l); + arena_reset(&p->scratch); scope_push(&p->scope, p); while (l->tok != TOK_RBRACE) { lex_expected_not(l, TM_EOF); parse_stmt(l, p); } if (nl) { - scope_collect(&p->scope, p, nl, &p->arena); + scope_collect(&p->scope, p, nl, &p->scratch); } scope_pop(&p->scope, p); lex_expected(l, TM_RBRACE); @@ -150,12 +151,12 @@ void parse_assign(Lexer *l, Proc *p) { Node *e = parse_expr(l, p, &b->node->type); if (node_uninit(e)) { lex_error_at(l, e->src_pos, LE_ERROR, - str_fmt(&p->arena, "uninitialized %S", - type_desc(&e->type, &p->arena))); + str_fmt(&p->scratch, "uninitialized %S", + type_desc(&e->type, &p->scratch))); } else if (node_maybe_uninit(e)) { lex_error_at(l, e->src_pos, LE_WARN, - str_fmt(&p->arena, "possibly uninitialized %S", - type_desc(&e->type, &p->arena))); + str_fmt(&p->scratch, "possibly uninitialized %S", + type_desc(&e->type, &p->scratch))); } scope_update(b, e, p); } @@ -249,8 +250,8 @@ void parse_if(Lexer *l, Proc *p) { .type = { .lvl = T_TOP, .t = T_TUPLE }, .tuple = { 0 } }; - ZDA_PUSH(&p->arena, &if_node->val.tuple, (Value) { .type = { .lvl = T_CTRL, .t = T_NONE } }); - ZDA_PUSH(&p->arena, &if_node->val.tuple, (Value) { .type = { .lvl = T_CTRL, .t = T_NONE } }); + ZDA_PUSH(&p->perm, &if_node->val.tuple, (Value) { .type = { .lvl = T_CTRL, .t = T_NONE } }); + ZDA_PUSH(&p->perm, &if_node->val.tuple, (Value) { .type = { .lvl = T_CTRL, .t = T_NONE } }); if_node = node_peephole(if_node, p, l); node_add(p, if_node, p->keepalive); Node *if_true = node_new(p, N_PROJ, if_node); @@ -265,7 +266,7 @@ void parse_if(Lexer *l, Proc *p) { node_add(p, if_true, p->keepalive); node_add(p, if_false, p->keepalive); ScopeNameList scope_before = { 0 }, scope_true = { 0 }, scope_false = { 0 }; - scope_collect(&p->scope, p, &scope_before, &p->arena); + scope_collect(&p->scope, p, &scope_before, &p->scratch); if (cond->type.lvl == T_CONST) { if (cond->val.i) if_false->type.lvl = T_XCTRL; else if_true->type.lvl = T_XCTRL; @@ -373,7 +374,7 @@ void parse_args_list(Lexer *l, Proc *proc) { Node *proj = node_new(proc, N_PROJ, proc->start); proj->type = v.type; proj->val.i = i++; - ZDA_PUSH(&proc->arena, &start->val.tuple, v); + ZDA_PUSH(&proc->perm, &start->val.tuple, v); scope_bind(&proc->scope, idbuf[j].name, proj, idbuf[j].pos, proc); } id = 0; @@ -444,7 +445,7 @@ void proc_opt_fwd(Proc *p, Lexer *l, Node *n) { void proc_opt(Proc *p, Lexer *l) { if (p->stop->in.len == 0) { if (p->ret_type.t != T_NONE) { - lex_error(l, LE_ERROR, str_fmt(&p->arena, "no return statement in function expecting %S", type_desc(&p->ret_type, &p->arena))); + lex_error(l, LE_ERROR, str_fmt(&p->scratch, "no return statement in function expecting %S", type_desc(&p->ret_type, &p->scratch))); } } for (int i = 0; i < p->start->out.len; i++) { @@ -489,12 +490,12 @@ Proc *parse_proc(Lexer *l, Unit *u) { void uninit_check(Lexer *l, Proc *p, Node *n, LexSpan pos) { if (node_uninit(n)) { lex_error_at(l, pos, LE_ERROR, - str_fmt(&p->arena, "uninitialized %S", - type_desc(&n->type, &p->arena))); + str_fmt(&p->scratch, "uninitialized %S", + type_desc(&n->type, &p->scratch))); } else if (node_maybe_uninit(n)) { lex_error_at(l, pos, LE_WARN, - str_fmt(&p->arena, "possibly uninitialized %S", - type_desc(&n->type, &p->arena))); + str_fmt(&p->scratch, "possibly uninitialized %S", + type_desc(&n->type, &p->scratch))); } } @@ -636,8 +637,8 @@ void node_print(Node *n, Proc *p) { int c = n->val.tuple.len; Value *v = n->val.tuple.data; for (int i = 0; i < c; i++) { - if (i > 0) str_cat(&s, S(", "), &p->arena); - str_cat(&s, type_desc(&v[i].type, &p->arena), &p->arena); + if (i > 0) str_cat(&s, S(", "), &p->scratch); + str_cat(&s, type_desc(&v[i].type, &p->scratch), &p->scratch); } printf("\t%d [label=\"start(%.*s)\"]", n->id, (int)s.n, s.s); } else if (n->op == N_LIT) { @@ -659,10 +660,10 @@ void node_print(Node *n, Proc *p) { break; } } else if (n->op == N_PROJ) { - Str d = type_desc(&n->in.data[0]->val.tuple.data[n->val.i].type, &p->arena); + Str d = type_desc(&n->in.data[0]->val.tuple.data[n->val.i].type, &p->scratch); printf("\t%d [label=\"%.*s(%ld)\", shape=record]", n->id, (int)d.n, d.s, n->val.i); } else if (n->op == N_UNINIT) { - Str s = type_desc(&n->type, &p->arena); + Str s = type_desc(&n->type, &p->scratch); printf("\t%d [label=\"uninitialized %.*s\", shape=record]", n->id, (int)s.n, s.s); } else { printf("\t%d [label=\"%s\", shape=record]", n->id, node_type_name(n->op)); @@ -689,7 +690,7 @@ void node_print(Node *n, Proc *p) { void proc_print(Proc *p) { if (p->start) { - Str d = type_desc(&p->ret_type, &p->arena); + Str d = type_desc(&p->ret_type, &p->scratch); printf("\t\"%.*s %.*s\" -> %d\n", (int)p->name.n, p->name.s, (int)d.n, d.s, p->start->id); node_print(p->start, p); if (no_opt) { |
