Commit 22e605fc

22e605fc757bMerged

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

Description

codegen: convert a poly value to bigint via sp_poly_as_bigint, not sp_bigint_new_int

When a bigint slot is assigned a poly value (e.g. d = Bigint.new(@base) where @base widened to poly under promote), sp_bigint_new_int expects a raw mrb_int and rejects the sp_RbVal. Use sp_poly_as_bigint, which narrows a poly to a bigint (promoting a small int, unwrapping an existing bigint). Unblocks loop_bigint_return, int_overflow_promote, ffi_int_arg_bigint.

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

Details

Commit
22e605fc757b
Parent
7a968cd5a840

src/codegen_stmt.cmodifiedView file

@@ -507,6 +507,7 @@
507507 else if (lv && lv->type == TY_BIGINT) {
508508 TyKind vt = comp_ntype(c, v);
509509 if (vt == TY_BIGINT) emit_expr(c, v, b);
510+ else if (vt == TY_POLY) { buf_puts(b, "sp_poly_as_bigint("); emit_expr(c, v, b); buf_puts(b, ")"); }
510511 else { buf_puts(b, "sp_bigint_new_int("); emit_expr(c, v, b); buf_puts(b, ")"); }
511512 }
512513 else if (lv && lv->type == TY_POLY) {
@@ -560,7 +561,8 @@
560561 if (bfn) {
561562 TyKind vt = comp_ntype(c, v);
562563 buf_printf(b, "%s(", bfn); emit_local_ref(c, id, nm, b); buf_puts(b, ", ");
563- if (vt != TY_BIGINT) { buf_puts(b, "sp_bigint_new_int("); emit_expr(c, v, b); buf_puts(b, ")"); }
564+ if (vt == TY_POLY) { buf_puts(b, "sp_poly_as_bigint("); emit_expr(c, v, b); buf_puts(b, ")"); }
565+ else if (vt != TY_BIGINT) { buf_puts(b, "sp_bigint_new_int("); emit_expr(c, v, b); buf_puts(b, ")"); }
564566 else emit_expr(c, v, b);
565567 buf_puts(b, ");\n");
566568 return;