Commit 8d18c5bd
8d18c5bdc9b9Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 5 files · +1 added · ~4 modified
Description
Implement non-local return from blocks (block return via longjmp)
When return appears inside a block passed to a yield function,
it now correctly returns from the enclosing method using longjmp.
Mechanism:
- block_has_return() detects PM_RETURN_NODE in block bodies
- Block env gets _blk_ret_val/_blk_ret_depth fields
- Call site wraps yield with setjmp; block return does longjmp(3)
- Distinguishes from exceptions (1) and throw (2)
throw benchmark: Spinel 0.03s vs CRuby 0.29s (10x faster) 70/70 tests pass.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 8d18c5bdc9b9
- Parent
- d559e8076432
examples/bm_throw.rbaddedView file
1+
def foo2+
yield3+
end4+
5+
def bar6+
foo { return 1 }7+
end8+
9+
total = 010+
i = 011+
while i < 20000012+
total = total + bar13+
total = total + bar14+
total = total + bar15+
total = total + bar16+
total = total + bar17+
total = total + bar18+
total = total + bar19+
total = total + bar20+
total = total + bar21+
total = total + bar22+
i = i + 123+
end24+
puts total25+
puts "done"src/codegen.cmodifiedView file
Loading diff…
src/codegen.hmodifiedView file
Loading diff…
src/expr.cmodifiedView file
Loading diff…
src/stmt.cmodifiedView file
Loading diff…