Commit 9f625d55

9f625d55a639Merged

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

Description

fix(codegen): bigint-typed attr/ivar op-assign uses sp_bigint_* helpers

Both compile_call_assign_typed (CallOperatorWriteNode -- obj.x OP= v) and the InstanceVariableOperatorWriteNode arm in compile_stmt fell through to raw C OP=, which on a bigint slot emits sp_Bigint * += long long int -- C rejects.

Add a bigint dispatch arm to both that:

  • routes + - * / % through the matching sp_bigint_* helper, wrapping a raw mrb_int rhs through sp_bigint_new_int.
  • unboxes both sides to mrb_int for bitwise/shift & | ^ << >>, reboxes the result through sp_bigint_new_int.

Promote-mode test count: 470 pass / 46 fail / 102 error -> 473 pass / 50 fail / 95 error. Default raise mode unchanged at 618 / 0 / 0.

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

Details

Commit
9f625d55a639
Parent
dea3ce875d95

spinel_codegen.rbmodifiedView file

@@ -25379,6 +25379,38 @@
2537925379 emit(" " + lhs + " = " + disp + ";")
2538025380 return
2538125381 end
25382+ # bigint-typed ivar in promote mode: route arithmetic through
25383+ # sp_bigint_* helpers, wrap an int rhs through sp_bigint_new_int.
25384+ if ivar_t == "bigint"
25385+ @needs_bigint = 1
25386+ rhs_t_iov = infer_type(@nd_expression[nid])
25387+ rhs_big_iov = rhs_t_iov == "bigint" ? "(sp_Bigint *)(" + val + ")" : "sp_bigint_new_int(" + val + ")"
25388+ if op == "+"
25389+ emit(" " + lhs + " = sp_bigint_add((sp_Bigint *)" + lhs + ", " + rhs_big_iov + ");")
25390+ return
25391+ end
25392+ if op == "-"
25393+ emit(" " + lhs + " = sp_bigint_sub((sp_Bigint *)" + lhs + ", " + rhs_big_iov + ");")
25394+ return
25395+ end
25396+ if op == "*"
25397+ emit(" " + lhs + " = sp_bigint_mul((sp_Bigint *)" + lhs + ", " + rhs_big_iov + ");")
25398+ return
25399+ end
25400+ if op == "/"
25401+ emit(" " + lhs + " = sp_bigint_div((sp_Bigint *)" + lhs + ", " + rhs_big_iov + ");")
25402+ return
25403+ end
25404+ if op == "%"
25405+ emit(" " + lhs + " = sp_bigint_mod((sp_Bigint *)" + lhs + ", " + rhs_big_iov + ");")
25406+ return
25407+ end
25408+ if op == "&" || op == "|" || op == "^" || op == "<<" || op == ">>"
25409+ rhs_int_iov = rhs_t_iov == "bigint" ? "sp_bigint_to_int(" + rhs_big_iov + ")" : "(" + val + ")"
25410+ emit(" " + lhs + " = sp_bigint_new_int(sp_bigint_to_int((sp_Bigint *)" + lhs + ") " + op + " " + rhs_int_iov + ");")
25411+ return
25412+ end
25413+ end
2538225414 # Bitwise / shift / arithmetic op-assigns map directly onto C
2538325415 # `OP=`. Without these arms `@a &= v`, `@a |= v`, etc. were
2538425416 # silently dropped — the function emit fell through with no
@@ -30244,6 +30276,38 @@
3024430276 tt + "->" + field + " = sp_str_concat(" + tt + "->" + field + ", (" + val + ")); }")
3024530277 return
3024630278 end
30279+ # bigint-typed attr in promote mode: route arithmetic / bitwise
30280+ # ops through the matching sp_bigint_* helper, wrapping a raw
30281+ # mrb_int rhs through sp_bigint_new_int first.
30282+ if ivar_t == "bigint"
30283+ @needs_bigint = 1
30284+ rhs_t = infer_type(@nd_expression[nid])
30285+ rhs_big = rhs_t == "bigint" ? "(sp_Bigint *)(" + val + ")" : "sp_bigint_new_int(" + val + ")"
30286+ big_op = ""
30287+ if op == "+"
30288+ big_op = "sp_bigint_add"
30289+ elsif op == "-"
30290+ big_op = "sp_bigint_sub"
30291+ elsif op == "*"
30292+ big_op = "sp_bigint_mul"
30293+ elsif op == "/"
30294+ big_op = "sp_bigint_div"
30295+ elsif op == "%"
30296+ big_op = "sp_bigint_mod"
30297+ end
30298+ if big_op != ""
30299+ emit(" { sp_" + cname + " *" + tt + " = " + rc + "; " +
30300+ tt + "->" + field + " = " + big_op + "((sp_Bigint *)" + tt + "->" + field + ", " + rhs_big + "); }")
30301+ return
30302+ end
30303+ # Bitwise ops (& | ^ << >>): unbox to mrb_int, apply C op, re-box.
30304+ if op == "&" || op == "|" || op == "^" || op == "<<" || op == ">>"
30305+ rhs_int = rhs_t == "bigint" ? "sp_bigint_to_int(" + rhs_big + ")" : "(" + val + ")"
30306+ emit(" { sp_" + cname + " *" + tt + " = " + rc + "; " +
30307+ tt + "->" + field + " = sp_bigint_new_int(sp_bigint_to_int((sp_Bigint *)" + tt + "->" + field + ") " + op + " " + rhs_int + "); }")
30308+ return
30309+ end
30310+ end
3024730311 if op == "%"
3024830312 emit(" { sp_" + cname + " *" + tt + " = " + rc + "; " +
3024930313 tt + "->" + field + " = sp_imod(" + tt + "->" + field + ", (" + val + ")); }")