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 matchingsp_bigint_*helper, wrapping a raw mrb_int rhs throughsp_bigint_new_int. - unboxes both sides to mrb_int for bitwise/shift
& | ^ << >>, reboxes the result throughsp_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
return2538125381
end25382+
# bigint-typed ivar in promote mode: route arithmetic through25383+
# sp_bigint_* helpers, wrap an int rhs through sp_bigint_new_int.25384+
if ivar_t == "bigint"25385+
@needs_bigint = 125386+
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+
return25391+
end25392+
if op == "-"25393+
emit(" " + lhs + " = sp_bigint_sub((sp_Bigint *)" + lhs + ", " + rhs_big_iov + ");")25394+
return25395+
end25396+
if op == "*"25397+
emit(" " + lhs + " = sp_bigint_mul((sp_Bigint *)" + lhs + ", " + rhs_big_iov + ");")25398+
return25399+
end25400+
if op == "/"25401+
emit(" " + lhs + " = sp_bigint_div((sp_Bigint *)" + lhs + ", " + rhs_big_iov + ");")25402+
return25403+
end25404+
if op == "%"25405+
emit(" " + lhs + " = sp_bigint_mod((sp_Bigint *)" + lhs + ", " + rhs_big_iov + ");")25406+
return25407+
end25408+
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+
return25412+
end25413+
end2538225414
# Bitwise / shift / arithmetic op-assigns map directly onto C2538325415
# `OP=`. Without these arms `@a &= v`, `@a |= v`, etc. were2538425416
# silently dropped — the function emit fell through with no@@ -30244,6 +30276,38 @@
3024430276
tt + "->" + field + " = sp_str_concat(" + tt + "->" + field + ", (" + val + ")); }")3024530277
return3024630278
end30279+
# bigint-typed attr in promote mode: route arithmetic / bitwise30280+
# ops through the matching sp_bigint_* helper, wrapping a raw30281+
# mrb_int rhs through sp_bigint_new_int first.30282+
if ivar_t == "bigint"30283+
@needs_bigint = 130284+
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+
end30298+
if big_op != ""30299+
emit(" { sp_" + cname + " *" + tt + " = " + rc + "; " +30300+
tt + "->" + field + " = " + big_op + "((sp_Bigint *)" + tt + "->" + field + ", " + rhs_big + "); }")30301+
return30302+
end30303+
# 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+
return30309+
end30310+
end3024730311
if op == "%"3024830312
emit(" { sp_" + cname + " *" + tt + " = " + rc + "; " +3024930313
tt + "->" + field + " = sp_imod(" + tt + "->" + field + ", (" + val + ")); }")