Commit 7f17edd8
7f17edd888edMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 1 file · ~1 modified
Description
feat: add Numeric#step(limit, step) with block
Iterates from receiver to limit by step increments. Compiles to a for loop. Step defaults to 1 when not specified.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 7f17edd888ed
- Parent
- 8e03810bbf69
spinel_codegen.rbmodifiedView file
@@ -15295,6 +15295,37 @@
1529515295
end1529615296
end1529715297
15298+
if mname == "step"15299+
if @nd_block[nid] >= 0 && recv >= 015300+
old = @in_loop15301+
@in_loop = 115302+
rc = compile_expr(recv)15303+
args_id = @nd_arguments[nid]15304+
limit_val = "0"15305+
step_val = "1"15306+
if args_id >= 015307+
aargs = get_args(args_id)15308+
if aargs.length > 015309+
limit_val = compile_expr(aargs[0])15310+
end15311+
if aargs.length > 115312+
step_val = compile_expr(aargs[1])15313+
end15314+
end15315+
bp1 = get_block_param(nid, 0)15316+
if bp1 == ""15317+
bp1 = "_i"15318+
end15319+
emit(" for (lv_" + bp1 + " = " + rc + "; lv_" + bp1 + " <= " + limit_val + "; lv_" + bp1 + " += " + step_val + ") {")15320+
@indent = @indent + 115321+
compile_stmts_body(@nd_body[@nd_block[nid]])15322+
@indent = @indent - 115323+
emit(" }")15324+
@in_loop = old15325+
return 115326+
end15327+
end15328+
1529815329
if mname == "cycle"1529915330
if @nd_block[nid] >= 0 && recv >= 01530015331
old = @in_loop