Commit 145d121f
145d121fb15cMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
fix(codegen): bigint bitwise ops + ivar op-write expression form
Two related fixes:
-
compile_operator_expr's bigint branch handled+ - * / % >= ==but not& | ^ << >>, sobigint & 0xfffell through to the general int path and emitted raw C&. Add a bitwise arm that unboxes both sides viasp_bigint_to_int, applies the C op, and reboxes viasp_bigint_new_int. Guard oninfer_type(recv) == "bigint"to avoid catching the poly-recv shape whereltis inferred bigint only because the arg is bigint. -
compile_expr'sInstanceVariableOperatorWriteNodearm (used as the rhs of chained@b = @a &= 0x80) emitted(iv_a &= 128LL)raw. Mirror the compile_stmt arm: when the ivar slot is bigint, route arithmetic through sp_bigint_add / sub / mul / div / mod and bitwise through the unbox-rebox shape.
Promote-mode test count: 508 pass / 45 fail / 65 error -> 508 pass / 46 fail / 64 error. Default raise mode unchanged at 618 / 0 / 0.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 145d121fb15c
- Parent
- 76c4c2c1e64f
spinel_codegen.rbmodifiedView file
if disp_iow != "" return "(" + lhs_iow + " = " + disp_iow + ")" end # promote-mode bigint ivar: route arithmetic/bitwise through # sp_bigint_* helpers. Mirrors the compile_stmt InstanceVariable # OperatorWriteNode arm but returning the new slot value as the # expression's value. if ivar_t_iow == "bigint" @needs_bigint = 1 rhs_t_iow = infer_type(@nd_expression[nid]) rhs_big_iow = rhs_t_iow == "bigint" ? "(sp_Bigint *)(" + val_iow + ")" : "sp_bigint_new_int(" + val_iow + ")" big_op_iow = "" if op_iow == "+" big_op_iow = "sp_bigint_add" elsif op_iow == "-" big_op_iow = "sp_bigint_sub" elsif op_iow == "*" big_op_iow = "sp_bigint_mul" elsif op_iow == "/" big_op_iow = "sp_bigint_div" elsif op_iow == "%" big_op_iow = "sp_bigint_mod" end if big_op_iow != "" return "(" + lhs_iow + " = " + big_op_iow + "((sp_Bigint *)" + lhs_iow + ", " + rhs_big_iow + "))" end if op_iow == "&" || op_iow == "|" || op_iow == "^" || op_iow == "<<" || op_iow == ">>" rhs_int_iow = rhs_t_iow == "bigint" ? "sp_bigint_to_int(" + rhs_big_iow + ")" : "(" + val_iow + ")" return "(" + lhs_iow + " = sp_bigint_new_int(sp_bigint_to_int((sp_Bigint *)" + lhs_iow + ") " + op_iow + " " + rhs_int_iow + "))" end end return "(" + lhs_iow + " " + op_iow + "= " + val_iow + ")" end if t == "LocalVariableOrWriteNode" if mname == "!=" return "(sp_bigint_cmp(" + rc + ", " + arg + ") != 0)" end # Bitwise / shift on a bigint recv: unbox to mrb_int, apply # native op, rebox. Only when the receiver is genuinely bigint # (not poly widened to share this `lt == bigint` block via the # arg-side bigint check above) — poly recv shifts dispatch # through a different runtime path. if (mname == "&" || mname == "|" || mname == "^" || mname == "<<" || mname == ">>") && infer_type(recv) == "bigint" return "sp_bigint_new_int(sp_bigint_to_int(" + rc + ") " + mname + " sp_bigint_to_int(" + arg + "))" end end # Operators if mname == "**" || mname == "pow"