Commit 3e29d59b

3e29d59bdf3eMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 2 files · +1 added · ~1 modified

Description

feat: Enumerable module with yield-based each and block callbacks

Support class methods that use yield with caller-provided blocks:

  • Detect yield in method bodies (including inside nested blocks)
  • Add sp_block_fn/_block_env params to methods that use yield
  • Generate block callback functions with captured variables via #define aliases for pointer-based mutation
  • Object method dispatch with block: scan captures, generate env struct, create callback, pass to method
  • Fix has_yield_nodes to recurse into call block bodies
  • Fix implicit_return leaking into Array#each block body codegen
  • Update forward declarations to include block params

Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]

Details

Commit
3e29d59bdf3e
Parent
6f84ed92e8c5

examples/bm_enumerable.rbaddedView file

1+class NumberList
2+ include Enumerable
3+ def initialize
4+ @data = (1..5).to_a
5+ end
6+ def each
7+ @data.each do |x|
8+ yield x
9+ end
10+ end
11+end
12+
13+list = NumberList.new
14+total = 0
15+list.each do |x|
16+ total += x
17+end
18+puts total # 15
19+puts "done"