Commit 758d6bba
758d6bba0454Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
feat(codegen): poly arg into bigint helper + bigint into float context
Two more promote-mode coercions:
compile_bigint_arg: poly-typed arg (a method whose return slot ended up "poly" due to heterogeneous body — Mixer / Noise / Pulsesamplein optcarrot) is unboxed via.v.ithen re-boxed into sp_Bigint *. Previously the catch-allsp_bigint_new_int(<poly_val>)cast tripped C compile.compile_arg0_as_floatand theComplex.polarFFI arm: bigint args now unbox viasp_bigint_to_int(...)before the(mrb_float)cast. C rejects struct-to-double casts; this path was the last optcarrot C compile error.
Optcarrot --int-overflow=promote: C compile now succeeds (0 errors). Binary runs but segfaults at runtime -- next phase covers that.
Default raise: 631/0/0. Optcarrot wrap checksum 59662 unchanged.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 758d6bba0454
- Parent
- 5ff1b0dd76ff
spinel_codegen.rbmodifiedView file
@@ -12963,9 +12963,18 @@
1296312963
arg_ids = get_args(args_id)1296412964
if arg_ids.length > 01296512965
ce = compile_expr(arg_ids[0])12966-
if infer_type(arg_ids[0]) == "poly"12966+
at_a0f = infer_type(arg_ids[0])12967+
if at_a0f == "poly"1296712968
return "sp_poly_to_f(" + ce + ")"1296812969
end12970+
# `--int-overflow=promote` widens int to sp_Bigint *; a float12971+
# context (FFI :float arg, Math.sin operand, etc.) needs the12972+
# mrb_float scalar. Unbox via sp_bigint_to_int and let the12973+
# implicit int -> double conversion finish the cast.12974+
if at_a0f == "bigint" || expr_emit_is_bigint(arg_ids[0]) == 112975+
@needs_bigint = 112976+
return "(mrb_float)sp_bigint_to_int((sp_Bigint *)" + ce + ")"12977+
end1296912978
return ce1297012979
end1297112980
end@@ -15441,6 +15450,14 @@
1544115450
# latent issue triggered by bigint inside begin/rescue.1544215451
return "(sp_Bigint *)" + val1544315452
end15453+
if at == "poly"15454+
# poly-typed source whose payload is an int (SP_TAG_INT). Unbox15455+
# via .v.i then re-box into sp_Bigint *. Common in optcarrot15456+
# where Mixer/Noise/Pulse `sample` methods end up with a "poly"15457+
# return slot because their bodies have heterogeneous tails.15458+
@needs_rb_value = 115459+
return "sp_bigint_new_int((" + val + ").v.i)"15460+
end1544415461
return "sp_bigint_new_int(" + val + ")"1544515462
end1544615463
end@@ -20300,13 +20317,21 @@
2030020317
if aargs_cp.length >= 22030120318
a0_e = compile_expr(aargs_cp[0])2030220319
a1_e = compile_expr(aargs_cp[1])20303-
if infer_type(aargs_cp[0]) == "poly"20320+
a0_t_cp = infer_type(aargs_cp[0])20321+
if a0_t_cp == "poly"2030420322
a0_e = "sp_poly_to_f(" + a0_e + ")"20323+
elsif a0_t_cp == "bigint" || expr_emit_is_bigint(aargs_cp[0]) == 120324+
@needs_bigint = 120325+
a0_e = "(mrb_float)sp_bigint_to_int((sp_Bigint *)" + a0_e + ")"2030520326
else2030620327
a0_e = "(mrb_float)(" + a0_e + ")"2030720328
end20308-
if infer_type(aargs_cp[1]) == "poly"20329+
a1_t_cp = infer_type(aargs_cp[1])20330+
if a1_t_cp == "poly"2030920331
a1_e = "sp_poly_to_f(" + a1_e + ")"20332+
elsif a1_t_cp == "bigint" || expr_emit_is_bigint(aargs_cp[1]) == 120333+
@needs_bigint = 120334+
a1_e = "(mrb_float)sp_bigint_to_int((sp_Bigint *)" + a1_e + ")"2031020335
else2031120336
a1_e = "(mrb_float)(" + a1_e + ")"2031220337
end