rubinius-melbourne 2.1.0.0 → 2.2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/defs_spec.rb CHANGED
@@ -1,73 +1,96 @@
1
1
  describe "A Defs node" do
2
2
  parse <<-ruby do
3
- def self.x(y)
4
- (y + 1)
5
- end
3
+ def self.m() end
6
4
  ruby
7
5
 
8
- [:defs,
9
- [:self],
10
- :x,
11
- [:args, :y],
12
- [:scope, [:block, [:call, [:lvar, :y], :+, [:arglist, [:lit, 1]]]]]]
6
+ [:defs, [:self], :m, [:args], [:scope, [:block, [:nil]]]]
13
7
  end
14
8
 
15
9
  parse <<-ruby do
16
- def self.setup(ctx)
17
- bind = allocate
18
- bind.context = ctx
19
- return bind
20
- end
10
+ a = ""
11
+ def a.m() end
21
12
  ruby
22
13
 
23
- [:defs,
24
- [:self],
25
- :setup,
26
- [:args, :ctx],
27
- [:scope,
28
- [:block,
29
- [:lasgn, :bind, [:call, nil, :allocate, [:arglist]]],
30
- [:attrasgn, [:lvar, :bind], :context=, [:arglist, [:lvar, :ctx]]],
31
- [:return, [:lvar, :bind]]]]]
14
+ [:block,
15
+ [:lasgn, :a, [:str, ""]],
16
+ [:defs, [:lvar, :a], :m, [:args], [:scope, [:block, [:nil]]]]]
32
17
  end
33
18
 
34
19
  parse <<-ruby do
35
- def self.empty(*)
36
- end
20
+ a = ""
21
+ def (a.b).m() end
37
22
  ruby
38
23
 
39
- [:defs, [:self], :empty, [:args, :*], [:scope, [:block, [:nil]]]]
24
+ [:block,
25
+ [:lasgn, :a, [:str, ""]],
26
+ [:defs,
27
+ [:call, [:lvar, :a], :b, [:arglist]],
28
+ :m,
29
+ [:args],
30
+ [:scope, [:block, [:nil]]]]]
40
31
  end
41
32
 
42
33
  parse <<-ruby do
43
- def self.empty
44
- end
34
+ def x.m(a=1, (b, (c, *d), *e)) end
45
35
  ruby
46
36
 
47
- [:defs, [:self], :empty, [:args], [:scope, [:block, [:nil]]]]
37
+ [:defs,
38
+ [:call, nil, :x, [:arglist]],
39
+ :m,
40
+ [:args,
41
+ :a,
42
+ [:masgn,
43
+ [:array,
44
+ [:lasgn, :b],
45
+ [:masgn, [:array, [:lasgn, :c], [:splat, [:lasgn, :d]]]],
46
+ [:splat, [:lasgn, :e]]],
47
+ [:lvar, :"_:1"]],
48
+ [:block, [:lasgn, :a, [:lit, 1]]]],
49
+ [:scope, [:block, [:nil]]]]
48
50
  end
49
51
 
50
52
  parse <<-ruby do
51
- def (a.b).empty(*)
52
- end
53
+ def x.m(a, b=1, *c, d, e:, f: 2, g:, **k, &l) end
53
54
  ruby
54
55
 
55
56
  [:defs,
56
- [:call, [:call, nil, :a, [:arglist]], :b, [:arglist]],
57
- :empty,
58
- [:args, :*],
57
+ [:call, nil, :x, [:arglist]],
58
+ :m,
59
+ [:args,
60
+ :a,
61
+ :b,
62
+ :"*c",
63
+ :d,
64
+ :e,
65
+ :f,
66
+ :g,
67
+ :"**k",
68
+ :"&l",
69
+ [:block, [:lasgn, :b, [:lit, 1]]],
70
+ [:block, [:e, :f, :g, :"**k"], [[:lasgn, :f, [:lit, 2]]]]],
59
71
  [:scope, [:block, [:nil]]]]
60
72
  end
61
73
 
62
74
  parse <<-ruby do
63
- x = "a"
64
- def x.m(a)
65
- a
66
- end
75
+ def x.m a, b=1, *c, d, e:, f: 2, g:, **k, &l
76
+ end
67
77
  ruby
68
78
 
69
- [:block,
70
- [:lasgn, :x, [:str, "a"]],
71
- [:defs, [:lvar, :x], :m, [:args, :a], [:scope, [:block, [:lvar, :a]]]]]
79
+ [:defs,
80
+ [:call, nil, :x, [:arglist]],
81
+ :m,
82
+ [:args,
83
+ :a,
84
+ :b,
85
+ :"*c",
86
+ :d,
87
+ :e,
88
+ :f,
89
+ :g,
90
+ :"**k",
91
+ :"&l",
92
+ [:block, [:lasgn, :b, [:lit, 1]]],
93
+ [:block, [:e, :f, :g, :"**k"], [[:lasgn, :f, [:lit, 2]]]]],
94
+ [:scope, [:block, [:nil]]]]
72
95
  end
73
96
  end
data/spec/dstr_spec.rb CHANGED
@@ -52,8 +52,7 @@ describe "A Dstr node" do
52
52
  [:dstr,
53
53
  "",
54
54
  [:evstr, [:lit, 22]],
55
- [:str, "aa"],
56
- [:str, "cd"],
55
+ [:str, "aacd"],
57
56
  [:evstr, [:lit, 44]],
58
57
  [:str, "55"],
59
58
  [:evstr, [:lit, 66]]]
data/spec/ensure_spec.rb CHANGED
@@ -60,20 +60,20 @@ describe "An Ensure node" do
60
60
 
61
61
  parse <<-ruby do
62
62
  begin
63
- 14
63
+ a = 14
64
64
  return 2
65
65
  ensure
66
66
  13
67
67
  end
68
68
  ruby
69
69
 
70
- [:ensure, [:block, [:lit, 14], [:return, [:lit, 2]]], [:lit, 13]]
70
+ [:ensure, [:block, [:lasgn, :a, [:lit, 14]], [:return, [:lit, 2]]], [:lit, 13]]
71
71
  end
72
72
 
73
73
  parse <<-ruby do
74
74
  begin
75
75
  begin
76
- 14
76
+ a = 14
77
77
  return 2
78
78
  ensure
79
79
  13
@@ -84,17 +84,19 @@ describe "An Ensure node" do
84
84
  ruby
85
85
 
86
86
  [:ensure,
87
- [:ensure, [:block, [:lit, 14], [:return, [:lit, 2]]], [:lit, 13]],
87
+ [:ensure,
88
+ [:block, [:lasgn, :a, [:lit, 14]], [:return, [:lit, 2]]],
89
+ [:lit, 13]],
88
90
  [:lit, 15]]
89
91
  end
90
92
 
91
93
  parse <<-ruby do
92
94
  begin
93
- 14
95
+ a = 14
94
96
  return 2
95
97
  ensure
96
98
  begin
97
- 15
99
+ b = 15
98
100
  return 3
99
101
  ensure
100
102
  16
@@ -103,7 +105,9 @@ describe "An Ensure node" do
103
105
  ruby
104
106
 
105
107
  [:ensure,
106
- [:block, [:lit, 14], [:return, [:lit, 2]]],
107
- [:ensure, [:block, [:lit, 15], [:return, [:lit, 3]]], [:lit, 16]]]
108
+ [:block, [:lasgn, :a, [:lit, 14]], [:return, [:lit, 2]]],
109
+ [:ensure,
110
+ [:block, [:lasgn, :b, [:lit, 15]], [:return, [:lit, 3]]],
111
+ [:lit, 16]]]
108
112
  end
109
113
  end
data/spec/flip2_spec.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  describe "A Flip2 node" do
2
2
  parse <<-ruby do
3
- x = if ((i % 4) == 0)..((i % 3) == 0) then
3
+ x = if ((i % 4) == 0)..((i % 3) == 0)
4
4
  i
5
5
  else
6
6
  nil
@@ -24,7 +24,7 @@ describe "A Flip2 node" do
24
24
  end
25
25
 
26
26
  parse <<-ruby do
27
- if 1..2.a?(b) then
27
+ if 1..2.a?(b)
28
28
  nil
29
29
  end
30
30
  ruby
@@ -36,4 +36,40 @@ describe "A Flip2 node" do
36
36
  [:nil],
37
37
  nil]
38
38
  end
39
+
40
+ parse <<-ruby do
41
+ x, y = 1, 2
42
+ if x..y.a?(b)
43
+ nil
44
+ end
45
+ ruby
46
+
47
+ [:block,
48
+ [:masgn,
49
+ [:array, [:lasgn, :x], [:lasgn, :y]],
50
+ [:array, [:lit, 1], [:lit, 2]]],
51
+ [:if,
52
+ [:flip2,
53
+ [:lvar, :x],
54
+ [:call, [:lvar, :y], :a?, [:arglist, [:call, nil, :b, [:arglist]]]]],
55
+ [:nil],
56
+ nil]]
57
+ end
58
+
59
+ parse <<-ruby do
60
+ if x..y.a?(b)
61
+ nil
62
+ end
63
+ ruby
64
+
65
+ [:if,
66
+ [:flip2,
67
+ [:call, nil, :x, [:arglist]],
68
+ [:call,
69
+ [:call, nil, :y, [:arglist]],
70
+ :a?,
71
+ [:arglist, [:call, nil, :b, [:arglist]]]]],
72
+ [:nil],
73
+ nil]
74
+ end
39
75
  end
data/spec/hash_spec.rb CHANGED
@@ -24,4 +24,51 @@ describe "A Hash node" do
24
24
  [:lasgn, :a, [:lit, 1]],
25
25
  [:hash, [:lit, :a], [:lvar, :a]]]
26
26
  end
27
+
28
+ parse <<-ruby do
29
+ { **{ a: 1, b: 2 }, b: 2 }
30
+ ruby
31
+
32
+ [:hash,
33
+ [:hash_splat],
34
+ [:hash, [:lit, :a], [:lit, 1], [:lit, :b], [:lit, 2]],
35
+ [:lit, :b],
36
+ [:lit, 2]]
37
+ end
38
+
39
+ parse <<-ruby do
40
+ { a: 1, **{ b: 2 }, c: 3 }
41
+ ruby
42
+
43
+ [:hash,
44
+ [:lit, :a],
45
+ [:lit, 1],
46
+ [:hash_splat],
47
+ [:hash, [:lit, :b], [:lit, 2]],
48
+ [:lit, :c],
49
+ [:lit, 3]]
50
+ end
51
+
52
+ parse <<-ruby do
53
+ h = { a: 1 }
54
+ { b: 2, **h }
55
+ ruby
56
+
57
+ [:block,
58
+ [:lasgn, :h, [:hash, [:lit, :a], [:lit, 1]]],
59
+ [:hash, [:lit, :b], [:lit, 2], [:hash_splat], [:lvar, :h]]]
60
+ end
61
+
62
+ parse <<-ruby do
63
+ { a: 1, **h, c: 3 }
64
+ ruby
65
+
66
+ [:hash,
67
+ [:lit, :a],
68
+ [:lit, 1],
69
+ [:hash_splat],
70
+ [:call, nil, :h, [:arglist]],
71
+ [:lit, :c],
72
+ [:lit, 3]]
73
+ end
27
74
  end
data/spec/iter_spec.rb CHANGED
@@ -11,501 +11,637 @@ describe "An Iter node" do
11
11
  [:call, nil, :m, [:arglist, [:iter, [:args], [:call, nil, :x, [:arglist]]]]]
12
12
  end
13
13
 
14
- parse "m { || x }" do
15
- [:call, nil, :m, [:arglist, [:iter, [:args], [:call, nil, :x, [:arglist]]]]]
14
+ parse "m { || }" do
15
+ [:call, nil, :m, [:arglist, [:iter, [:args], [:nil]]]]
16
+ end
17
+
18
+ parse "m { |; x| }" do
19
+ [:call, nil, :m, [:arglist, [:iter, [:args], [:nil]]]]
20
+ end
21
+
22
+ parse "m { |; x, y| x - y + z }" do
23
+ [:call,
24
+ nil,
25
+ :m,
26
+ [:arglist, [:iter, [:args], [:block, [[:lvar, :x], [:lvar, :y]]]]]]
27
+ end
28
+
29
+ parse "m { |a| }" do
30
+ [:call, nil, :m, [:arglist, [:iter, [:args, :a], [:nil]]]]
16
31
  end
17
32
 
18
- parse "m { |a| a + x }" do
33
+ parse "m { |a, (b, c)| }" do
19
34
  [:call,
20
35
  nil,
21
36
  :m,
22
37
  [:arglist,
23
38
  [:iter,
24
- [:args, :a],
25
- [:call, [:lvar, :a], :+, [:arglist, [:call, nil, :x, [:arglist]]]]]]]
39
+ [:args,
40
+ :a,
41
+ [:masgn, [:array, [:lasgn, :b], [:lasgn, :c]], [:lvar, :"_:1"]]],
42
+ [:nil]]]]
26
43
  end
27
44
 
28
- parse "m { |*| x }" do
45
+ parse "m { |a; x| }" do
46
+ [:call, nil, :m, [:arglist, [:iter, [:args, :a], [:block, [[:lvar, :x]]]]]]
47
+ end
48
+
49
+ parse "m { |a=1| }" do
29
50
  [:call,
30
51
  nil,
31
52
  :m,
32
- [:arglist, [:iter, [:args, :*], [:call, nil, :x, [:arglist]]]]]
53
+ [:arglist, [:iter, [:args, :a, [:block, [:lasgn, :a, [:lit, 1]]]], [:nil]]]]
33
54
  end
34
55
 
35
- parse "m { |*c| x; c }" do
56
+ parse "m { |a=1, (b, (c, *d), *e)| }" do
36
57
  [:call,
37
58
  nil,
38
59
  :m,
39
60
  [:arglist,
40
61
  [:iter,
41
- [:args, :"*c"],
42
- [:block, [:call, nil, :x, [:arglist]], [:lvar, :c]]]]]
62
+ [:args,
63
+ :a,
64
+ [:masgn,
65
+ [:array,
66
+ [:lasgn, :b],
67
+ [:masgn, [:array, [:lasgn, :c], [:splat, [:lasgn, :d]]]],
68
+ [:splat, [:lasgn, :e]]],
69
+ [:lvar, :"_:1"]],
70
+ [:block, [:lasgn, :a, [:lit, 1]]]],
71
+ [:nil]]]]
43
72
  end
44
73
 
45
- parse "m { |a, | a + x }" do
74
+ parse "m { |a=1; x| }" do
46
75
  [:call,
47
76
  nil,
48
77
  :m,
49
78
  [:arglist,
50
79
  [:iter,
51
- [:args, :a],
52
- [:call, [:lvar, :a], :+, [:arglist, [:call, nil, :x, [:arglist]]]]]]]
80
+ [:args, :a, [:block, [:lasgn, :a, [:lit, 1]]]],
81
+ [:block, [[:lvar, :x]]]]]]
82
+ end
83
+
84
+ parse "m { |*| }" do
85
+ [:call, nil, :m, [:arglist, [:iter, [:args, :*], [:nil]]]]
86
+ end
87
+
88
+ parse "m { |*; x| }" do
89
+ [:call, nil, :m, [:arglist, [:iter, [:args, :*], [:block, [[:lvar, :x]]]]]]
90
+ end
91
+
92
+ parse "m { |*a| }" do
93
+ [:call, nil, :m, [:arglist, [:iter, [:args, :"*a"], [:nil]]]]
94
+ end
95
+
96
+ parse "m { |*a; x| }" do
97
+ [:call, nil, :m, [:arglist, [:iter, [:args, :"*a"], [:block, [[:lvar, :x]]]]]]
98
+ end
99
+
100
+ parse "m { |a:| }" do
101
+ [:call, nil, :m, [:arglist, [:iter, [:args, :a, [:block, [:a]]], [:nil]]]]
53
102
  end
54
103
 
55
- parse "m { |a, *| a + x }" do
104
+ parse "m { |a:; x| }" do
56
105
  [:call,
57
106
  nil,
58
107
  :m,
59
- [:arglist,
60
- [:iter,
61
- [:args, :a, :*],
62
- [:call, [:lvar, :a], :+, [:arglist, [:call, nil, :x, [:arglist]]]]]]]
108
+ [:arglist, [:iter, [:args, :a, [:block, [:a]]], [:block, [[:lvar, :x]]]]]]
63
109
  end
64
110
 
65
- parse "m { |a, *c| a + x; c }" do
111
+ parse "m { |a: 1| }" do
66
112
  [:call,
67
113
  nil,
68
114
  :m,
69
115
  [:arglist,
70
- [:iter,
71
- [:args, :a, :"*c"],
72
- [:block,
73
- [:call, [:lvar, :a], :+, [:arglist, [:call, nil, :x, [:arglist]]]],
74
- [:lvar, :c]]]]]
116
+ [:iter, [:args, :a, [:block, [:a], [[:lasgn, :a, [:lit, 1]]]]], [:nil]]]]
75
117
  end
76
118
 
77
- parse "m { |a, b| a + x; b }" do
119
+ parse "m { |a: 1; x| }" do
78
120
  [:call,
79
121
  nil,
80
122
  :m,
81
123
  [:arglist,
82
124
  [:iter,
83
- [:args, :a, :b],
84
- [:block,
85
- [:call, [:lvar, :a], :+, [:arglist, [:call, nil, :x, [:arglist]]]],
86
- [:lvar, :b]]]]]
125
+ [:args, :a, [:block, [:a], [[:lasgn, :a, [:lit, 1]]]]],
126
+ [:block, [[:lvar, :x]]]]]]
127
+ end
128
+
129
+ parse "m { |**| }" do
130
+ [:call, nil, :m, [:arglist, [:iter, [:args, :**, [:block, [:**]]], [:nil]]]]
87
131
  end
88
132
 
89
- parse "m { |a, b, | a + x; b }" do
133
+ parse "m { |**; x| }" do
90
134
  [:call,
91
135
  nil,
92
136
  :m,
93
- [:arglist,
94
- [:iter,
95
- [:args, :a, :b],
96
- [:block,
97
- [:call, [:lvar, :a], :+, [:arglist, [:call, nil, :x, [:arglist]]]],
98
- [:lvar, :b]]]]]
137
+ [:arglist, [:iter, [:args, :**, [:block, [:**]]], [:block, [[:lvar, :x]]]]]]
138
+ end
139
+
140
+ parse "m { |**k| }" do
141
+ [:call,
142
+ nil,
143
+ :m,
144
+ [:arglist, [:iter, [:args, :"**k", [:block, [:"**k"]]], [:nil]]]]
99
145
  end
100
146
 
101
- parse "m { |a, b, *| a + x; b }" do
147
+ parse "m { |**k; x| }" do
102
148
  [:call,
103
149
  nil,
104
150
  :m,
105
151
  [:arglist,
106
- [:iter,
107
- [:args, :a, :b, :*],
108
- [:block,
109
- [:call, [:lvar, :a], :+, [:arglist, [:call, nil, :x, [:arglist]]]],
110
- [:lvar, :b]]]]]
152
+ [:iter, [:args, :"**k", [:block, [:"**k"]]], [:block, [[:lvar, :x]]]]]]
153
+ end
154
+
155
+ parse "m { |&b| }" do
156
+ [:call, nil, :m, [:arglist, [:iter, [:args, :"&b"], [:nil]]]]
157
+ end
158
+
159
+ parse "m { |&b; x| }" do
160
+ [:call, nil, :m, [:arglist, [:iter, [:args, :"&b"], [:block, [[:lvar, :x]]]]]]
161
+ end
162
+
163
+ parse "m { |a, | }" do
164
+ [:call, nil, :m, [:arglist, [:iter, [:args, :a, :*], [:nil]]]]
165
+ end
166
+
167
+ parse "m { |a,; x| }" do
168
+ [:call, nil, :m, [:arglist, [:iter, [:args, :a, :*], [:block, [[:lvar, :x]]]]]]
111
169
  end
112
170
 
113
- masgn_rest_arg_block = lambda do |g|
114
- g.push :self
171
+ parse "m { |a, b| }" do
172
+ [:call, nil, :m, [:arglist, [:iter, [:args, :a, :b], [:nil]]]]
173
+ end
115
174
 
116
- g.in_block_send :m, :rest, -3 do |d|
117
- d.push_local 0
118
- d.push :self
119
- d.send :x, 0, true
120
- d.send :+, 1, false
121
- d.pop
122
- d.push_local 1
123
- d.pop
124
- d.push_local 2
125
- end
175
+ parse "m { |a, b; x| }" do
176
+ [:call, nil, :m, [:arglist, [:iter, [:args, :a, :b], [:block, [[:lvar, :x]]]]]]
126
177
  end
127
178
 
128
- parse "m { |a, b, *c| a + x; b; c }" do
179
+ parse "m { |a, b=1| }" do
129
180
  [:call,
130
181
  nil,
131
182
  :m,
132
183
  [:arglist,
133
- [:iter,
134
- [:args, :a, :b, :"*c"],
135
- [:block,
136
- [:call, [:lvar, :a], :+, [:arglist, [:call, nil, :x, [:arglist]]]],
137
- [:lvar, :b],
138
- [:lvar, :c]]]]]
184
+ [:iter, [:args, :a, :b, [:block, [:lasgn, :b, [:lit, 1]]]], [:nil]]]]
185
+ end
186
+
187
+ parse "m { |a, *| }" do
188
+ [:call, nil, :m, [:arglist, [:iter, [:args, :a, :*], [:nil]]]]
139
189
  end
140
190
 
141
- parse "m do |a, b, *c| a + x; b; c end" do
191
+ parse "m { |a, *b| }" do
192
+ [:call, nil, :m, [:arglist, [:iter, [:args, :a, :"*b"], [:nil]]]]
193
+ end
194
+
195
+ parse "m { |a, b:| }" do
196
+ [:call, nil, :m, [:arglist, [:iter, [:args, :a, :b, [:block, [:b]]], [:nil]]]]
197
+ end
198
+
199
+ parse "m { |a, b: 1| }" do
142
200
  [:call,
143
201
  nil,
144
202
  :m,
145
203
  [:arglist,
146
- [:iter,
147
- [:args, :a, :b, :"*c"],
148
- [:block,
149
- [:call, [:lvar, :a], :+, [:arglist, [:call, nil, :x, [:arglist]]]],
150
- [:lvar, :b],
151
- [:lvar, :c]]]]]
204
+ [:iter, [:args, :a, :b, [:block, [:b], [[:lasgn, :b, [:lit, 1]]]]], [:nil]]]]
152
205
  end
153
206
 
154
- parse "m { n = 1; n }" do
207
+ parse "m { |a, **| }" do
155
208
  [:call,
156
209
  nil,
157
210
  :m,
158
- [:arglist, [:iter, [:args], [:block, [:lasgn, :n, [:lit, 1]], [:lvar, :n]]]]]
211
+ [:arglist, [:iter, [:args, :a, :**, [:block, [:**]]], [:nil]]]]
159
212
  end
160
213
 
161
- parse "m { n = 1; m { n } }" do
214
+ parse "m { |a, **k| }" do
162
215
  [:call,
163
216
  nil,
164
217
  :m,
165
- [:arglist,
166
- [:iter,
167
- [:args],
168
- [:block,
169
- [:lasgn, :n, [:lit, 1]],
170
- [:call, nil, :m, [:arglist, [:iter, [:args], [:lvar, :n]]]]]]]]
218
+ [:arglist, [:iter, [:args, :a, :"**k", [:block, [:"**k"]]], [:nil]]]]
171
219
  end
172
220
 
173
- parse "n = 1; m { n = 2 }; n" do
174
- [:block,
175
- [:lasgn, :n, [:lit, 1]],
176
- [:call, nil, :m, [:arglist, [:iter, [:args], [:lasgn, :n, [:lit, 2]]]]],
177
- [:lvar, :n]]
221
+ parse "m { |a, &b| }" do
222
+ [:call, nil, :m, [:arglist, [:iter, [:args, :a, :"&b"], [:nil]]]]
178
223
  end
179
224
 
180
- parse "m(a) { |b| a + x }" do
225
+ parse "m { |a=1, b=2| }" do
181
226
  [:call,
182
227
  nil,
183
228
  :m,
184
229
  [:arglist,
185
- [:call, nil, :a, [:arglist]],
186
230
  [:iter,
187
- [:args, :b],
188
- [:call,
189
- [:call, nil, :a, [:arglist]],
190
- :+,
191
- [:arglist, [:call, nil, :x, [:arglist]]]]]]]
231
+ [:args, :a, :b, [:block, [:lasgn, :a, [:lit, 1]], [:lasgn, :b, [:lit, 2]]]],
232
+ [:nil]]]]
192
233
  end
193
234
 
194
- parse <<-ruby do
195
- m { |a|
196
- a + x
197
- }
198
- ruby
199
-
235
+ parse "m { |a=1, b| }" do
200
236
  [:call,
201
237
  nil,
202
238
  :m,
203
239
  [:arglist,
204
- [:iter,
205
- [:args, :a],
206
- [:call, [:lvar, :a], :+, [:arglist, [:call, nil, :x, [:arglist]]]]]]]
240
+ [:iter, [:args, :a, :b, [:block, [:lasgn, :a, [:lit, 1]]]], [:nil]]]]
207
241
  end
208
242
 
209
- parse <<-ruby do
210
- m do |a|
211
- a + x
212
- end
213
- ruby
243
+ parse "m { |a=1, *| }" do
244
+ [:call,
245
+ nil,
246
+ :m,
247
+ [:arglist,
248
+ [:iter, [:args, :a, :*, [:block, [:lasgn, :a, [:lit, 1]]]], [:nil]]]]
249
+ end
214
250
 
251
+ parse "m { |a=1, *b| }" do
215
252
  [:call,
216
253
  nil,
217
254
  :m,
218
255
  [:arglist,
219
- [:iter,
220
- [:args, :a],
221
- [:call, [:lvar, :a], :+, [:arglist, [:call, nil, :x, [:arglist]]]]]]]
256
+ [:iter, [:args, :a, :"*b", [:block, [:lasgn, :a, [:lit, 1]]]], [:nil]]]]
222
257
  end
223
258
 
224
- parse "obj.m { |a| a + x }" do
259
+ parse "m { |a=1, b:| }" do
225
260
  [:call,
226
- [:call, nil, :obj, [:arglist]],
261
+ nil,
227
262
  :m,
228
263
  [:arglist,
229
264
  [:iter,
230
- [:args, :a],
231
- [:call, [:lvar, :a], :+, [:arglist, [:call, nil, :x, [:arglist]]]]]]]
265
+ [:args, :a, :b, [:block, [:lasgn, :a, [:lit, 1]]], [:block, [:b]]],
266
+ [:nil]]]]
232
267
  end
233
268
 
234
- parse "obj.m(x) { |a| a + x }" do
269
+ parse "m { |a=1, b: 2| }" do
235
270
  [:call,
236
- [:call, nil, :obj, [:arglist]],
271
+ nil,
237
272
  :m,
238
273
  [:arglist,
239
- [:call, nil, :x, [:arglist]],
240
274
  [:iter,
241
- [:args, :a],
242
- [:call, [:lvar, :a], :+, [:arglist, [:call, nil, :x, [:arglist]]]]]]]
275
+ [:args,
276
+ :a,
277
+ :b,
278
+ [:block, [:lasgn, :a, [:lit, 1]]],
279
+ [:block, [:b], [[:lasgn, :b, [:lit, 2]]]]],
280
+ [:nil]]]]
243
281
  end
244
282
 
245
- parse "obj.m(a) { |a| a + x }" do
283
+ parse "m { |a=1, **| }" do
246
284
  [:call,
247
- [:call, nil, :obj, [:arglist]],
285
+ nil,
248
286
  :m,
249
287
  [:arglist,
250
- [:call, nil, :a, [:arglist]],
251
288
  [:iter,
252
- [:args, :a],
253
- [:call, [:lvar, :a], :+, [:arglist, [:call, nil, :x, [:arglist]]]]]]]
254
- end
255
-
256
- parse "a = 1; m { |a| a + x }" do
257
- [:block,
258
- [:lasgn, :a, [:lit, 1]],
259
- [:call,
260
- nil,
261
- :m,
262
- [:arglist,
263
- [:iter,
264
- [:args, :a],
265
- [:call, [:lvar, :a], :+, [:arglist, [:call, nil, :x, [:arglist]]]]]]]]
266
- end
267
-
268
- parse <<-ruby do
269
- x = nil
270
- m do |a|
271
- begin
272
- x
273
- rescue Exception => x
274
- break
275
- ensure
276
- x = a
277
- end
278
- end
279
- ruby
280
-
281
- [:block,
282
- [:lasgn, :x, [:nil]],
283
- [:call,
284
- nil,
285
- :m,
286
- [:arglist,
287
- [:iter,
288
- [:args, :a],
289
- [:ensure,
290
- [:rescue,
291
- [:lvar, :x],
292
- [:resbody,
293
- [:array, [:const, :Exception], [:lasgn, :x, [:gvar, :$!]]],
294
- [:break, [:nil]]]],
295
- [:lasgn, :x, [:lvar, :a]]]]]]]
289
+ [:args, :a, :**, [:block, [:lasgn, :a, [:lit, 1]]], [:block, [:**]]],
290
+ [:nil]]]]
296
291
  end
297
292
 
298
- parse "m { next }" do
299
- [:call, nil, :m, [:arglist, [:iter, [:args], [:next]]]]
293
+ parse "m { |a=1, **k| }" do
294
+ [:call,
295
+ nil,
296
+ :m,
297
+ [:arglist,
298
+ [:iter,
299
+ [:args, :a, :"**k", [:block, [:lasgn, :a, [:lit, 1]]], [:block, [:"**k"]]],
300
+ [:nil]]]]
300
301
  end
301
302
 
302
- parse "m { next if x }" do
303
+ parse "m { |a=1, &b| }" do
303
304
  [:call,
304
305
  nil,
305
306
  :m,
306
307
  [:arglist,
307
- [:iter, [:args], [:if, [:call, nil, :x, [:arglist]], [:next], nil]]]]
308
+ [:iter, [:args, :a, :"&b", [:block, [:lasgn, :a, [:lit, 1]]]], [:nil]]]]
309
+ end
310
+
311
+ parse "m { |*, a| }" do
312
+ [:call, nil, :m, [:arglist, [:iter, [:args, :*, :a], [:nil]]]]
313
+ end
314
+
315
+ parse "m { |*a, b| }" do
316
+ [:call, nil, :m, [:arglist, [:iter, [:args, :"*a", :b], [:nil]]]]
308
317
  end
309
318
 
310
- parse "m { next x }" do
319
+ parse "m { |*, a:| }" do
320
+ [:call, nil, :m, [:arglist, [:iter, [:args, :*, :a, [:block, [:a]]], [:nil]]]]
321
+ end
322
+
323
+ parse "m { |*a, b:| }" do
311
324
  [:call,
312
325
  nil,
313
326
  :m,
314
- [:arglist, [:iter, [:args], [:next, [:call, nil, :x, [:arglist]]]]]]
327
+ [:arglist, [:iter, [:args, :"*a", :b, [:block, [:b]]], [:nil]]]]
315
328
  end
316
329
 
317
- parse "m { x = 1; next x }" do
330
+ parse "m { |*, a: 1| }" do
318
331
  [:call,
319
332
  nil,
320
333
  :m,
321
334
  [:arglist,
322
- [:iter, [:args], [:block, [:lasgn, :x, [:lit, 1]], [:next, [:lvar, :x]]]]]]
335
+ [:iter, [:args, :*, :a, [:block, [:a], [[:lasgn, :a, [:lit, 1]]]]], [:nil]]]]
323
336
  end
324
337
 
325
- parse "m { next [1] }" do
326
- [:call, nil, :m, [:arglist, [:iter, [:args], [:next, [:array, [:lit, 1]]]]]]
338
+ parse "m { |*a, b: 1| }" do
339
+ [:call,
340
+ nil,
341
+ :m,
342
+ [:arglist,
343
+ [:iter,
344
+ [:args, :"*a", :b, [:block, [:b], [[:lasgn, :b, [:lit, 1]]]]],
345
+ [:nil]]]]
327
346
  end
328
347
 
329
- parse "m { next *[1] }" do
348
+ parse "m { |*, **| }" do
330
349
  [:call,
331
350
  nil,
332
351
  :m,
333
- [:arglist, [:iter, [:args], [:next, [:splat, [:array, [:lit, 1]]]]]]]
352
+ [:arglist, [:iter, [:args, :*, :**, [:block, [:**]]], [:nil]]]]
334
353
  end
335
354
 
336
- parse "m { next [*[1]] }" do
355
+ parse "m { |*a, **| }" do
337
356
  [:call,
338
357
  nil,
339
358
  :m,
340
- [:arglist, [:iter, [:args], [:next, [:splat, [:array, [:lit, 1]]]]]]]
359
+ [:arglist, [:iter, [:args, :"*a", :**, [:block, [:**]]], [:nil]]]]
341
360
  end
342
361
 
343
- parse "m { next *[1, 2] }" do
362
+ parse "m { |*, **k| }" do
344
363
  [:call,
345
364
  nil,
346
365
  :m,
347
- [:arglist,
348
- [:iter, [:args], [:next, [:splat, [:array, [:lit, 1], [:lit, 2]]]]]]]
366
+ [:arglist, [:iter, [:args, :*, :"**k", [:block, [:"**k"]]], [:nil]]]]
349
367
  end
350
368
 
351
- parse "m { next [*[1, 2]] }" do
369
+ parse "m { |*a, **k| }" do
352
370
  [:call,
353
371
  nil,
354
372
  :m,
355
- [:arglist,
356
- [:iter, [:args], [:next, [:splat, [:array, [:lit, 1], [:lit, 2]]]]]]]
373
+ [:arglist, [:iter, [:args, :"*a", :"**k", [:block, [:"**k"]]], [:nil]]]]
357
374
  end
358
375
 
359
- parse "m { break }" do
360
- [:call, nil, :m, [:arglist, [:iter, [:args], [:break, [:nil]]]]]
376
+ parse "m { |*, &b| }" do
377
+ [:call, nil, :m, [:arglist, [:iter, [:args, :*, :"&b"], [:nil]]]]
378
+ end
379
+
380
+ parse "m { |*a, &b| }" do
381
+ [:call, nil, :m, [:arglist, [:iter, [:args, :"*a", :"&b"], [:nil]]]]
382
+ end
383
+
384
+ parse "m { |a:, b:| }" do
385
+ [:call,
386
+ nil,
387
+ :m,
388
+ [:arglist, [:iter, [:args, :a, :b, [:block, [:a, :b]]], [:nil]]]]
361
389
  end
362
390
 
363
- parse "m { break if x }" do
391
+ parse "m { |a:, b: 1| }" do
364
392
  [:call,
365
393
  nil,
366
394
  :m,
367
395
  [:arglist,
368
396
  [:iter,
369
- [:args],
370
- [:if, [:call, nil, :x, [:arglist]], [:break, [:nil]], nil]]]]
397
+ [:args, :a, :b, [:block, [:a, :b], [[:lasgn, :b, [:lit, 1]]]]],
398
+ [:nil]]]]
371
399
  end
372
400
 
373
- parse "m { break x }" do
401
+ parse "m { |a:, **| }" do
374
402
  [:call,
375
403
  nil,
376
404
  :m,
377
- [:arglist, [:iter, [:args], [:break, [:call, nil, :x, [:arglist]]]]]]
405
+ [:arglist, [:iter, [:args, :a, :**, [:block, [:a, :**]]], [:nil]]]]
378
406
  end
379
407
 
380
- parse "m { x = 1; break x }" do
408
+ parse "m { |a:, **k| }" do
381
409
  [:call,
382
410
  nil,
383
411
  :m,
384
- [:arglist,
385
- [:iter, [:args], [:block, [:lasgn, :x, [:lit, 1]], [:break, [:lvar, :x]]]]]]
412
+ [:arglist, [:iter, [:args, :a, :"**k", [:block, [:a, :"**k"]]], [:nil]]]]
386
413
  end
387
414
 
388
- parse "m { break [1] }" do
389
- [:call, nil, :m, [:arglist, [:iter, [:args], [:break, [:array, [:lit, 1]]]]]]
415
+ parse "m { |a:, &b| }" do
416
+ [:call,
417
+ nil,
418
+ :m,
419
+ [:arglist, [:iter, [:args, :a, :"&b", [:block, [:a]]], [:nil]]]]
390
420
  end
391
421
 
392
- parse "m { break *[1] }" do
422
+ parse "m { |a: 1, b:| }" do
393
423
  [:call,
394
424
  nil,
395
425
  :m,
396
- [:arglist, [:iter, [:args], [:break, [:splat, [:array, [:lit, 1]]]]]]]
426
+ [:arglist,
427
+ [:iter,
428
+ [:args, :a, :b, [:block, [:a, :b], [[:lasgn, :a, [:lit, 1]]]]],
429
+ [:nil]]]]
397
430
  end
398
431
 
399
- parse "m { break [*[1]] }" do
432
+ parse "m { |a: 1, b: 2| }" do
400
433
  [:call,
401
434
  nil,
402
435
  :m,
403
- [:arglist, [:iter, [:args], [:break, [:splat, [:array, [:lit, 1]]]]]]]
436
+ [:arglist,
437
+ [:iter,
438
+ [:args,
439
+ :a,
440
+ :b,
441
+ [:block, [:a, :b], [[:lasgn, :a, [:lit, 1]], [:lasgn, :b, [:lit, 2]]]]],
442
+ [:nil]]]]
404
443
  end
405
444
 
406
- parse "m { break *[1, 2] }" do
445
+ parse "m { |a: 1, **| }" do
407
446
  [:call,
408
447
  nil,
409
448
  :m,
410
449
  [:arglist,
411
- [:iter, [:args], [:break, [:splat, [:array, [:lit, 1], [:lit, 2]]]]]]]
450
+ [:iter,
451
+ [:args, :a, :**, [:block, [:a, :**], [[:lasgn, :a, [:lit, 1]]]]],
452
+ [:nil]]]]
412
453
  end
413
454
 
414
- parse "m { break [*[1, 2]] }" do
455
+ parse "m { |a: 1, **k| }" do
415
456
  [:call,
416
457
  nil,
417
458
  :m,
418
459
  [:arglist,
419
- [:iter, [:args], [:break, [:splat, [:array, [:lit, 1], [:lit, 2]]]]]]]
460
+ [:iter,
461
+ [:args, :a, :"**k", [:block, [:a, :"**k"], [[:lasgn, :a, [:lit, 1]]]]],
462
+ [:nil]]]]
420
463
  end
421
464
 
422
- parse "m { return }" do
423
- [:call, nil, :m, [:arglist, [:iter, [:args], [:return]]]]
465
+ parse "m { |a: 1, &b| }" do
466
+ [:call,
467
+ nil,
468
+ :m,
469
+ [:arglist,
470
+ [:iter,
471
+ [:args, :a, :"&b", [:block, [:a], [[:lasgn, :a, [:lit, 1]]]]],
472
+ [:nil]]]]
424
473
  end
425
474
 
426
- parse "m { return if x }" do
475
+ parse "m { |**, &b| }" do
427
476
  [:call,
428
477
  nil,
429
478
  :m,
430
- [:arglist,
431
- [:iter, [:args], [:if, [:call, nil, :x, [:arglist]], [:return], nil]]]]
479
+ [:arglist, [:iter, [:args, :**, :"&b", [:block, [:**]]], [:nil]]]]
432
480
  end
433
481
 
434
- parse "m { return x }" do
482
+ parse "m { |**k, &b| }" do
435
483
  [:call,
436
484
  nil,
437
485
  :m,
438
- [:arglist, [:iter, [:args], [:return, [:call, nil, :x, [:arglist]]]]]]
486
+ [:arglist, [:iter, [:args, :"**k", :"&b", [:block, [:"**k"]]], [:nil]]]]
439
487
  end
440
488
 
441
- parse "m { x = 1; return x }" do
489
+ parse "m { n = 1; m { n } }" do
442
490
  [:call,
443
491
  nil,
444
492
  :m,
445
493
  [:arglist,
446
- [:iter, [:args], [:block, [:lasgn, :x, [:lit, 1]], [:return, [:lvar, :x]]]]]]
494
+ [:iter,
495
+ [:args],
496
+ [:block,
497
+ [:lasgn, :n, [:lit, 1]],
498
+ [:call, nil, :m, [:arglist, [:iter, [:args], [:lvar, :n]]]]]]]]
447
499
  end
448
500
 
449
- parse "m { return [1] }" do
450
- [:call, nil, :m, [:arglist, [:iter, [:args], [:return, [:array, [:lit, 1]]]]]]
501
+ parse "m(x) { |a, b=1, *c, d, e:, f: 2, **k, &l| }" do
502
+ [:call,
503
+ nil,
504
+ :m,
505
+ [:arglist,
506
+ [:call, nil, :x, [:arglist]],
507
+ [:iter,
508
+ [:args,
509
+ :a,
510
+ :b,
511
+ :"*c",
512
+ :d,
513
+ :e,
514
+ :f,
515
+ :"**k",
516
+ :"&l",
517
+ [:block, [:lasgn, :b, [:lit, 1]]],
518
+ [:block, [:e, :f, :"**k"], [[:lasgn, :f, [:lit, 2]]]]],
519
+ [:nil]]]]
451
520
  end
452
521
 
453
- parse "m { return *[1] }" do
522
+ parse "m(x, y) { |a, b=1, *c, d, e:, f: 2, **k, &l| }" do
454
523
  [:call,
455
524
  nil,
456
525
  :m,
457
- [:arglist, [:iter, [:args], [:return, [:splat, [:array, [:lit, 1]]]]]]]
526
+ [:arglist,
527
+ [:call, nil, :x, [:arglist]],
528
+ [:call, nil, :y, [:arglist]],
529
+ [:iter,
530
+ [:args,
531
+ :a,
532
+ :b,
533
+ :"*c",
534
+ :d,
535
+ :e,
536
+ :f,
537
+ :"**k",
538
+ :"&l",
539
+ [:block, [:lasgn, :b, [:lit, 1]]],
540
+ [:block, [:e, :f, :"**k"], [[:lasgn, :f, [:lit, 2]]]]],
541
+ [:nil]]]]
458
542
  end
459
543
 
460
- parse "m { return [*[1]] }" do
544
+ parse "x.m { |a, b=1, *c, d, e:, f: 2, **k, &l| }" do
461
545
  [:call,
462
- nil,
546
+ [:call, nil, :x, [:arglist]],
463
547
  :m,
464
- [:arglist, [:iter, [:args], [:return, [:splat, [:array, [:lit, 1]]]]]]]
548
+ [:arglist,
549
+ [:iter,
550
+ [:args,
551
+ :a,
552
+ :b,
553
+ :"*c",
554
+ :d,
555
+ :e,
556
+ :f,
557
+ :"**k",
558
+ :"&l",
559
+ [:block, [:lasgn, :b, [:lit, 1]]],
560
+ [:block, [:e, :f, :"**k"], [[:lasgn, :f, [:lit, 2]]]]],
561
+ [:nil]]]]
465
562
  end
466
563
 
467
- parse "m { return *[1, 2] }" do
564
+ parse "x.m(x, y) { |a, b=1, *c, d, e:, f: 2, **k, &l| }" do
468
565
  [:call,
469
- nil,
566
+ [:call, nil, :x, [:arglist]],
470
567
  :m,
471
568
  [:arglist,
472
- [:iter, [:args], [:return, [:splat, [:array, [:lit, 1], [:lit, 2]]]]]]]
569
+ [:call, nil, :x, [:arglist]],
570
+ [:call, nil, :y, [:arglist]],
571
+ [:iter,
572
+ [:args,
573
+ :a,
574
+ :b,
575
+ :"*c",
576
+ :d,
577
+ :e,
578
+ :f,
579
+ :"**k",
580
+ :"&l",
581
+ [:block, [:lasgn, :b, [:lit, 1]]],
582
+ [:block, [:e, :f, :"**k"], [[:lasgn, :f, [:lit, 2]]]]],
583
+ [:nil]]]]
473
584
  end
474
585
 
475
- parse "m { return [*[1, 2]] }" do
586
+ parse "m { next }" do
587
+ [:call, nil, :m, [:arglist, [:iter, [:args], [:next]]]]
588
+ end
589
+
590
+ parse "m { next 1 }" do
591
+ [:call, nil, :m, [:arglist, [:iter, [:args], [:next, [:lit, 1]]]]]
592
+ end
593
+
594
+ parse "m { x = 1; next x }" do
476
595
  [:call,
477
596
  nil,
478
597
  :m,
479
598
  [:arglist,
480
- [:iter, [:args], [:return, [:splat, [:array, [:lit, 1], [:lit, 2]]]]]]]
599
+ [:iter, [:args], [:block, [:lasgn, :x, [:lit, 1]], [:next, [:lvar, :x]]]]]]
481
600
  end
482
601
 
483
- parse "m { redo }" do
484
- [:call, nil, :m, [:arglist, [:iter, [:args], [:redo]]]]
602
+ parse "m { next *x }" do
603
+ [:call,
604
+ nil,
605
+ :m,
606
+ [:arglist, [:iter, [:args], [:next, [:splat, [:call, nil, :x, [:arglist]]]]]]]
607
+ end
608
+
609
+ parse "m { break }" do
610
+ [:call, nil, :m, [:arglist, [:iter, [:args], [:break, [:nil]]]]]
485
611
  end
486
612
 
487
- parse "m { redo if x }" do
613
+ parse "m { break x }" do
488
614
  [:call,
489
615
  nil,
490
616
  :m,
491
- [:arglist,
492
- [:iter, [:args], [:if, [:call, nil, :x, [:arglist]], [:redo], nil]]]]
617
+ [:arglist, [:iter, [:args], [:break, [:call, nil, :x, [:arglist]]]]]]
618
+ end
619
+
620
+ parse "m { return }" do
621
+ [:call, nil, :m, [:arglist, [:iter, [:args], [:return]]]]
493
622
  end
494
623
 
495
- parse "m(a) { retry }" do
624
+ parse "m { return x }" do
496
625
  [:call,
497
626
  nil,
498
627
  :m,
499
- [:arglist, [:call, nil, :a, [:arglist]], [:iter, [:args], [:retry]]]]
628
+ [:arglist, [:iter, [:args], [:return, [:call, nil, :x, [:arglist]]]]]]
500
629
  end
501
630
 
502
- parse "m(a) { retry if x }" do
631
+ parse "m { x = 1; return x }" do
503
632
  [:call,
504
633
  nil,
505
634
  :m,
506
635
  [:arglist,
507
- [:call, nil, :a, [:arglist]],
508
- [:iter, [:args], [:if, [:call, nil, :x, [:arglist]], [:retry], nil]]]]
636
+ [:iter, [:args], [:block, [:lasgn, :x, [:lit, 1]], [:return, [:lvar, :x]]]]]]
637
+ end
638
+
639
+ parse "m { redo }" do
640
+ [:call, nil, :m, [:arglist, [:iter, [:args], [:redo]]]]
641
+ end
642
+
643
+ parse "m { retry }" do
644
+ [:call, nil, :m, [:arglist, [:iter, [:args], [:retry]]]]
509
645
  end
510
646
 
511
647
  parse "break" do
@@ -524,16 +660,7 @@ describe "An Iter node" do
524
660
  [:next]
525
661
  end
526
662
 
527
- parse <<-ruby do
528
- def x(a)
529
- bar { super }
530
- end
531
- ruby
532
-
533
- [:defn,
534
- :x,
535
- [:args, :a],
536
- [:scope,
537
- [:block, [:call, nil, :bar, [:arglist, [:iter, [:args], [:zsuper]]]]]]]
663
+ parse "m { super }" do
664
+ [:call, nil, :m, [:arglist, [:iter, [:args], [:zsuper]]]]
538
665
  end
539
666
  end