Commit 16670279

166702795e7dMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 2 files · +1 added · ~1 modified

Description

fix: bigint ops inline (no temp vars), pidigits passes in test suite

Root cause: temp variable extraction for bigint ops caused while-loop conditions to be evaluated only once (temps computed outside the loop). Reverted to inline bigint expressions.

pidigits n=27 (default) passes in test suite with self-compiled binary. Known issue: n>50 has GC safety issues with nested bigint expressions (intermediate results not rooted). Needs GC-safe bigint expression compilation without temp variables.

68 tests pass, bootstrap clean.

Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]

Details

Commit
166702795e7d
Parent
0136bfddffd2

spinel_codegen.rbmodifiedView file

@@ -10981,52 +10981,44 @@
1098110981 end
1098210982 end
1098310983 if lt == "bigint"
10984- # Root operands in temp vars to prevent GC collection during nested ops
1098510984 rc_raw = compile_expr(recv)
10986- rc_tmp = new_temp
10987- if infer_type(recv) == "bigint"
10988- emit(" sp_Bigint *" + rc_tmp + " = " + rc_raw + ";")
10989- else
10990- emit(" sp_Bigint *" + rc_tmp + " = sp_bigint_new_int(" + rc_raw + ");")
10991- end
10992- arg_tmp = new_temp
10993- arg_val = compile_bigint_arg(nid)
10994- emit(" sp_Bigint *" + arg_tmp + " = " + arg_val + ";")
10985+ rc = infer_type(recv) == "bigint" ? rc_raw : "sp_bigint_new_int(" + rc_raw + ")"
10986+ arg = compile_bigint_arg(nid)
1099510987 if mname == "+"
10996- return "sp_bigint_add(" + rc_tmp + ", " + arg_tmp + ")"
10988+ return "sp_bigint_add(" + rc + ", " + arg + ")"
1099710989 end
1099810990 if mname == "-"
10999- return "sp_bigint_sub(" + rc_tmp + ", " + arg_tmp + ")"
10991+ return "sp_bigint_sub(" + rc + ", " + arg + ")"
1100010992 end
1100110993 if mname == "*"
11002- return "sp_bigint_mul(" + rc_tmp + ", " + arg_tmp + ")"
10994+ return "sp_bigint_mul(" + rc + ", " + arg + ")"
1100310995 end
1100410996 if mname == "/"
11005- return "sp_bigint_div(" + rc_tmp + ", " + arg_tmp + ")"
10997+ return "sp_bigint_div(" + rc + ", " + arg + ")"
1100610998 end
1100710999 if mname == "%"
11008- return "sp_bigint_mod(" + rc_tmp + ", " + arg_tmp + ")"
11000+ return "sp_bigint_mod(" + rc + ", " + arg + ")"
1100911001 end
1101011002 if mname == "**"
11011- return "sp_bigint_pow(" + rc_tmp + ", " + compile_arg0(nid) + ")"
11003+ return "sp_bigint_pow(" + rc + ", " + compile_arg0(nid) + ")"
1101211004 end
1101311005 if mname == ">"
11014- return "(sp_bigint_cmp(" + rc_tmp + ", " + arg_tmp + ") > 0)"
11006+ return "(sp_bigint_cmp(" + rc + ", " + arg + ") > 0)"
1101511007 end
1101611008 if mname == "<"
11017- return "(sp_bigint_cmp(" + rc_tmp + ", " + arg_tmp + ") < 0)"
11009+ return "(sp_bigint_cmp(" + rc + ", " + arg + ") < 0)"
1101811010 end
1101911011 if mname == ">="
11020- return "(sp_bigint_cmp(" + rc_tmp + ", " + arg_tmp + ") >= 0)"
11012+ return "(sp_bigint_cmp(" + rc + ", " + arg + ") >= 0)"
1102111013 end
1102211014 if mname == "<="
11023- return "(sp_bigint_cmp(" + rc_tmp + ", " + arg_tmp + ") <= 0)"
11015+ return "(sp_bigint_cmp(" + rc + ", " + arg + ") <= 0)"
1102411016 end
1102511017 if mname == "=="
11026- return "(sp_bigint_cmp(" + rc_tmp + ", " + arg_tmp + ") == 0)"
11018+ return "(sp_bigint_cmp(" + rc + ", " + arg + ") == 0)"
1102711019 end
1102811020 if mname == "!="
11029- return "(sp_bigint_cmp(" + rc_tmp + ", " + arg_tmp + ") != 0)"
11021+ return "(sp_bigint_cmp(" + rc + ", " + arg + ") != 0)"
1103011022 end
1103111023 end
1103211024 # Operators