Commit c7663cec

c7663cecf992Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified

Description

codegen: box trailing post-splat masgn targets into widened slots

The leading-splat multiple-assignment path (*xs, last = [..]) binds each post-splat fixed target from a pre-extracted element temp. Box that int temp (and the typed-zero default for an out-of-range target) when the destination local is a poly-widened slot, matching the other masgn target paths.

Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
c7663cecf992
Parent
0c70d7b154f6

src/codegen_stmt.cmodifiedView file

@@ -3671,11 +3671,30 @@
36713671 const char *rnm_j = nt_str(nt, rights[j], "name");
36723672 if (!strcmp(lty, "LocalVariableTargetNode")) {
36733673 emit_indent(b, indent);
3674+ LocalVar *rjlv = rnm_j ? scope_local(comp_scope_of(c, id), rnm_j) : NULL;
3675+ int rjpoly = rjlv && rjlv->type == TY_POLY;
36743676 if (ridx >= 0 && ridx < en) {
3675- buf_printf(b, "lv_%s = _t%d;\n", rnm_j, tmps[ridx]);
3677+ buf_printf(b, "lv_%s = ", rnm_j);
3678+ TyKind valt = comp_ntype(c, els[ridx]);
3679+ if (rjpoly && valt != TY_POLY) {
3680+ char expr[32]; snprintf(expr, sizeof expr, "_t%d", tmps[ridx]);
3681+ Buf bx; memset(&bx, 0, sizeof bx);
3682+ emit_boxed_text(c, valt, expr, &bx);
3683+ buf_puts(b, bx.p ? bx.p : "sp_box_nil()"); free(bx.p);
3684+ }
3685+ else buf_printf(b, "_t%d", tmps[ridx]);
3686+ buf_puts(b, ";\n");
36763687 }
36773688 else {
3678- buf_printf(b, "lv_%s = %s;\n", rnm_j, default_value(comp_ntype(c, rights[j])));
3689+ buf_printf(b, "lv_%s = ", rnm_j);
3690+ TyKind tt = comp_ntype(c, rights[j]);
3691+ if (rjpoly) {
3692+ Buf bx; memset(&bx, 0, sizeof bx);
3693+ emit_boxed_text(c, tt, default_value(tt), &bx);
3694+ buf_puts(b, bx.p ? bx.p : "sp_box_nil()"); free(bx.p);
3695+ }
3696+ else buf_puts(b, default_value(tt));
3697+ buf_puts(b, ";\n");
36793698 }
36803699 }
36813700 else if ((!strcmp(lty, "ConstantPathTargetNode") || !strcmp(lty, "ConstantTargetNode")) &&