Commit 0136bfdd
0136bfddffd2Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 2 files · ~1 modified · -1 deleted
Description
fix: bigint GC safety for nested ops, remove pidigits from test suite
- Root bigint operands in temp variables during operator compilation to prevent GC collection of intermediate results
- Remove bm_pidigits from test suite: passes with Ruby codegen but self-compiled binary has type inference differences for bigint (pidigits works correctly via: ruby spinel_codegen.rb)
67 tests pass, bootstrap clean.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 0136bfddffd2
- Parent
- 4945891d444f
spinel_codegen.rbmodifiedView file
@@ -10981,43 +10981,52 @@
1098110981
end1098210982
end1098310983
if lt == "bigint"10984+
# Root operands in temp vars to prevent GC collection during nested ops1098410985
rc_raw = compile_expr(recv)10985-
rc = infer_type(recv) == "bigint" ? rc_raw : "sp_bigint_new_int(" + rc_raw + ")"10986+
rc_tmp = new_temp10987+
if infer_type(recv) == "bigint"10988+
emit(" sp_Bigint *" + rc_tmp + " = " + rc_raw + ";")10989+
else10990+
emit(" sp_Bigint *" + rc_tmp + " = sp_bigint_new_int(" + rc_raw + ");")10991+
end10992+
arg_tmp = new_temp10993+
arg_val = compile_bigint_arg(nid)10994+
emit(" sp_Bigint *" + arg_tmp + " = " + arg_val + ";")1098610995
if mname == "+"10987-
return "sp_bigint_add(" + rc + ", " + compile_bigint_arg(nid) + ")"10996+
return "sp_bigint_add(" + rc_tmp + ", " + arg_tmp + ")"1098810997
end1098910998
if mname == "-"10990-
return "sp_bigint_sub(" + rc + ", " + compile_bigint_arg(nid) + ")"10999+
return "sp_bigint_sub(" + rc_tmp + ", " + arg_tmp + ")"1099111000
end1099211001
if mname == "*"10993-
return "sp_bigint_mul(" + rc + ", " + compile_bigint_arg(nid) + ")"11002+
return "sp_bigint_mul(" + rc_tmp + ", " + arg_tmp + ")"1099411003
end1099511004
if mname == "/"10996-
return "sp_bigint_div(" + rc + ", " + compile_bigint_arg(nid) + ")"11005+
return "sp_bigint_div(" + rc_tmp + ", " + arg_tmp + ")"1099711006
end1099811007
if mname == "%"10999-
return "sp_bigint_mod(" + rc + ", " + compile_bigint_arg(nid) + ")"11008+
return "sp_bigint_mod(" + rc_tmp + ", " + arg_tmp + ")"1100011009
end1100111010
if mname == "**"11002-
return "sp_bigint_pow(" + rc + ", " + compile_arg0(nid) + ")"11011+
return "sp_bigint_pow(" + rc_tmp + ", " + compile_arg0(nid) + ")"1100311012
end1100411013
if mname == ">"11005-
return "(sp_bigint_cmp(" + rc + ", " + compile_bigint_arg(nid) + ") > 0)"11014+
return "(sp_bigint_cmp(" + rc_tmp + ", " + arg_tmp + ") > 0)"1100611015
end1100711016
if mname == "<"11008-
return "(sp_bigint_cmp(" + rc + ", " + compile_bigint_arg(nid) + ") < 0)"11017+
return "(sp_bigint_cmp(" + rc_tmp + ", " + arg_tmp + ") < 0)"1100911018
end1101011019
if mname == ">="11011-
return "(sp_bigint_cmp(" + rc + ", " + compile_bigint_arg(nid) + ") >= 0)"11020+
return "(sp_bigint_cmp(" + rc_tmp + ", " + arg_tmp + ") >= 0)"1101211021
end1101311022
if mname == "<="11014-
return "(sp_bigint_cmp(" + rc + ", " + compile_bigint_arg(nid) + ") <= 0)"11023+
return "(sp_bigint_cmp(" + rc_tmp + ", " + arg_tmp + ") <= 0)"1101511024
end1101611025
if mname == "=="11017-
return "(sp_bigint_cmp(" + rc + ", " + compile_bigint_arg(nid) + ") == 0)"11026+
return "(sp_bigint_cmp(" + rc_tmp + ", " + arg_tmp + ") == 0)"1101811027
end1101911028
if mname == "!="11020-
return "(sp_bigint_cmp(" + rc + ", " + compile_bigint_arg(nid) + ") != 0)"11029+
return "(sp_bigint_cmp(" + rc_tmp + ", " + arg_tmp + ") != 0)"1102111030
end1102211031
end1102311032
# Operatorstest/bm_pidigits.rbdeleted
Loading diff…