Commit 246c0e94
246c0e942b4bMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 3 files · +1 added · ~2 modified
Description
Add case/when, unless, next, default args, const char * strings
New features:
- case/when: both statement and expression context, with integer matching, multiple values (when 2, 3), range matching (when 4..6), and else clause
- unless: compiles to if (!(cond))
- next: compiles to continue (in loops)
- Default parameter values: def greet(name, greeting = "Hello") fills defaults at call sites when fewer args passed
- const char * for SPINEL_TYPE_STRING (standalone string handling)
Test: examples/bm_case.rb exercises all patterns. All regressions pass.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 246c0e942b4b
- Parent
- 3897a383f61a
examples/bm_case.rbaddedView file
1+
# Test case/when, unless, next, default args2+
3+
def describe(n)4+
case n5+
when 16+
"one"7+
when 2, 38+
"two or three"9+
when 4..610+
"four to six"11+
else12+
"other"13+
end14+
end15+
16+
puts describe(1)17+
puts describe(3)18+
puts describe(5)19+
puts describe(9)20+
21+
# unless22+
x = 1023+
unless x > 2024+
puts "small"25+
end26+
27+
# next in loop28+
total = 029+
i = 030+
while i < 1031+
i += 132+
next if i % 3 == 033+
total += i34+
end35+
puts total # 1+2+4+5+7+8+10 = 3736+
37+
# default args38+
def greet(name, greeting = "Hello")39+
puts greeting40+
puts name41+
end42+
greet("world")43+
greet("Ruby", "Hi")src/codegen.cmodifiedView file
Loading diff…
src/codegen.hmodifiedView file
Loading diff…