Commit 53baf10d
53baf10d46cfMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 7 files · +6 added · ~1 modified
Description
Merge pull request #355 from mame/pr/poly-int-auto-unify-arith
fix(codegen): auto-unbox poly arg in arithmetic / bit operators with primitive recv
Details
- Commit
- 53baf10d46cf
- Parent
- f6b89b028b0c
- Merge parent
- c8aa00eb07f1
spinel_codegen.rbmodifiedView file
@@ -22696,7 +22696,7 @@
2269622696
end2269722697
end2269822698
if lt == "int"22699-
return "((mrb_int)pow((double)" + compile_expr(recv) + ", (double)" + compile_arg0(nid) + "))"22699+
return "((mrb_int)pow((double)" + compile_expr(recv) + ", (double)" + compile_arg0_as_int(nid) + "))"2270022700
end2270122701
return "pow(" + compile_expr(recv) + ", " + compile_arg0(nid) + ")"2270222702
end@@ -22767,7 +22767,7 @@
2276722767
emit(" sp_" + pfx + "_push(" + tmp + ", sp_" + pfx + "_get(" + arg + ", " + itmp + "));")2276822768
return tmp2276922769
end22770-
return "(" + compile_expr(recv) + " + " + compile_arg0(nid) + ")"22770+
return "(" + compile_expr(recv) + " + " + compile_arg0_as_int(nid) + ")"2277122771
end2277222772
if mname == "-"2277322773
lt = infer_type(recv)@@ -22796,7 +22796,7 @@
2279622796
if r != ""2279722797
return r2279822798
end22799-
return "(" + compile_expr(recv) + " - " + compile_arg0(nid) + ")"22799+
return "(" + compile_expr(recv) + " - " + compile_arg0_as_int(nid) + ")"2280022800
end2280122801
if mname == "*"2280222802
lt = infer_type(recv)@@ -22823,7 +22823,7 @@
2282322823
emit(" { mrb_int _mi; mrb_int _sl = sp_" + pfx + "_length(" + src + "); for (_mi = 0; _mi < " + cnt + "; _mi++) { mrb_int _mj; for (_mj = 0; _mj < _sl; _mj++) sp_" + pfx + "_push(" + tmp + ", sp_" + pfx + "_get(" + src + ", _mj)); } }")2282422824
return tmp2282522825
end22826-
return "(" + compile_expr(recv) + " * " + compile_arg0(nid) + ")"22826+
return "(" + compile_expr(recv) + " * " + compile_arg0_as_int(nid) + ")"2282722827
end2282822828
if mname == "/"2282922829
lt = infer_type(recv)@@ -22845,7 +22845,7 @@
2284522845
end2284622846
end2284722847
end22848-
return "sp_idiv(" + compile_expr(recv) + ", " + compile_arg0(nid) + ")"22848+
return "sp_idiv(" + compile_expr(recv) + ", " + compile_arg0_as_int(nid) + ")"2284922849
end2285022850
if mname == "%"2285122851
lt = infer_type(recv)@@ -22925,7 +22925,7 @@
2292522925
return "sp_sprintf(" + fmt_c + ", (long long)" + compile_expr(arg0) + ")"2292622926
end2292722927
end22928-
return "sp_imod(" + compile_expr(recv) + ", " + compile_arg0(nid) + ")"22928+
return "sp_imod(" + compile_expr(recv) + ", " + compile_arg0_as_int(nid) + ")"2292922929
end2293022930
if mname == "<"2293122931
lt = infer_type(recv)@@ -23103,14 +23103,14 @@
2310323103
@needs_rb_value = 12310423104
return "sp_poly_shl(" + compile_expr(recv) + ", " + box_expr_to_poly(get_args(@nd_arguments[nid])[0]) + ")"2310523105
end23106-
return "(" + compile_expr(recv) + " << " + compile_arg0(nid) + ")"23106+
return "(" + compile_expr(recv) + " << " + compile_arg0_as_int(nid) + ")"2310723107
end2310823108
if mname == ">>"2310923109
if infer_type(recv) == "poly"2311023110
@needs_rb_value = 12311123111
return "sp_poly_shr(" + compile_expr(recv) + ", " + box_expr_to_poly(get_args(@nd_arguments[nid])[0]) + ")"2311223112
end23113-
return "(" + compile_expr(recv) + " >> " + compile_arg0(nid) + ")"23113+
return "(" + compile_expr(recv) + " >> " + compile_arg0_as_int(nid) + ")"2311423114
end2311523115
if mname == "&"2311623116
lt = infer_type(recv)@@ -23122,7 +23122,7 @@
2312223122
if r != ""2312323123
return r2312423124
end23125-
return "(" + compile_expr(recv) + " & " + compile_arg0(nid) + ")"23125+
return "(" + compile_expr(recv) + " & " + compile_arg0_as_int(nid) + ")"2312623126
end2312723127
if mname == "|"2312823128
lt = infer_type(recv)@@ -23134,14 +23134,14 @@
2313423134
if r != ""2313523135
return r2313623136
end23137-
return "(" + compile_expr(recv) + " | " + compile_arg0(nid) + ")"23137+
return "(" + compile_expr(recv) + " | " + compile_arg0_as_int(nid) + ")"2313823138
end2313923139
if mname == "^"2314023140
if infer_type(recv) == "poly"2314123141
@needs_rb_value = 12314223142
return "sp_poly_bxor(" + compile_expr(recv) + ", " + box_expr_to_poly(get_args(@nd_arguments[nid])[0]) + ")"2314323143
end23144-
return "(" + compile_expr(recv) + " ^ " + compile_arg0(nid) + ")"23144+
return "(" + compile_expr(recv) + " ^ " + compile_arg0_as_int(nid) + ")"2314523145
end2314623146
if mname == "~"2314723147
return "(~" + compile_expr(recv) + ")"@@ -29019,9 +29019,11 @@
2901929019
# (matches `to_i` semantics for poly).2902029020
if rhs_t == "poly" && (vt == "int" || vt == "bool")2902129021
val = "(" + val + ").v.i"29022+
rhs_t = vt2902229023
end2902329024
if rhs_t == "poly" && vt == "float"2902429025
val = "(" + val + ").v.f"29026+
rhs_t = vt2902529027
end2902629028
emit(" " + vref + " = " + val + ";")2902729029
endtest/auto_unbox_keeps_int_slot.rbaddedView file
Loading diff…
test/auto_unbox_keeps_int_slot.rb.expectedaddedView file
Loading diff…
test/poly_int_arith_auto_unify.rbaddedView file
Loading diff…
test/poly_int_arith_auto_unify.rb.expectedaddedView file
Loading diff…
test/poly_int_bitops_auto_unify.rbaddedView file
Loading diff…
test/poly_int_bitops_auto_unify.rb.expectedaddedView file
Loading diff…