Commit 24a87506
24a87506af5dMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 4 files · +2 added · ~2 modified
Description
codegen: Integer#magnitude/modulo/remainder/size/gcdlcm
Five Integer instance methods that fell through to the unresolved- call fallback (emitting 0). All are direct lowerings to existing helpers:
magnitude - alias for abs modulo - sp_imod (same as %) remainder - truncated-division remainder, differs from % for mixed-sign operands (-7.remainder(3) == -1) size - bytes per mrb_int = 8 (constant on 64-bit) gcdlcm - [gcd, lcm] tuple via the same path divmod uses
Refs #860 #873 #875 #876 #894
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 24a87506af5d
- Parent
- da7ca3b74f65
spinel_analyze.rbmodifiedView file
@@ -3769,7 +3769,10 @@
37693769
if mname == "allbits?" || mname == "anybits?" || mname == "nobits?"37703770
return 137713771
end3772-
if mname == "gcd" || mname == "lcm" || mname == "ceildiv" || mname == "div" || mname == "clamp"3772+
if mname == "gcd" || mname == "lcm" || mname == "gcdlcm" || mname == "ceildiv" || mname == "div" || mname == "clamp"3773+
return 13774+
end3775+
if mname == "magnitude" || mname == "modulo" || mname == "remainder" || mname == "size"37733776
return 137743777
end37753778
if mname == "itself" || mname == "then" || mname == "yield_self"@@ -4392,7 +4395,16 @@
43924395
if mname == "nil?"43934396
return "bool"43944397
end4395-
if mname == "abs"4398+
if mname == "abs" || mname == "magnitude"4399+
if recv >= 04400+
lt = infer_type(recv)4401+
if lt == "float"4402+
return "float"4403+
end4404+
end4405+
return "int"4406+
end4407+
if mname == "modulo" || mname == "remainder"43964408
if recv >= 043974409
lt = infer_type(recv)43984410
if lt == "float"@@ -4401,6 +4413,20 @@
44014413
end44024414
return "int"44034415
end4416+
# Integer#size: bytes used to represent the int. Spinel4417+
# mrb_int is always 64-bit, so it's a constant 8. Issue #860.4418+
if mname == "size" && recv >= 04419+
rt_sz = infer_type(recv)4420+
if rt_sz == "int"4421+
return "int"4422+
end4423+
end4424+
# Integer#gcdlcm returns [gcd, lcm] as a tuple value. Issue #894.4425+
if mname == "gcdlcm"4426+
tt_gl_inf = "tuple:int,int"4427+
register_tuple_type(tt_gl_inf)4428+
return "tuple:int,int"4429+
end44044430
if mname == "**" || mname == "pow"44054431
if recv >= 044064432
lt = infer_type(recv)spinel_codegen.rbmodifiedView file
Loading diff…
test/integer_extra_methods.rbaddedView file
Loading diff…
test/integer_extra_methods.rb.expectedaddedView file
Loading diff…