mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Move mutable value decl stuff to a separate procedure
This commit is contained in:
+75
-68
@@ -2155,74 +2155,8 @@ gb_internal void cg_build_type_switch_stmt(cgProcedure *p, Ast *node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
gb_internal void cg_build_stmt(cgProcedure *p, Ast *node) {
|
gb_internal void cg_build_mutable_value_decl(cgProcedure *p, Ast *node) {
|
||||||
Ast *prev_stmt = p->curr_stmt;
|
ast_node(vd, ValueDecl, node);
|
||||||
defer (p->curr_stmt = prev_stmt);
|
|
||||||
p->curr_stmt = node;
|
|
||||||
|
|
||||||
// TODO(bill): check if last instruction was a terminating one or not
|
|
||||||
|
|
||||||
cg_set_debug_pos_from_node(p, node);
|
|
||||||
|
|
||||||
u16 prev_state_flags = p->state_flags;
|
|
||||||
defer (p->state_flags = prev_state_flags);
|
|
||||||
|
|
||||||
if (node->state_flags != 0) {
|
|
||||||
u16 in = node->state_flags;
|
|
||||||
u16 out = p->state_flags;
|
|
||||||
|
|
||||||
if (in & StateFlag_bounds_check) {
|
|
||||||
out |= StateFlag_bounds_check;
|
|
||||||
out &= ~StateFlag_no_bounds_check;
|
|
||||||
} else if (in & StateFlag_no_bounds_check) {
|
|
||||||
out |= StateFlag_no_bounds_check;
|
|
||||||
out &= ~StateFlag_bounds_check;
|
|
||||||
}
|
|
||||||
if (in & StateFlag_no_type_assert) {
|
|
||||||
out |= StateFlag_no_type_assert;
|
|
||||||
out &= ~StateFlag_type_assert;
|
|
||||||
} else if (in & StateFlag_type_assert) {
|
|
||||||
out |= StateFlag_type_assert;
|
|
||||||
out &= ~StateFlag_no_type_assert;
|
|
||||||
}
|
|
||||||
|
|
||||||
p->state_flags = out;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (node->kind) {
|
|
||||||
case_ast_node(bs, EmptyStmt, node);
|
|
||||||
case_end;
|
|
||||||
|
|
||||||
case_ast_node(us, UsingStmt, node);
|
|
||||||
case_end;
|
|
||||||
|
|
||||||
case_ast_node(ws, WhenStmt, node);
|
|
||||||
cg_build_when_stmt(p, ws);
|
|
||||||
case_end;
|
|
||||||
|
|
||||||
case_ast_node(bs, BlockStmt, node);
|
|
||||||
TB_Node *done = nullptr;
|
|
||||||
if (bs->label != nullptr) {
|
|
||||||
done = cg_control_region(p, "block_done");
|
|
||||||
cgTargetList *tl = cg_push_target_list(p, bs->label, done, nullptr, nullptr);
|
|
||||||
tl->is_block = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
cg_scope_open(p, bs->scope);
|
|
||||||
cg_build_stmt_list(p, bs->stmts);
|
|
||||||
cg_scope_close(p, cgDeferExit_Default, nullptr);
|
|
||||||
|
|
||||||
if (done != nullptr) {
|
|
||||||
cg_emit_goto(p, done);
|
|
||||||
tb_inst_set_control(p->func, done);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bs->label != nullptr) {
|
|
||||||
cg_pop_target_list(p);
|
|
||||||
}
|
|
||||||
case_end;
|
|
||||||
|
|
||||||
case_ast_node(vd, ValueDecl, node);
|
|
||||||
if (!vd->is_mutable) {
|
if (!vd->is_mutable) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -2239,6 +2173,7 @@ gb_internal void cg_build_stmt(cgProcedure *p, Ast *node) {
|
|||||||
is_static = true;
|
is_static = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_static) {
|
if (is_static) {
|
||||||
for_array(i, vd->names) {
|
for_array(i, vd->names) {
|
||||||
Ast *ident = vd->names[i];
|
Ast *ident = vd->names[i];
|
||||||
@@ -2347,6 +2282,78 @@ gb_internal void cg_build_stmt(cgProcedure *p, Ast *node) {
|
|||||||
cgValue init = inits[i];
|
cgValue init = inits[i];
|
||||||
cg_addr_store(p, lval, init);
|
cg_addr_store(p, lval, init);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
gb_internal void cg_build_stmt(cgProcedure *p, Ast *node) {
|
||||||
|
Ast *prev_stmt = p->curr_stmt;
|
||||||
|
defer (p->curr_stmt = prev_stmt);
|
||||||
|
p->curr_stmt = node;
|
||||||
|
|
||||||
|
// TODO(bill): check if last instruction was a terminating one or not
|
||||||
|
|
||||||
|
cg_set_debug_pos_from_node(p, node);
|
||||||
|
|
||||||
|
u16 prev_state_flags = p->state_flags;
|
||||||
|
defer (p->state_flags = prev_state_flags);
|
||||||
|
|
||||||
|
if (node->state_flags != 0) {
|
||||||
|
u16 in = node->state_flags;
|
||||||
|
u16 out = p->state_flags;
|
||||||
|
|
||||||
|
if (in & StateFlag_bounds_check) {
|
||||||
|
out |= StateFlag_bounds_check;
|
||||||
|
out &= ~StateFlag_no_bounds_check;
|
||||||
|
} else if (in & StateFlag_no_bounds_check) {
|
||||||
|
out |= StateFlag_no_bounds_check;
|
||||||
|
out &= ~StateFlag_bounds_check;
|
||||||
|
}
|
||||||
|
if (in & StateFlag_no_type_assert) {
|
||||||
|
out |= StateFlag_no_type_assert;
|
||||||
|
out &= ~StateFlag_type_assert;
|
||||||
|
} else if (in & StateFlag_type_assert) {
|
||||||
|
out |= StateFlag_type_assert;
|
||||||
|
out &= ~StateFlag_no_type_assert;
|
||||||
|
}
|
||||||
|
|
||||||
|
p->state_flags = out;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (node->kind) {
|
||||||
|
case_ast_node(bs, EmptyStmt, node);
|
||||||
|
case_end;
|
||||||
|
|
||||||
|
case_ast_node(us, UsingStmt, node);
|
||||||
|
case_end;
|
||||||
|
|
||||||
|
case_ast_node(ws, WhenStmt, node);
|
||||||
|
cg_build_when_stmt(p, ws);
|
||||||
|
case_end;
|
||||||
|
|
||||||
|
case_ast_node(bs, BlockStmt, node);
|
||||||
|
TB_Node *done = nullptr;
|
||||||
|
if (bs->label != nullptr) {
|
||||||
|
done = cg_control_region(p, "block_done");
|
||||||
|
cgTargetList *tl = cg_push_target_list(p, bs->label, done, nullptr, nullptr);
|
||||||
|
tl->is_block = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
cg_scope_open(p, bs->scope);
|
||||||
|
cg_build_stmt_list(p, bs->stmts);
|
||||||
|
cg_scope_close(p, cgDeferExit_Default, nullptr);
|
||||||
|
|
||||||
|
if (done != nullptr) {
|
||||||
|
cg_emit_goto(p, done);
|
||||||
|
tb_inst_set_control(p->func, done);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bs->label != nullptr) {
|
||||||
|
cg_pop_target_list(p);
|
||||||
|
}
|
||||||
|
case_end;
|
||||||
|
|
||||||
|
case_ast_node(vd, ValueDecl, node);
|
||||||
|
cg_build_mutable_value_decl(p, node);
|
||||||
case_end;
|
case_end;
|
||||||
|
|
||||||
case_ast_node(bs, BranchStmt, node);
|
case_ast_node(bs, BranchStmt, node);
|
||||||
|
|||||||
Reference in New Issue
Block a user