mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 08:08:50 +00:00
Simplification of the ValueDecl code
This commit is contained in:
+26
-25
@@ -1353,9 +1353,8 @@ gb_internal void cg_build_stmt(cgProcedure *p, Ast *node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool is_static = false;
|
bool is_static = false;
|
||||||
if (vd->names.count > 0) {
|
for (Ast *name : vd->names) if (!is_blank_ident(name)) {
|
||||||
for (Ast *name : vd->names) {
|
// NOTE(bill): Sanity check to check for the existence of the variable's Entity
|
||||||
if (!is_blank_ident(name)) {
|
|
||||||
GB_ASSERT(name->kind == Ast_Ident);
|
GB_ASSERT(name->kind == Ast_Ident);
|
||||||
Entity *e = entity_of_node(name);
|
Entity *e = entity_of_node(name);
|
||||||
TokenPos pos = ast_token(name).pos;
|
TokenPos pos = ast_token(name).pos;
|
||||||
@@ -1363,9 +1362,6 @@ gb_internal void cg_build_stmt(cgProcedure *p, Ast *node) {
|
|||||||
if (e->flags & EntityFlag_Static) {
|
if (e->flags & EntityFlag_Static) {
|
||||||
// NOTE(bill): If one of the entities is static, they all are
|
// NOTE(bill): If one of the entities is static, they all are
|
||||||
is_static = true;
|
is_static = true;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is_static) {
|
if (is_static) {
|
||||||
@@ -1375,24 +1371,7 @@ gb_internal void cg_build_stmt(cgProcedure *p, Ast *node) {
|
|||||||
|
|
||||||
TEMPORARY_ALLOCATOR_GUARD();
|
TEMPORARY_ALLOCATOR_GUARD();
|
||||||
|
|
||||||
auto const &values = vd->values;
|
|
||||||
if (values.count == 0) {
|
|
||||||
for (Ast *name : vd->names) {
|
|
||||||
if (!is_blank_ident(name)) {
|
|
||||||
Entity *e = entity_of_node(name);
|
|
||||||
cgAddr addr = cg_add_local(p, e->type, e, true);
|
|
||||||
gb_unused(addr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
auto lvals = slice_make<cgAddr>(temporary_allocator(), vd->names.count);
|
auto lvals = slice_make<cgAddr>(temporary_allocator(), vd->names.count);
|
||||||
auto inits = array_make<cgValue>(temporary_allocator(), 0, lvals.count);
|
|
||||||
for (Ast *rhs : values) {
|
|
||||||
rhs = unparen_expr(rhs);
|
|
||||||
cgValue init = cg_build_expr(p, rhs);
|
|
||||||
cg_append_tuple_values(p, &inits, init);
|
|
||||||
}
|
|
||||||
|
|
||||||
for_array(i, vd->names) {
|
for_array(i, vd->names) {
|
||||||
Ast *name = vd->names[i];
|
Ast *name = vd->names[i];
|
||||||
if (!is_blank_ident(name)) {
|
if (!is_blank_ident(name)) {
|
||||||
@@ -1400,13 +1379,19 @@ gb_internal void cg_build_stmt(cgProcedure *p, Ast *node) {
|
|||||||
lvals[i] = cg_add_local(p, e->type, e, true);
|
lvals[i] = cg_add_local(p, e->type, e, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GB_ASSERT(lvals.count == inits.count);
|
|
||||||
|
auto inits = array_make<cgValue>(temporary_allocator(), 0, vd->values.count != 0 ? lvals.count : 0);
|
||||||
|
for (Ast *rhs : vd->values) {
|
||||||
|
cgValue init = cg_build_expr(p, rhs);
|
||||||
|
cg_append_tuple_values(p, &inits, init);
|
||||||
|
}
|
||||||
|
|
||||||
|
GB_ASSERT(vd->values.count == 0 || lvals.count == inits.count);
|
||||||
for_array(i, inits) {
|
for_array(i, inits) {
|
||||||
cgAddr lval = lvals[i];
|
cgAddr lval = lvals[i];
|
||||||
cgValue init = inits[i];
|
cgValue init = inits[i];
|
||||||
cg_addr_store(p, lval, init);
|
cg_addr_store(p, lval, init);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
case_end;
|
case_end;
|
||||||
|
|
||||||
case_ast_node(bs, BranchStmt, node);
|
case_ast_node(bs, BranchStmt, node);
|
||||||
@@ -1460,10 +1445,25 @@ gb_internal void cg_build_stmt(cgProcedure *p, Ast *node) {
|
|||||||
cg_build_for_stmt(p, node);
|
cg_build_for_stmt(p, node);
|
||||||
case_end;
|
case_end;
|
||||||
|
|
||||||
|
case_ast_node(rs, RangeStmt, node);
|
||||||
|
GB_PANIC("TODO(bill): cg_build_range_stmt");
|
||||||
|
// cg_build_range_stmt(p, rs, rs->scope);
|
||||||
|
case_end;
|
||||||
|
|
||||||
|
case_ast_node(rs, UnrollRangeStmt, node);
|
||||||
|
GB_PANIC("TODO(bill): lb_build_unroll_range_stmt");
|
||||||
|
// cg_build_range_stmt(p, rs, rs->scope);
|
||||||
|
case_end;
|
||||||
|
|
||||||
case_ast_node(fs, SwitchStmt, node);
|
case_ast_node(fs, SwitchStmt, node);
|
||||||
cg_build_switch_stmt(p, node);
|
cg_build_switch_stmt(p, node);
|
||||||
case_end;
|
case_end;
|
||||||
|
|
||||||
|
case_ast_node(ss, TypeSwitchStmt, node);
|
||||||
|
GB_PANIC("TODO(bill): cg_build_type_switch_stmt");
|
||||||
|
// cg_build_type_switch_stmt(p, ss);
|
||||||
|
case_end;
|
||||||
|
|
||||||
case_ast_node(ds, DeferStmt, node);
|
case_ast_node(ds, DeferStmt, node);
|
||||||
Type *pt = base_type(p->type);
|
Type *pt = base_type(p->type);
|
||||||
GB_ASSERT(pt->kind == Type_Proc);
|
GB_ASSERT(pt->kind == Type_Proc);
|
||||||
@@ -1481,6 +1481,7 @@ gb_internal void cg_build_stmt(cgProcedure *p, Ast *node) {
|
|||||||
case_end;
|
case_end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
GB_PANIC("TODO cg_build_stmt %.*s", LIT(ast_strings[node->kind]));
|
GB_PANIC("TODO cg_build_stmt %.*s", LIT(ast_strings[node->kind]));
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user