Commit d97111bb
d97111bb178cMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · +2 added · ~1 modified
Description
Merge pull request #1407 from OriPekelman/fix/array-new-poly-size
codegen: coerce a poly Array.new size operand to int
Details
- Commit
- d97111bb178c
- Parent
- 343baab89c88
- Merge parent
- 40672965ab1f
src/codegen_call.cmodifiedView file
@@ -2357,7 +2357,7 @@
23572357
if (cn && !strcmp(cn, "Array") && argc == 1 && nt_ref(nt, id, "block") < 0) {23582358
/* Array.new(n) -> PolyArray of n nils */23592359
int tn = ++g_tmp, tr = ++g_tmp, ti = ++g_tmp;2360-
Buf nb; memset(&nb, 0, sizeof nb); emit_expr(c, argv[0], &nb);2360+
Buf nb; memset(&nb, 0, sizeof nb); emit_int_expr(c, argv[0], &nb); /* poly size -> int (spinel-dev#24) */23612361
emit_indent(g_pre, g_indent);23622362
buf_printf(g_pre, "mrb_int _t%d = ", tn); buf_puts(g_pre, nb.p ? nb.p : "0"); buf_puts(g_pre, ";\n");23632363
emit_indent(g_pre, g_indent);@@ -2381,7 +2381,7 @@
23812381
const char *ip = block_param_name(c, blk, 0);23822382
const char *irn = ip ? rename_local(ip) : NULL;23832383
Buf nb; memset(&nb, 0, sizeof nb);2384-
if (argc >= 1) emit_expr(c, argv[0], &nb);2384+
if (argc >= 1) emit_int_expr(c, argv[0], &nb); /* poly size -> int (spinel-dev#24) */23852385
emit_indent(g_pre, g_indent);23862386
if (argc >= 1) { buf_printf(g_pre, "mrb_int _t%d = ", tn); buf_puts(g_pre, nb.p ? nb.p : "0"); buf_puts(g_pre, ";\n"); }23872387
else { buf_printf(g_pre, "mrb_int _t%d = 0;\n", tn); }@@ -2433,7 +2433,10 @@
24332433
const char *k = (at == TY_POLY_ARRAY) ? "Poly" : array_kind(at);24342434
if (k) {24352435
int tn = ++g_tmp, tv = ++g_tmp, tr = ++g_tmp, ti = ++g_tmp;2436-
Buf nb; memset(&nb, 0, sizeof nb); emit_expr(c, argv[0], &nb);2436+
/* The size goes into an `mrb_int` temp; coerce a poly size expression2437+
(e.g. `nrows * ncols` where a factor widened to poly -> sp_poly_mul,2438+
which returns sp_RbVal) through sp_poly_to_i. spinel-dev#24. */2439+
Buf nb; memset(&nb, 0, sizeof nb); emit_int_expr(c, argv[0], &nb);24372440
Buf vb; memset(&vb, 0, sizeof vb); emit_expr(c, argv[1], &vb);24382441
emit_indent(g_pre, g_indent);24392442
buf_printf(g_pre, "mrb_int _t%d = ", tn); buf_puts(g_pre, nb.p ? nb.p : ""); buf_puts(g_pre, ";\n");test/array_new_poly_size.rbaddedView file
Loading diff…
test/array_new_poly_size.rb.expectedaddedView file
Loading diff…