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 end
1529615296 end
1529715297
15298+ if mname == "step"
15299+ if @nd_block[nid] >= 0 && recv >= 0
15300+ old = @in_loop
15301+ @in_loop = 1
15302+ rc = compile_expr(recv)
15303+ args_id = @nd_arguments[nid]
15304+ limit_val = "0"
15305+ step_val = "1"
15306+ if args_id >= 0
15307+ aargs = get_args(args_id)
15308+ if aargs.length > 0
15309+ limit_val = compile_expr(aargs[0])
15310+ end
15311+ if aargs.length > 1
15312+ step_val = compile_expr(aargs[1])
15313+ end
15314+ end
15315+ bp1 = get_block_param(nid, 0)
15316+ if bp1 == ""
15317+ bp1 = "_i"
15318+ end
15319+ emit(" for (lv_" + bp1 + " = " + rc + "; lv_" + bp1 + " <= " + limit_val + "; lv_" + bp1 + " += " + step_val + ") {")
15320+ @indent = @indent + 1
15321+ compile_stmts_body(@nd_body[@nd_block[nid]])
15322+ @indent = @indent - 1
15323+ emit(" }")
15324+ @in_loop = old
15325+ return 1
15326+ end
15327+ end
15328+
1529815329 if mname == "cycle"
1529915330 if @nd_block[nid] >= 0 && recv >= 0
1530015331 old = @in_loop