Commit 6858360b
6858360b70dfMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 3 files · +1 added · ~2 modified
Description
Add keyword arguments and rest/splat parameters
Keyword args: def greet(name:, greeting: "Hello")
- RequiredKeywordParameterNode / OptionalKeywordParameterNode parsed
- Call sites with KeywordHashNode: match keys to params by name
- Missing optional keywords filled with defaults
- Type inference from call-site keyword values
Rest/splat: def sum(*nums)
- RestParameterNode parsed, rest param typed as sp_IntArray
- Call sites collect extra positional args into IntArray
- Function body uses rest param as normal array (each, length)
Test: examples/bm_kwargs.rb — keyword calls and splat, matches Ruby. All regressions pass.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 6858360b70df
- Parent
- 883d2093a2a0
examples/bm_kwargs.rbaddedView file
1+
# Test keyword arguments and splat2+
3+
def greet(name:, greeting: "Hello")4+
puts greeting5+
puts name6+
end7+
8+
greet(name: "world")9+
greet(name: "Ruby", greeting: "Hi")10+
11+
# Rest args (splat)12+
def sum(*nums)13+
total = 014+
nums.each do |n|15+
total += n16+
end17+
total18+
end19+
20+
puts sum(1, 2, 3) # 621+
puts sum(10, 20) # 30src/codegen.cmodifiedView file
Loading diff…
src/codegen.hmodifiedView file
Loading diff…