Commit 3804f3e7
3804f3e757bdMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 1 file · ~1 modified
Description
feat: add Array#zip with block
Iterates two arrays in parallel, yielding pairs to the block. Both block parameters inherit the receiver's element type.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 3804f3e757bd
- Parent
- 7f17edd888ed
spinel_codegen.rbmodifiedView file
@@ -9463,6 +9463,15 @@
94639463
else94649464
types.push("int")94659465
end9466+
elsif mname == "zip"9467+
# Both params get element type from receiver9468+
if recv_type == "str_array"9469+
types.push("string")9470+
elsif recv_type == "float_array"9471+
types.push("float")9472+
else9473+
types.push("int")9474+
end94669475
elsif mname == "each_with_index"94679476
if bk == 094689477
# Element@@ -15295,6 +15304,35 @@
1529515304
end1529615305
end1529715306
15307+
if mname == "zip"15308+
if @nd_block[nid] >= 0 && recv >= 015309+
old = @in_loop15310+
@in_loop = 115311+
rt = infer_type(recv)15312+
rc = compile_expr(recv)15313+
arg = compile_arg0(nid)15314+
bp1 = get_block_param(nid, 0)15315+
bp2 = get_block_param(nid, 1)15316+
if bp1 == ""15317+
bp1 = "_a"15318+
end15319+
if bp2 == ""15320+
bp2 = "_b"15321+
end15322+
pfx = array_c_prefix(rt)15323+
tmp_i = new_temp15324+
emit(" for (mrb_int " + tmp_i + " = 0; " + tmp_i + " < sp_" + pfx + "_length(" + rc + "); " + tmp_i + "++) {")15325+
emit(" lv_" + bp1 + " = sp_" + pfx + "_get(" + rc + ", " + tmp_i + ");")15326+
emit(" lv_" + bp2 + " = sp_" + pfx + "_get(" + arg + ", " + tmp_i + ");")15327+
@indent = @indent + 115328+
compile_stmts_body(@nd_body[@nd_block[nid]])15329+
@indent = @indent - 115330+
emit(" }")15331+
@in_loop = old15332+
return 115333+
end15334+
end15335+
1529815336
if mname == "step"1529915337
if @nd_block[nid] >= 0 && recv >= 01530015338
old = @in_loop