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 features
2+
3+# private (should be ignored)
4+class Foo
5+ def pub; "public"; end
6+ private
7+ def priv; "private"; end
8+end
9+f = Foo.new
10+puts f.pub
11+
12+# bare case (case without expression)
13+x = 5
14+result = case
15+ when x > 10 then "big"
16+ when x > 3 then "medium"
17+ else "small"
18+ end
19+puts result
20+
21+# Array.new(n, val)
22+arr = Array.new(5, 42)
23+puts arr.length # 5
24+puts arr[0] # 42
25+puts arr[4] # 42
26+
27+# Array#compact (no-op for IntArray)
28+a2 = [1, 2, 3]
29+puts a2.compact.length # 3
30+
31+# Array#flatten (no-op for IntArray)
32+puts a2.flatten.length # 3
33+
34+# Array#unshift
35+a3 = [2, 3, 4]
36+a3.unshift(1)
37+puts a3[0] # 1
38+puts a3.length # 4
39+
40+# Array#reverse
41+a4 = [1, 2, 3]
42+rev = a4.reverse
43+puts rev[0] # 3
44+puts rev[2] # 1
45+
46+# Float::INFINITY
47+puts Float::INFINITY > 999999 # true
48+
49+puts "done"