Commit dbd67a42

dbd67a423fd8Merged

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

Description

fix(codegen): map_expr times/range arms wrap loop counter for bigint slot

compile_map_expr's N.times.map and range .map fusion arms emitted lv_<bp> = <counter>; directly. With promote mode widening the block param's outer slot to bigint, the assignment failed at the C-level pointer/int boundary. Probe find_var_type before declare_var and wrap through sp_bigint_new_int when the slot is bigint. The block-scope declare_var also follows the outer slot type so the body's arithmetic dispatches through sp_bigint_mul instead of sp_int_mul.

Also unbox a bigint block tail before sp_IntArray_push in the range-map arm.

Promote-mode test count: 518 pass / 48 fail / 52 error (unchanged, but range / map paths now emit correct bigint, reducing latent breakage once other paths catch up). Default raise mode unchanged at 618 / 0 / 0.

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

Details

Commit
dbd67a423fd8
Parent
7f4aabe11729

spinel_codegen.rbmodifiedView file

@@ -32989,7 +32989,13 @@
3298932989 emit(" SP_GC_ROOT(" + tmp_arrn + ");")
3299032990 emit(" for (mrb_int " + tmp_in + " = 0; " + tmp_in + " < " + ncount + "; " + tmp_in + "++) {")
3299132991 if bpn != ""
32992- emit(" lv_" + bpn + " = " + tmp_in + ";")
32992+ bpn_t_mp = find_var_type(bpn)
32993+ if bpn_t_mp == "bigint"
32994+ @needs_bigint = 1
32995+ emit(" lv_" + bpn + " = sp_bigint_new_int(" + tmp_in + ");")
32996+ else
32997+ emit(" lv_" + bpn + " = " + tmp_in + ";")
32998+ end
3299332999 end
3299433000 @indent = @indent + 1
3299533001 if blk_n >= 0
@@ -33336,8 +33342,17 @@
3333633342 emit(" for (mrb_int " + tmp_i + " = " + first_e + "; " + tmp_i + " " + excl + " " + last_e + "; " + tmp_i + "++) {")
3333733343 have_bp_r = (get_block_param(nid, 0) != "")
3333833344 if have_bp_r
33339- declare_var(bp1, "int")
33340- emit(" lv_" + bp1 + " = " + tmp_i + ";")
33345+ bp1_t_rng = find_var_type(bp1)
33346+ if bp1_t_rng != "bigint"
33347+ bp1_t_rng = "int"
33348+ end
33349+ declare_var(bp1, bp1_t_rng)
33350+ if bp1_t_rng == "bigint"
33351+ @needs_bigint = 1
33352+ emit(" lv_" + bp1 + " = sp_bigint_new_int(" + tmp_i + ");")
33353+ else
33354+ emit(" lv_" + bp1 + " = " + tmp_i + ";")
33355+ end
3334133356 end
3334233357 @indent = @indent + 1
3334333358 if blk_r >= 0
@@ -33364,6 +33379,12 @@
3336433379 emit(" sp_PtrArray_push(" + tmp_arr + ", (void *)" + lastv_r + ");")
3336533380 end
3336633381 else
33382+ # promote-mode block tail returning bigint into IntArray;
33383+ # unbox before pushing.
33384+ if infer_type(stmts_r2.last) == "bigint"
33385+ @needs_bigint = 1
33386+ lastv_r = "sp_bigint_to_int((sp_Bigint *)" + lastv_r + ")"
33387+ end
3336733388 emit(" sp_IntArray_push(" + tmp_arr + ", " + lastv_r + ");")
3336833389 end
3336933390 else