Commit a10021ea

a10021ea03feMerged

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

Description

fix(codegen): inlined LocalVariableOperatorWriteNode dispatches bigint ops

compile_stmt_with_block's LocalVariableOperatorWriteNode arm emitted raw C += / -= / *= against the renamed local, which on a promote-mode-widened sp_Bigint * slot tripped "invalid use of undefined type" since the bigint struct is opaque.

Add a bigint dispatch arm mirroring the InstanceVariableOperator WriteNode bigint branch: route +, -, * through sp_bigint_add / sub / mul, wrapping a raw mrb_int rhs through sp_bigint_new_int.

Also revert the earlier compile_yield_stmt unbox: block_params_ csig_for_body already promotes the function-pointer signature to sp_Bigint * when the yield arg's static type is bigint, so the call site can pass the raw bigint pointer through.

Promote-mode test count: 502 pass / 43 fail / 73 error -> 503 pass / 43 fail / 72 error. Default raise mode unchanged at 618 / 0 / 0.

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

Details

Commit
a10021ea03fe
Parent
304bb73a0913

spinel_codegen.rbmodifiedView file

@@ -34183,14 +34183,7 @@
3418334183 aids = get_args(args_id)
3418434184 k = 0
3418534185 while k < aids.length
34186- # The block's C ABI is `(mrb_int, ..., void *)`; promote-mode
34187- # widened args are sp_Bigint * locally and need unboxing.
34188- yarg_ev = compile_expr(aids[k])
34189- if infer_type(aids[k]) == "bigint"
34190- @needs_bigint = 1
34191- yarg_ev = "sp_bigint_to_int((sp_Bigint *)" + yarg_ev + ")"
34192- end
34193- emitted.push(yarg_ev)
34186+ emitted.push(compile_expr(aids[k]))
3419434187 k = k + 1
3419534188 end
3419634189 end
@@ -34508,6 +34501,25 @@
3450834501 rname = remap_local(lname, map_from, map_to)
3450934502 op = @nd_binop[nid]
3451034503 val = compile_expr_remap(@nd_expression[nid], map_from, map_to)
34504+ vt_lvo = find_var_type(lname)
34505+ # promote-mode-widened slot: route through sp_bigint_*.
34506+ if vt_lvo == "bigint"
34507+ @needs_bigint = 1
34508+ rhs_t_lvo = infer_type(@nd_expression[nid])
34509+ rhs_big_lvo = rhs_t_lvo == "bigint" ? "(sp_Bigint *)(" + val + ")" : "sp_bigint_new_int(" + val + ")"
34510+ if op == "+"
34511+ emit(" lv_" + rname + " = sp_bigint_add((sp_Bigint *)lv_" + rname + ", " + rhs_big_lvo + ");")
34512+ return
34513+ end
34514+ if op == "-"
34515+ emit(" lv_" + rname + " = sp_bigint_sub((sp_Bigint *)lv_" + rname + ", " + rhs_big_lvo + ");")
34516+ return
34517+ end
34518+ if op == "*"
34519+ emit(" lv_" + rname + " = sp_bigint_mul((sp_Bigint *)lv_" + rname + ", " + rhs_big_lvo + ");")
34520+ return
34521+ end
34522+ end
3451134523 if op == "+"
3451234524 emit(" lv_" + rname + " += " + val + ";")
3451334525 end