diff options
| author | gingerBill <bill@gingerbill.org> | 2023-07-25 01:11:57 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2023-07-25 01:11:57 +0100 |
| commit | e4006eb58343d35e7e26177a1adf41b0d9665b10 (patch) | |
| tree | 805b051040198774d8aae07f62a52232ec6a627b /src/tilde_stmt.cpp | |
| parent | b934e4b564e58c62b8c6848a71fe99b02c588a94 (diff) | |
Update tilde
Diffstat (limited to 'src/tilde_stmt.cpp')
| -rw-r--r-- | src/tilde_stmt.cpp | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/src/tilde_stmt.cpp b/src/tilde_stmt.cpp index a663a401d..794061335 100644 --- a/src/tilde_stmt.cpp +++ b/src/tilde_stmt.cpp @@ -2246,20 +2246,42 @@ gb_internal void cg_build_stmt(cgProcedure *p, Ast *node) { TEMPORARY_ALLOCATOR_GUARD(); + auto inits = array_make<cgValue>(temporary_allocator(), 0, vd->values.count != 0 ? vd->names.count : 0); + for (Ast *rhs : vd->values) { + cgValue init = cg_build_expr(p, rhs); + cg_append_tuple_values(p, &inits, init); + } + + auto lvals = slice_make<cgAddr>(temporary_allocator(), vd->names.count); for_array(i, vd->names) { Ast *name = vd->names[i]; if (!is_blank_ident(name)) { Entity *e = entity_of_node(name); - lvals[i] = cg_add_local(p, e->type, e, true); + bool zero_init = vd->values.count == 0; + if (vd->names.count == vd->values.count) { + Ast *expr = unparen_expr(vd->values[i]); + if (expr->kind == Ast_CompoundLit && + inits[i].kind == cgValue_Addr) { + TB_Node *ptr = inits[i].node; + + if (e != nullptr && e->token.string.len > 0 && e->token.string != "_") { + // NOTE(bill): for debugging purposes only + String name = e->token.string; + TB_DebugType *debug_type = cg_debug_type(p->module, e->type); + tb_node_append_attrib(ptr, tb_function_attrib_variable(p->func, name.len, cast(char const *)name.text, debug_type)); + } + + cgAddr addr = cg_addr(inits[i]); + map_set(&p->variable_map, e, addr); + continue; + } + } + + lvals[i] = cg_add_local(p, e->type, e, zero_init); } } - 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) { |