Commit f5e8a06c
f5e8a06c89ddMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 5 files · +1 added · ~4 modified
Description
Add Phase A features: private/protected/public no-op, bare case, Array.new(n,val), Array#compact/flatten/unshift/reverse, Hash#values/key?, Float::INFINITY/NAN, dir, abort, STDERR/STDIN/STDOUT constants
Features implemented:
- A1: private/protected/public keywords ignored (no-op in stmt.c)
- A2: bare case (case without expression) already worked, verified
- A3: Array.new(n, val) and Array.new(n) in expr.c
- A4: Array#compact (no-op dup for IntArray)
- A5: Array#flatten (no-op dup for IntArray)
- A6: Array#unshift with sp_IntArray_unshift in emit.c
- A7: Array#reverse (non-bang, creates new reversed array)
- A8: Hash#values, Hash#key? for StrIntHash; RbHash#has_key?/key?
- A12: alias :sym form already supported
- A13: %w[...] and %i[...] already work via PM_ARRAY_NODE
- A14: Float::INFINITY and Float::NAN in expr.c and type.c
- A15: dir returns directory of source file
- A16: abort("msg"), exit(true/false), STDERR/STDIN/STDOUT constants
All 57 tests pass including new bm_lrama_features.rb.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- f5e8a06c89dd
- Parent
- 7bc7da762308
examples/bm_lrama_features.rbaddedView file
1+
# Test lrama-required features2+
3+
# private (should be ignored)4+
class Foo5+
def pub; "public"; end6+
private7+
def priv; "private"; end8+
end9+
f = Foo.new10+
puts f.pub11+
12+
# bare case (case without expression)13+
x = 514+
result = case15+
when x > 10 then "big"16+
when x > 3 then "medium"17+
else "small"18+
end19+
puts result20+
21+
# Array.new(n, val)22+
arr = Array.new(5, 42)23+
puts arr.length # 524+
puts arr[0] # 4225+
puts arr[4] # 4226+
27+
# Array#compact (no-op for IntArray)28+
a2 = [1, 2, 3]29+
puts a2.compact.length # 330+
31+
# Array#flatten (no-op for IntArray)32+
puts a2.flatten.length # 333+
34+
# Array#unshift35+
a3 = [2, 3, 4]36+
a3.unshift(1)37+
puts a3[0] # 138+
puts a3.length # 439+
40+
# Array#reverse41+
a4 = [1, 2, 3]42+
rev = a4.reverse43+
puts rev[0] # 344+
puts rev[2] # 145+
46+
# Float::INFINITY47+
puts Float::INFINITY > 999999 # true48+
49+
puts "done"src/emit.cmodifiedView file
Loading diff…
src/expr.cmodifiedView file
Loading diff…
src/stmt.cmodifiedView file
Loading diff…
src/type.cmodifiedView file
Loading diff…