Commit 3dad6a2f

3dad6a2f4392Merged

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

Description

fix(codegen): step block wraps loop counter into bigint slot when promoted

compile_step_block emitted for (lv_i = start; lv_i <= limit; lv_i += step) directly into the function-level LV, so a promote- mode-widened lv_i: sp_Bigint * slot tripped the C compiler on the <= comparison and the += step arithmetic.

Mirror the for/times/downto/range fixes: when find_var_type(bp) returns bigint, allocate a fresh mrb_int counter and box into the LV on each iteration via sp_bigint_new_int(counter).

Promote-mode test count: 480 pass / 54 fail / 84 error -> 480 pass / 55 fail / 83 error. Default raise mode unchanged at 618 / 0 / 0.

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

Details

Commit
3dad6a2f4392
Parent
f4e69c34cfdc

spinel_codegen.rbmodifiedView file

@@ -28098,10 +28098,18 @@
2809828098 emit(" {")
2809928099 emit(" mrb_int lv_" + bp1 + " = 0;")
2810028100 end
28101- emit(" for (lv_" + bp1 + " = " + rc + "; lv_" + bp1 + " <= " + limit_val + "; lv_" + bp1 + " += " + step_val + ") {")
28101+ bp_t_st = find_var_type(bp1)
28102+ if bp_t_st == "bigint"
28103+ @needs_bigint = 1
28104+ stmp_st = new_temp
28105+ emit(" for (mrb_int " + stmp_st + " = " + rc + "; " + stmp_st + " <= " + limit_val + "; " + stmp_st + " += " + step_val + ") {")
28106+ emit(" lv_" + bp1 + " = sp_bigint_new_int(" + stmp_st + ");")
28107+ else
28108+ emit(" for (lv_" + bp1 + " = " + rc + "; lv_" + bp1 + " <= " + limit_val + "; lv_" + bp1 + " += " + step_val + ") {")
28109+ end
2810228110 @indent = @indent + 1
2810328111 push_scope
28104- declare_var(bp1, "int")
28112+ declare_var(bp1, bp_t_st == "bigint" ? "bigint" : "int")
2810528113 redo_label = push_redo_label
2810628114 emit_redo_label(redo_label)
2810728115 compile_stmts_body(@nd_body[@nd_block[nid]])