Commit 6ee8a675
6ee8a675b277Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
Merge pull request #90 from mame/pr/array-mul
feat(codegen): support Array#* (repeat) for typed arrays
Details
- Commit
- 6ee8a675b277
- Parent
- 667be99671bf
- Merge parent
- d161a0dbbf31
spinel_codegen.rbmodifiedView file
@@ -1726,6 +1726,10 @@
17261726
if lt == "poly"17271727
return "poly"17281728
end1729+
if is_array_type(lt) == 11730+
# Array#* (repeat) yields another array of the same element type.1731+
return lt1732+
end17291733
# Check RHS for float promotion17301734
args_id = @nd_arguments[nid]17311735
if args_id >= 0@@ -3559,6 +3563,19 @@
35593563
035603564
end35613565
3566+
# Set the right @needs_<runtime> flag for the given array type.3567+
def mark_array_runtime_needs(t)3568+
if t == "float_array"3569+
@needs_float_array = 13570+
elsif t == "str_array"3571+
@needs_str_array = 13572+
elsif t == "poly_array"3573+
@needs_rb_value = 13574+
else3575+
@needs_int_array = 13576+
end3577+
end3578+
35623579
# ---- Collection pass ----35633580
def collect_all35643581
root = @root_id@@ -13908,6 +13925,22 @@
1390813925
@needs_rb_value = 11390913926
return "sp_poly_mul(" + compile_expr(recv) + ", " + box_expr_to_poly(get_args(@nd_arguments[nid])[0]) + ")"1391013927
end13928+
if is_array_type(lt) == 113929+
# All array kinds expose `_new` / `_length` / `_get` / `_push` with13930+
# the same shape, so the repeat loop is a single template13931+
# parameterized by the C prefix.13932+
mark_array_runtime_needs(lt)13933+
@needs_gc = 113934+
pfx = array_c_prefix(lt)13935+
tmp = new_temp13936+
src = new_temp13937+
cnt = new_temp13938+
emit(" sp_" + pfx + " *" + src + " = " + compile_expr(recv) + ";")13939+
emit(" mrb_int " + cnt + " = " + compile_arg0(nid) + ";")13940+
emit(" sp_" + pfx + " *" + tmp + " = sp_" + pfx + "_new();")13941+
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)); } }")13942+
return tmp13943+
end1391113944
return "(" + compile_expr(recv) + " * " + compile_arg0(nid) + ")"1391213945
end1391313946
if mname == "/"test/array_mul.rbaddedView file
Loading diff…