fastruby 0.0.14 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +12 -0
- data/README +0 -2
- data/Rakefile +1 -1
- data/benchmarks/benchmark.rb +1 -0
- data/benchmarks/benchmark5.rb +3 -1
- data/ext/fastruby_base/fastruby_base.inl +2 -0
- data/lib/fastruby/builder.rb +18 -42
- data/lib/fastruby/exceptions.rb +8 -0
- data/lib/fastruby/getlocals.rb +17 -0
- data/lib/fastruby/object.rb +1 -31
- data/lib/fastruby/translator/modules/block.rb +44 -22
- data/lib/fastruby/translator/modules/call.rb +25 -1
- data/lib/fastruby/translator/modules/defn.rb +85 -57
- data/lib/fastruby/translator/modules/iter.rb +159 -46
- data/lib/fastruby/translator/modules/method_group.rb +7 -0
- data/lib/fastruby/translator/translator.rb +224 -245
- data/lib/fastruby.rb +1 -1
- data/lib/targetted +84 -0
- data/spec/block/arguments_spec.rb +214 -0
- data/spec/block/block_as_proc_spec.rb +98 -0
- data/spec/block/callcc_spec.rb +233 -0
- data/spec/block/proc_as_block_spec.rb +111 -0
- data/spec/call/base_call_spec.rb +3 -2
- data/spec/defn/default_args_spec.rb +303 -0
- data/spec/defn/multiple_args_spec.rb +35 -0
- data/spec/exception/base_spec.rb +26 -0
- metadata +10 -4
@@ -0,0 +1,111 @@
|
|
1
|
+
require "fastruby"
|
2
|
+
|
3
|
+
describe FastRuby, "fastruby" do
|
4
|
+
class ::VY1
|
5
|
+
fastruby "
|
6
|
+
def foo
|
7
|
+
yield
|
8
|
+
end
|
9
|
+
"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should allow block as proc when calling from normal ruby" do
|
13
|
+
executed = 0
|
14
|
+
|
15
|
+
block = proc do
|
16
|
+
executed = 1
|
17
|
+
end
|
18
|
+
|
19
|
+
::VY1.new.foo(&block)
|
20
|
+
|
21
|
+
executed.should be == 1
|
22
|
+
end
|
23
|
+
|
24
|
+
class ::VY2
|
25
|
+
fastruby "
|
26
|
+
def foo
|
27
|
+
yield
|
28
|
+
end
|
29
|
+
|
30
|
+
def bar(block)
|
31
|
+
foo(&block)
|
32
|
+
end
|
33
|
+
"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should allow block as proc when calling from fastruby" do
|
37
|
+
executed = 0
|
38
|
+
|
39
|
+
block = proc do
|
40
|
+
executed = 1
|
41
|
+
end
|
42
|
+
|
43
|
+
::VY2.new.bar(block)
|
44
|
+
|
45
|
+
executed.should be == 1
|
46
|
+
end
|
47
|
+
|
48
|
+
class ::VY3
|
49
|
+
fastruby "
|
50
|
+
def foo
|
51
|
+
yield(1)
|
52
|
+
end
|
53
|
+
|
54
|
+
def bar(block)
|
55
|
+
foo(&block)
|
56
|
+
end
|
57
|
+
"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should allow block as proc when calling from fastruby with arguments" do
|
61
|
+
executed = 0
|
62
|
+
recv_x = nil
|
63
|
+
|
64
|
+
block = proc do |x|
|
65
|
+
recv_x = x
|
66
|
+
executed = 1
|
67
|
+
end
|
68
|
+
|
69
|
+
::VY3.new.bar(block)
|
70
|
+
|
71
|
+
recv_x.should be == 1
|
72
|
+
executed.should be == 1
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
class ::VY4
|
77
|
+
def foo(a,b,c)
|
78
|
+
yield(a,b,c)
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
fastruby "
|
83
|
+
def bar(x,block)
|
84
|
+
foo(*x,&block)
|
85
|
+
end
|
86
|
+
"
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should allow block as proc when calling from fastruby with splat arguments" do
|
90
|
+
executed = 0
|
91
|
+
recv_a = nil
|
92
|
+
recv_b = nil
|
93
|
+
recv_c = nil
|
94
|
+
|
95
|
+
block = proc do |a,b,c|
|
96
|
+
recv_a = a
|
97
|
+
recv_b = b
|
98
|
+
recv_c = c
|
99
|
+
executed = 1
|
100
|
+
end
|
101
|
+
|
102
|
+
::VY4.new.bar([1,2,3],block)
|
103
|
+
|
104
|
+
recv_a.should be == 1
|
105
|
+
recv_b.should be == 2
|
106
|
+
recv_c.should be == 3
|
107
|
+
executed.should be == 1
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
end
|
data/spec/call/base_call_spec.rb
CHANGED
@@ -0,0 +1,303 @@
|
|
1
|
+
require "fastruby"
|
2
|
+
|
3
|
+
describe FastRuby, "fastruby" do
|
4
|
+
it "should allow one optional argument" do
|
5
|
+
fastruby "
|
6
|
+
class CFX1
|
7
|
+
def foo(a=0)
|
8
|
+
a
|
9
|
+
end
|
10
|
+
end
|
11
|
+
"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should allow one optional argument and should return the default when no specified" do
|
15
|
+
fastruby "
|
16
|
+
class CFX2
|
17
|
+
def foo(a=0)
|
18
|
+
a
|
19
|
+
end
|
20
|
+
end
|
21
|
+
"
|
22
|
+
|
23
|
+
CFX2.new.foo.should be == 0
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should allow one optional argument and should return the passed value when specified" do
|
27
|
+
fastruby "
|
28
|
+
class CFX3
|
29
|
+
def foo(a=0)
|
30
|
+
a
|
31
|
+
end
|
32
|
+
end
|
33
|
+
"
|
34
|
+
|
35
|
+
CFX3.new.foo(99).should be == 99
|
36
|
+
end
|
37
|
+
|
38
|
+
fastruby "
|
39
|
+
class CFX4
|
40
|
+
def foo(a=7,b=4)
|
41
|
+
[a,b]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
"
|
45
|
+
|
46
|
+
it "should allow two optional argument and should return the passed value when no arguments is passed" do
|
47
|
+
cfx4 = CFX4.new
|
48
|
+
cfx4.foo().should be == [7,4]
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should allow two optional argument and should return the passed value when one argument is passed" do
|
52
|
+
cfx4 = CFX4.new
|
53
|
+
cfx4.foo(99).should be == [99,4]
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should allow two optional argument and should return the passed value when two arguments are passed" do
|
57
|
+
cfx4 = CFX4.new
|
58
|
+
cfx4.foo(99,88).should be == [99,88]
|
59
|
+
end
|
60
|
+
|
61
|
+
fastruby "
|
62
|
+
class CFX5
|
63
|
+
def foo(a,b=4)
|
64
|
+
[a,b]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
"
|
68
|
+
|
69
|
+
it "should allow one mandatory and one optional argument and should return the passed value when one argument is passed" do
|
70
|
+
cfx5 = CFX5.new
|
71
|
+
cfx5.foo(99).should be == [99,4]
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should allow one mandatory and one optional argument and should return the passed value when two arguments are passed" do
|
75
|
+
cfx5 = CFX5.new
|
76
|
+
cfx5.foo(99,88).should be == [99,88]
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should raise ArgumentError when no arguments are passed" do
|
80
|
+
lambda {
|
81
|
+
cfx5 = CFX5.new
|
82
|
+
cfx5.foo
|
83
|
+
}.should raise_error(ArgumentError)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should raise ArgumentError when three arguments are passed" do
|
87
|
+
lambda {
|
88
|
+
cfx5 = CFX5.new
|
89
|
+
cfx5.foo(1,2,3)
|
90
|
+
}.should raise_error(ArgumentError)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should allow splat arguments with default arguments " do
|
94
|
+
fastruby "
|
95
|
+
class CFX6
|
96
|
+
def foo(x=44,*y)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
"
|
100
|
+
end
|
101
|
+
|
102
|
+
fastruby "
|
103
|
+
class CFX7
|
104
|
+
def foo(x=44,*y)
|
105
|
+
x
|
106
|
+
end
|
107
|
+
end
|
108
|
+
"
|
109
|
+
|
110
|
+
it "should allow splat arguments with default arguments accepting no arguments " do
|
111
|
+
CFX7.new.foo.should be == 44
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should allow splat arguments with default arguments accepting one argument" do
|
115
|
+
CFX7.new.foo(55).should be == 55
|
116
|
+
end
|
117
|
+
|
118
|
+
fastruby "
|
119
|
+
class CFX8
|
120
|
+
def foo(x=44,*y)
|
121
|
+
y
|
122
|
+
end
|
123
|
+
end
|
124
|
+
"
|
125
|
+
|
126
|
+
it "should allow splat arguments with default arguments accepting no arguments" do
|
127
|
+
CFX8.new.foo.should be == []
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should allow splat arguments with default arguments accepting one arguments" do
|
131
|
+
CFX8.new.foo(55).should be == []
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should allow splat arguments with default arguments accepting two arguments" do
|
135
|
+
CFX8.new.foo(55,66).should be == [66]
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should allow splat arguments with default arguments accepting three arguments" do
|
139
|
+
CFX8.new.foo(55,66,67,68).should be == [66,67,68]
|
140
|
+
end
|
141
|
+
|
142
|
+
fastruby "
|
143
|
+
class CFX9
|
144
|
+
def foo(a,x=44,*y)
|
145
|
+
a
|
146
|
+
end
|
147
|
+
end
|
148
|
+
"
|
149
|
+
|
150
|
+
it "should allow splat arguments with default arguments accepting one argument" do
|
151
|
+
CFX9.new.foo(55).should be == 55
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should allow splat arguments with default arguments accepting two argument" do
|
155
|
+
CFX9.new.foo(55,66).should be == 55
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should allow splat arguments with default arguments accepting three argument" do
|
159
|
+
CFX9.new.foo(55,66,77).should be == 55
|
160
|
+
end
|
161
|
+
|
162
|
+
fastruby "
|
163
|
+
class CFX10
|
164
|
+
def foo(a,x=44,*y)
|
165
|
+
x
|
166
|
+
end
|
167
|
+
end
|
168
|
+
"
|
169
|
+
it "should allow splat arguments with default arguments accepting one argument" do
|
170
|
+
CFX10.new.foo(55).should be == 44
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should allow splat arguments with default arguments accepting two argument" do
|
174
|
+
CFX10.new.foo(55,66).should be == 66
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should allow splat arguments with default arguments accepting three argument" do
|
178
|
+
CFX10.new.foo(55,66,77).should be == 66
|
179
|
+
end
|
180
|
+
|
181
|
+
fastruby "
|
182
|
+
class CFX11
|
183
|
+
def foo(a,x=44,*y)
|
184
|
+
y
|
185
|
+
end
|
186
|
+
end
|
187
|
+
"
|
188
|
+
|
189
|
+
it "should raise ArgumentError with splat arguments with default arguments when no arguments are passed" do
|
190
|
+
lambda {
|
191
|
+
CFX11.new.foo
|
192
|
+
}.should raise_error(ArgumentError)
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should allow splat arguments with default arguments accepting one argument" do
|
196
|
+
CFX11.new.foo(55).should be == []
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should allow splat arguments with default arguments accepting two argument" do
|
200
|
+
CFX11.new.foo(55,66).should be == []
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should allow splat arguments with default arguments accepting three argument" do
|
204
|
+
CFX11.new.foo(55,66,77).should be == [77]
|
205
|
+
end
|
206
|
+
|
207
|
+
fastruby "
|
208
|
+
class CFX12
|
209
|
+
def foo(a=0,&block)
|
210
|
+
a
|
211
|
+
end
|
212
|
+
end
|
213
|
+
"
|
214
|
+
|
215
|
+
it "should allow splat arguments with default with block arguments accepting no argument" do
|
216
|
+
CFX12.new.foo() {
|
217
|
+
|
218
|
+
}.should be == 0
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should allow splat arguments with default with block arguments accepting one argument" do
|
222
|
+
CFX12.new.foo(44) {
|
223
|
+
|
224
|
+
}.should be == 44
|
225
|
+
end
|
226
|
+
|
227
|
+
fastruby "
|
228
|
+
class CFX13
|
229
|
+
def foo(a=0,&block)
|
230
|
+
block.call
|
231
|
+
end
|
232
|
+
end
|
233
|
+
"
|
234
|
+
|
235
|
+
it "should allow splat arguments with default with block arguments accepting no argument" do
|
236
|
+
CFX13.new.foo() {
|
237
|
+
66
|
238
|
+
}.should be == 66
|
239
|
+
end
|
240
|
+
|
241
|
+
it "should allow splat arguments with default with block arguments accepting one argument" do
|
242
|
+
CFX13.new.foo(44) {
|
243
|
+
77
|
244
|
+
}.should be == 77
|
245
|
+
end
|
246
|
+
|
247
|
+
fastruby "
|
248
|
+
class CFX14
|
249
|
+
def foo
|
250
|
+
55
|
251
|
+
end
|
252
|
+
end
|
253
|
+
"
|
254
|
+
|
255
|
+
fastruby "
|
256
|
+
class CFX15
|
257
|
+
def foo(cfx14,b = cfx14.foo)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
"
|
261
|
+
|
262
|
+
it "should execute default blocks when no argument is passed" do
|
263
|
+
cfx14 = CFX14.new
|
264
|
+
cfx15 = CFX15.new
|
265
|
+
|
266
|
+
cfx14.should_receive :foo
|
267
|
+
|
268
|
+
cfx15.foo(cfx14)
|
269
|
+
end
|
270
|
+
|
271
|
+
it "should not execute default blocks when argument is passed" do
|
272
|
+
cfx14 = CFX14.new
|
273
|
+
cfx15 = CFX15.new
|
274
|
+
|
275
|
+
cfx14.should_not_receive :foo
|
276
|
+
|
277
|
+
cfx15.foo(cfx14,99)
|
278
|
+
end
|
279
|
+
|
280
|
+
it "should allow if on default argument" do
|
281
|
+
fastruby "
|
282
|
+
class ::CFX16
|
283
|
+
def foo(a, b = if a
|
284
|
+
87
|
285
|
+
else
|
286
|
+
55
|
287
|
+
end
|
288
|
+
)
|
289
|
+
b
|
290
|
+
end
|
291
|
+
end
|
292
|
+
"
|
293
|
+
|
294
|
+
|
295
|
+
cfx16 = ::CFX16.new
|
296
|
+
|
297
|
+
cfx16.foo(false).should be == 55
|
298
|
+
cfx16.foo(true).should be == 87
|
299
|
+
cfx16.foo(true,99).should be == 99
|
300
|
+
cfx16.foo(false,99).should be == 99
|
301
|
+
end
|
302
|
+
|
303
|
+
end
|
@@ -279,4 +279,39 @@ describe FastRuby, "fastruby" do
|
|
279
279
|
|
280
280
|
::CF18.new.foo(1,2,3,4,5).should be == "12345"
|
281
281
|
end
|
282
|
+
|
283
|
+
|
284
|
+
class ::CFF
|
285
|
+
|
286
|
+
end
|
287
|
+
it "should allow define splat arguments on singleton method" do
|
288
|
+
fastruby "
|
289
|
+
class ::CF19
|
290
|
+
def bar(x)
|
291
|
+
def x.foo(*y)
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
295
|
+
"
|
296
|
+
|
297
|
+
x = ::CFF.new
|
298
|
+
::CF19.new.bar(x)
|
299
|
+
x.foo(1,2,3,4,5)
|
300
|
+
end
|
301
|
+
|
302
|
+
it "should read splat arguments on singleton method" do
|
303
|
+
fastruby "
|
304
|
+
class ::CF20
|
305
|
+
def bar(x)
|
306
|
+
def x.foo(*y)
|
307
|
+
y
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
311
|
+
"
|
312
|
+
|
313
|
+
x = ::CFF.new
|
314
|
+
::CF20.new.bar(x)
|
315
|
+
x.foo(1,2,3,4,5).should be == [1,2,3,4,5]
|
316
|
+
end
|
282
317
|
end
|
data/spec/exception/base_spec.rb
CHANGED
@@ -36,4 +36,30 @@ describe FastRuby, "fastruby" do
|
|
36
36
|
}.should_not raise_exception
|
37
37
|
end
|
38
38
|
|
39
|
+
it "should trap exception raised on ensure after return on parent frame" do
|
40
|
+
|
41
|
+
fastruby <<ENDSTR
|
42
|
+
|
43
|
+
class L3
|
44
|
+
def foo
|
45
|
+
yield
|
46
|
+
ensure
|
47
|
+
raise RuntimeError
|
48
|
+
end
|
49
|
+
|
50
|
+
def bar
|
51
|
+
foo do
|
52
|
+
return 4
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
ENDSTR
|
58
|
+
|
59
|
+
lambda {
|
60
|
+
::L3.new.bar
|
61
|
+
}.should raise_exception(RuntimeError)
|
62
|
+
|
63
|
+
end
|
64
|
+
|
39
65
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fastruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 15
|
10
|
+
version: 0.0.15
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dario Seminara
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-11-01 00:00:00 -03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -97,12 +97,14 @@ files:
|
|
97
97
|
- lib/fastruby/method_extension.rb
|
98
98
|
- lib/fastruby/cache/cache.rb
|
99
99
|
- lib/fastruby.rb
|
100
|
+
- lib/targetted
|
100
101
|
- spec/variable_spec.rb
|
101
102
|
- spec/control_spec.rb
|
102
103
|
- spec/return_spec.rb
|
103
104
|
- spec/expression_spec.rb
|
104
105
|
- spec/defn/replacement_spec.rb
|
105
106
|
- spec/defn/multiple_args_spec.rb
|
107
|
+
- spec/defn/default_args_spec.rb
|
106
108
|
- spec/module_spec.rb
|
107
109
|
- spec/jump/next_spec.rb
|
108
110
|
- spec/base_spec.rb
|
@@ -111,7 +113,11 @@ files:
|
|
111
113
|
- spec/block/lambda_spec.rb
|
112
114
|
- spec/block/next_spec.rb
|
113
115
|
- spec/block/break_spec.rb
|
116
|
+
- spec/block/callcc_spec.rb
|
117
|
+
- spec/block/block_as_proc_spec.rb
|
118
|
+
- spec/block/arguments_spec.rb
|
114
119
|
- spec/block/proc_spec.rb
|
120
|
+
- spec/block/proc_as_block_spec.rb
|
115
121
|
- spec/exception/exc_trap_spec.rb
|
116
122
|
- spec/exception/syntaxis_spec.rb
|
117
123
|
- spec/exception/base_spec.rb
|