fastruby 0.0.17 → 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +10 -0
- data/Rakefile +4 -2
- data/benchmarks/benchmark.rb +20 -44
- data/benchmarks/benchmark.rb~ +47 -0
- data/benchmarks/benchmark2.rb +19 -45
- data/benchmarks/benchmark2.rb~ +46 -0
- data/benchmarks/benchmark3.rb +19 -45
- data/benchmarks/benchmark3.rb~ +46 -0
- data/benchmarks/benchmark4.rb +30 -65
- data/benchmarks/benchmark4.rb~ +61 -0
- data/benchmarks/benchmark5.rb +25 -55
- data/benchmarks/benchmark5.rb~ +54 -0
- data/benchmarks/benchmark6.rb +19 -40
- data/benchmarks/benchmark6.rb~ +41 -0
- data/benchmarks/benchmark7.rb +23 -52
- data/benchmarks/benchmark7.rb~ +48 -0
- data/ext/fastruby_base/fastruby_base.inl +1 -0
- data/lib/fastruby/builder.rb +128 -76
- data/lib/fastruby/cache/cache.rb +9 -5
- data/lib/fastruby/fastruby_sexp.rb +18 -0
- data/lib/fastruby/inliner/inliner.rb +68 -0
- data/lib/fastruby/inliner/modules/call.rb +150 -0
- data/lib/fastruby/inliner/modules/recursive.rb +35 -0
- data/lib/fastruby/object.rb +17 -32
- data/lib/fastruby/reductor/modules/case.rb +49 -0
- data/lib/{fastruby.rb~ → fastruby/reductor/modules/for.rb} +11 -13
- data/lib/fastruby/reductor/modules/nontree.rb +31 -0
- data/lib/fastruby/reductor/modules/recursive.rb +31 -0
- data/lib/fastruby/reductor/reductor.rb +39 -0
- data/lib/fastruby/set_tree.rb +7 -1
- data/lib/fastruby/sexp_extension.rb +6 -0
- data/lib/fastruby/translator/modules/block.rb +4 -4
- data/lib/fastruby/translator/modules/call.rb +9 -26
- data/lib/fastruby/translator/modules/defn.rb +5 -3
- data/lib/fastruby/translator/modules/directive.rb +42 -0
- data/lib/fastruby/translator/modules/exceptions.rb +12 -30
- data/lib/fastruby/translator/modules/flow.rb +33 -83
- data/lib/fastruby/translator/modules/iter.rb +4 -7
- data/lib/fastruby/translator/modules/literal.rb +11 -25
- data/lib/fastruby/translator/modules/logical.rb +5 -3
- data/lib/fastruby/translator/modules/method_group.rb +4 -3
- data/lib/fastruby/translator/modules/nonlocal.rb +7 -5
- data/lib/fastruby/translator/modules/static.rb +242 -0
- data/lib/fastruby/translator/modules/variable.rb +16 -9
- data/lib/fastruby/translator/scope_mode_helper.rb +2 -27
- data/lib/fastruby/translator/translator.rb +131 -60
- data/lib/fastruby/translator/translator_modules.rb +6 -2
- data/lib/fastruby.rb +1 -1
- data/spec/reductor/base_spec.rb +46 -0
- data/spec/ruby/base_spec.rb~ +394 -0
- data/spec/ruby/block/arguments_spec.rb~ +214 -0
- data/spec/ruby/block/proc_as_block_spec.rb~ +23 -0
- data/spec/ruby/block/retry_spec.rb~ +43 -0
- data/spec/ruby/block_spec.rb~ +520 -0
- data/spec/ruby/defn/replacement_spec.rb~ +102 -0
- data/spec/ruby/integrity_spec.rb~ +40 -0
- data/spec/ruby/singleton_spec.rb~ +76 -0
- data/spec/scope_mode/base_spec.rb +14 -5
- data/spec/scope_mode/block_spec.rb +18 -9
- data/spec/scope_mode/call_spec.rb +11 -2
- data/spec/scope_mode/exception_spec.rb +11 -2
- data/spec/scope_mode/flow_spec.rb +18 -8
- data/spec/scope_mode/optimization_spec.rb +21 -13
- data/spec/static/base_spec.rb +54 -0
- data/spec/static/flow_spec.rb +48 -0
- data/spec/static/operator_spec.rb +104 -0
- metadata +58 -8
@@ -0,0 +1,394 @@
|
|
1
|
+
require "fastruby"
|
2
|
+
|
3
|
+
class X
|
4
|
+
fastruby "
|
5
|
+
def foo(a,b)
|
6
|
+
return a+b
|
7
|
+
end
|
8
|
+
"
|
9
|
+
def foo2(a,b)
|
10
|
+
return a+b
|
11
|
+
end
|
12
|
+
|
13
|
+
fastruby "
|
14
|
+
def foo3(a)
|
15
|
+
9
|
16
|
+
end
|
17
|
+
"
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
describe FastRuby, "fastruby" do
|
22
|
+
|
23
|
+
def self.test_foo(a,b)
|
24
|
+
it "should execute a method with + of #{a.class}" do
|
25
|
+
x = X.new
|
26
|
+
x.foo(a,b).should be == x.foo2(a,b)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
test_foo(5353531,6000000)
|
31
|
+
test_foo("5353531","6000000")
|
32
|
+
test_foo([1,2,3], [5,6])
|
33
|
+
|
34
|
+
it "methods without return should return last expression result" do
|
35
|
+
X.new.foo3(0).should be == 9
|
36
|
+
end
|
37
|
+
|
38
|
+
class ::X2
|
39
|
+
fastruby "
|
40
|
+
def foo
|
41
|
+
0
|
42
|
+
end
|
43
|
+
"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "methods without arguments should be called" do
|
47
|
+
::X2.new.foo.should be == 0
|
48
|
+
end
|
49
|
+
|
50
|
+
class ::X3
|
51
|
+
fastruby "
|
52
|
+
def foo
|
53
|
+
while false
|
54
|
+
end
|
55
|
+
0
|
56
|
+
end
|
57
|
+
"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should execute methods with while" do
|
61
|
+
::X3.new.foo.should be == 0
|
62
|
+
end
|
63
|
+
|
64
|
+
class ::X4
|
65
|
+
fastruby "
|
66
|
+
def foo
|
67
|
+
i = 10
|
68
|
+
i
|
69
|
+
end
|
70
|
+
"
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should assign and read locals" do
|
74
|
+
::X4.new.foo.should be == 10
|
75
|
+
end
|
76
|
+
|
77
|
+
class ::X5
|
78
|
+
fastruby "
|
79
|
+
def foo
|
80
|
+
i = 10
|
81
|
+
while i > 0
|
82
|
+
i = i - 1
|
83
|
+
end
|
84
|
+
0
|
85
|
+
end
|
86
|
+
"
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should run 10 iterations" do
|
90
|
+
::X5.new.foo.should be == 0
|
91
|
+
end
|
92
|
+
|
93
|
+
class ::A1
|
94
|
+
fastruby "
|
95
|
+
def foo
|
96
|
+
i = 9
|
97
|
+
end
|
98
|
+
"
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should compile a methd with lvar assignment as the last instruction" do
|
102
|
+
::A1.new.foo.should be == 9
|
103
|
+
end
|
104
|
+
|
105
|
+
class ::B2
|
106
|
+
fastruby "
|
107
|
+
def foo
|
108
|
+
self
|
109
|
+
end
|
110
|
+
"
|
111
|
+
end
|
112
|
+
class ::A2
|
113
|
+
fastruby "
|
114
|
+
def foo(b2)
|
115
|
+
b2.foo
|
116
|
+
end
|
117
|
+
"
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should read self of nested frame" do
|
121
|
+
b2 = ::B2.new
|
122
|
+
::A2.new.foo(b2).should be == b2
|
123
|
+
end
|
124
|
+
|
125
|
+
class ::A3
|
126
|
+
fastruby "
|
127
|
+
def foo(x)
|
128
|
+
x.to_i(16)
|
129
|
+
end
|
130
|
+
"
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should execute native methods with variable arguments" do
|
134
|
+
::A3.new.foo("40").should be == 64
|
135
|
+
end
|
136
|
+
|
137
|
+
class ::A4
|
138
|
+
fastruby "
|
139
|
+
def foo(x)
|
140
|
+
x.to_i
|
141
|
+
end
|
142
|
+
"
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should execute native methods with variable arguments (and no arguments is passed)" do
|
146
|
+
::A4.new.foo("40").should be == 40
|
147
|
+
end
|
148
|
+
|
149
|
+
class ::A5
|
150
|
+
fastruby "
|
151
|
+
def bar(x)
|
152
|
+
x
|
153
|
+
end
|
154
|
+
"
|
155
|
+
|
156
|
+
fastruby "
|
157
|
+
def foo(x,a,b)
|
158
|
+
bar(
|
159
|
+
if (x)
|
160
|
+
a
|
161
|
+
else
|
162
|
+
b
|
163
|
+
end
|
164
|
+
)
|
165
|
+
end
|
166
|
+
"
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should compile inline if when passed as argument in a method call" do
|
170
|
+
::A5.new.foo(true,11,12).should be == 11
|
171
|
+
end
|
172
|
+
|
173
|
+
class ::A6
|
174
|
+
fastruby "
|
175
|
+
def bar(x)
|
176
|
+
x
|
177
|
+
end
|
178
|
+
"
|
179
|
+
|
180
|
+
fastruby "
|
181
|
+
def foo(x,a,b)
|
182
|
+
bar(
|
183
|
+
if (x)
|
184
|
+
x.to_s
|
185
|
+
a
|
186
|
+
else
|
187
|
+
x.to_s
|
188
|
+
b
|
189
|
+
end
|
190
|
+
)
|
191
|
+
end
|
192
|
+
"
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should compile inline if when passed as argument in a method call. if as many lines" do
|
196
|
+
::A6.new.foo(true,11,12).should be == 11
|
197
|
+
end
|
198
|
+
|
199
|
+
class ::A7
|
200
|
+
fastruby "
|
201
|
+
def bar(x)
|
202
|
+
x
|
203
|
+
end
|
204
|
+
"
|
205
|
+
|
206
|
+
fastruby "
|
207
|
+
def foo(xz,a,b)
|
208
|
+
bar(
|
209
|
+
if (xz)
|
210
|
+
xz.to_s
|
211
|
+
a
|
212
|
+
else
|
213
|
+
xz.to_s
|
214
|
+
b
|
215
|
+
end
|
216
|
+
) {
|
217
|
+
}
|
218
|
+
end
|
219
|
+
"
|
220
|
+
end
|
221
|
+
|
222
|
+
it "should compile inline if when passed as argument in a method call with block. if has many lines" do
|
223
|
+
::A7.new.foo(true,11,12).should be == 11
|
224
|
+
end
|
225
|
+
|
226
|
+
class ::A8
|
227
|
+
fastruby "
|
228
|
+
def foo(x)
|
229
|
+
a = if (x)
|
230
|
+
x.to_s
|
231
|
+
1
|
232
|
+
else
|
233
|
+
x.to_s
|
234
|
+
2
|
235
|
+
end
|
236
|
+
|
237
|
+
a
|
238
|
+
end
|
239
|
+
"
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should compile inline if at lvar assignment" do
|
243
|
+
::A8.new.foo(true).should be == 1
|
244
|
+
::A8.new.foo(false).should be == 2
|
245
|
+
end
|
246
|
+
|
247
|
+
class ::A9
|
248
|
+
fastruby "
|
249
|
+
def foo(x)
|
250
|
+
if (x)
|
251
|
+
x.to_s
|
252
|
+
1
|
253
|
+
else
|
254
|
+
x.to_s
|
255
|
+
2
|
256
|
+
end
|
257
|
+
end
|
258
|
+
"
|
259
|
+
end
|
260
|
+
|
261
|
+
it "should compile inline if at end of method" do
|
262
|
+
::A9.new.foo(true).should be == 1
|
263
|
+
::A9.new.foo(false).should be == 2
|
264
|
+
end
|
265
|
+
|
266
|
+
class ::A10
|
267
|
+
fastruby '
|
268
|
+
def foo
|
269
|
+
a = nil
|
270
|
+
inline_c "plocals->a = INT2FIX(143)"
|
271
|
+
a
|
272
|
+
end
|
273
|
+
'
|
274
|
+
end
|
275
|
+
|
276
|
+
it "should compile inline C when using inline_c directive" do
|
277
|
+
::A10.new.foo().should be == 143;
|
278
|
+
end
|
279
|
+
|
280
|
+
class ::A11
|
281
|
+
fastruby '
|
282
|
+
def foo(b)
|
283
|
+
a = b
|
284
|
+
inline_c " if (plocals->a == Qnil) {
|
285
|
+
plocals->a = INT2FIX(43);
|
286
|
+
} else {
|
287
|
+
plocals->a = INT2FIX(44);
|
288
|
+
}
|
289
|
+
"
|
290
|
+
a
|
291
|
+
end
|
292
|
+
'
|
293
|
+
end
|
294
|
+
|
295
|
+
it "should compile inline C if when using inline_c directive" do
|
296
|
+
::A11.new.foo(nil).should be == 43;
|
297
|
+
::A11.new.foo(true).should be == 44;
|
298
|
+
end
|
299
|
+
|
300
|
+
class ::A12
|
301
|
+
fastruby '
|
302
|
+
def foo(b)
|
303
|
+
a = b
|
304
|
+
x = inline_c(" if (plocals->a == Qnil) {
|
305
|
+
plocals->a = INT2FIX(43);
|
306
|
+
} else {
|
307
|
+
plocals->a = INT2FIX(44);
|
308
|
+
}
|
309
|
+
")
|
310
|
+
a
|
311
|
+
end
|
312
|
+
'
|
313
|
+
end
|
314
|
+
|
315
|
+
it "should compile inline C when it is used as rvalue and return nil when no return is specified" do
|
316
|
+
::A12.new.foo(55).should be == 44;
|
317
|
+
end
|
318
|
+
|
319
|
+
class ::A13
|
320
|
+
fastruby '
|
321
|
+
def foo(b)
|
322
|
+
a = b
|
323
|
+
x = inline_c(" if (plocals->a == Qnil) {
|
324
|
+
plocals->a = INT2FIX(43);
|
325
|
+
} else {
|
326
|
+
plocals->a = INT2FIX(44);
|
327
|
+
}
|
328
|
+
")
|
329
|
+
x
|
330
|
+
end
|
331
|
+
'
|
332
|
+
end
|
333
|
+
|
334
|
+
it "should compile inline C when it is used as rvalue and assign nil if not return is specified" do
|
335
|
+
::A13.new.foo(55).should be == nil;
|
336
|
+
end
|
337
|
+
|
338
|
+
class ::A14
|
339
|
+
fastruby '
|
340
|
+
def foo(b)
|
341
|
+
a = b
|
342
|
+
x = inline_c(" if (plocals->a == Qnil) {
|
343
|
+
return INT2FIX(43);
|
344
|
+
} else {
|
345
|
+
return INT2FIX(44);
|
346
|
+
}
|
347
|
+
")
|
348
|
+
x
|
349
|
+
end
|
350
|
+
'
|
351
|
+
end
|
352
|
+
|
353
|
+
it "should compile inline C when it is used as rvalue and assign the returned expression" do
|
354
|
+
::A14.new.foo(55).should be == 44;
|
355
|
+
end
|
356
|
+
|
357
|
+
it "should do nothing when execute fastruby with nothing" do
|
358
|
+
lambda {
|
359
|
+
fastruby ""
|
360
|
+
}.should_not raise_error
|
361
|
+
end
|
362
|
+
|
363
|
+
it "should allow basic inheritance" do
|
364
|
+
fastruby "
|
365
|
+
class J56
|
366
|
+
def foo
|
367
|
+
43
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
class ::K56 < J56
|
372
|
+
end
|
373
|
+
"
|
374
|
+
|
375
|
+
::K56.new.foo.should be == 43
|
376
|
+
end
|
377
|
+
|
378
|
+
it "should allow call to self method" do
|
379
|
+
fastruby "
|
380
|
+
class J57
|
381
|
+
def foo
|
382
|
+
43
|
383
|
+
end
|
384
|
+
def bar
|
385
|
+
foo
|
386
|
+
end
|
387
|
+
end
|
388
|
+
"
|
389
|
+
|
390
|
+
::J57.new.foo.should be == 43
|
391
|
+
::J57.new.bar.should be == 43
|
392
|
+
end
|
393
|
+
|
394
|
+
end
|
@@ -0,0 +1,214 @@
|
|
1
|
+
require "fastruby"
|
2
|
+
|
3
|
+
describe FastRuby, "fastruby" do
|
4
|
+
class ::VO1
|
5
|
+
fastruby "
|
6
|
+
def foo(x)
|
7
|
+
yield(*x)
|
8
|
+
end
|
9
|
+
"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should allow pass splat arguments to yield" do
|
13
|
+
::VO1.new.foo([1,2,3]) do |x,y,z|
|
14
|
+
x.should be == 1
|
15
|
+
y.should be == 2
|
16
|
+
z.should be == 3
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class ::VO2
|
21
|
+
fastruby "
|
22
|
+
def foo(x)
|
23
|
+
yield(1,*x)
|
24
|
+
end
|
25
|
+
"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should allow pass normal and splat arguments to yield" do
|
29
|
+
::VO2.new.foo([2,3,4]) do |a,x,y,z|
|
30
|
+
a.should be == 1
|
31
|
+
x.should be == 2
|
32
|
+
y.should be == 3
|
33
|
+
z.should be == 4
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class ::VO3
|
38
|
+
fastruby "
|
39
|
+
def foo(x)
|
40
|
+
yield(1,2,*x)
|
41
|
+
end
|
42
|
+
"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should allow pass two normal args and one splat argument to yield" do
|
46
|
+
::VO3.new.foo([3,4,5]) do |a,b,x,y,z|
|
47
|
+
a.should be == 1
|
48
|
+
b.should be == 2
|
49
|
+
x.should be == 3
|
50
|
+
y.should be == 4
|
51
|
+
z.should be == 5
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should take only the object argument when trying to splat a non-array" do
|
56
|
+
::VO1.new.foo("non-array") do |x|
|
57
|
+
x.should be == "non-array"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class ::VO4
|
62
|
+
|
63
|
+
def bar
|
64
|
+
yield(1,2,3,4)
|
65
|
+
end
|
66
|
+
|
67
|
+
fastruby "
|
68
|
+
def foo
|
69
|
+
bar do |*y|
|
70
|
+
y
|
71
|
+
end
|
72
|
+
end
|
73
|
+
"
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should allow masgn arguments on block passes" do
|
77
|
+
::VO4.new.foo.should be == [1,2,3,4]
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
class ::VO5
|
82
|
+
|
83
|
+
fastruby "
|
84
|
+
def bar
|
85
|
+
yield(1,2,3,4)
|
86
|
+
end
|
87
|
+
|
88
|
+
def foo
|
89
|
+
bar do |*y|
|
90
|
+
y
|
91
|
+
end
|
92
|
+
end
|
93
|
+
"
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should allow masgn arguments on block passes (fastruby call)" do
|
97
|
+
::VO5.new.foo.should be == [1,2,3,4]
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
class ::VO6
|
102
|
+
|
103
|
+
def bar
|
104
|
+
yield(1,2,3,4)
|
105
|
+
end
|
106
|
+
|
107
|
+
fastruby "
|
108
|
+
def foo
|
109
|
+
bar do |a,b,*y|
|
110
|
+
y
|
111
|
+
end
|
112
|
+
end
|
113
|
+
"
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should allow normal arguments with masgn arguments on block passes" do
|
117
|
+
::VO6.new.foo.should be == [3,4]
|
118
|
+
end
|
119
|
+
|
120
|
+
class ::VO7
|
121
|
+
fastruby "
|
122
|
+
def foo
|
123
|
+
pr = proc do |*x|
|
124
|
+
x
|
125
|
+
end
|
126
|
+
pr.call(32)
|
127
|
+
end
|
128
|
+
"
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should allow splat arguments on proc block" do
|
132
|
+
::VO7.new.foo.should be == [32]
|
133
|
+
end
|
134
|
+
|
135
|
+
class ::VO8
|
136
|
+
fastruby "
|
137
|
+
def foo
|
138
|
+
pr = proc do |*x|
|
139
|
+
x
|
140
|
+
end
|
141
|
+
pr.call(32,33,34)
|
142
|
+
end
|
143
|
+
"
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should allow multiple splat arguments on proc block" do
|
147
|
+
::VO8.new.foo.should be == [32,33,34]
|
148
|
+
end
|
149
|
+
|
150
|
+
class ::VO9
|
151
|
+
def bar
|
152
|
+
yield(32)
|
153
|
+
end
|
154
|
+
fastruby "
|
155
|
+
def foo
|
156
|
+
bar do |x|
|
157
|
+
x
|
158
|
+
end
|
159
|
+
end
|
160
|
+
"
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should read single argument on block" do
|
164
|
+
::VO9.new.foo.should be == 32
|
165
|
+
end
|
166
|
+
|
167
|
+
|
168
|
+
class ::VO10
|
169
|
+
fastruby "
|
170
|
+
def foo
|
171
|
+
pr = proc do |*x|
|
172
|
+
x
|
173
|
+
end
|
174
|
+
pr.call([32])
|
175
|
+
end
|
176
|
+
"
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should allow splat arguments on proc block when the argument is an array" do
|
180
|
+
::VO10.new.foo.should be == [[32]]
|
181
|
+
end
|
182
|
+
|
183
|
+
|
184
|
+
class ::VO11
|
185
|
+
fastruby "
|
186
|
+
def foo
|
187
|
+
pr = proc do |*x|
|
188
|
+
x
|
189
|
+
end
|
190
|
+
pr.call([])
|
191
|
+
end
|
192
|
+
"
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should allow splat arguments on proc block when the argument is an array empty" do
|
196
|
+
::VO11.new.foo.should be == [[]]
|
197
|
+
end
|
198
|
+
|
199
|
+
class ::VO12
|
200
|
+
fastruby "
|
201
|
+
def foo
|
202
|
+
pr = proc do |*x|
|
203
|
+
x
|
204
|
+
end
|
205
|
+
pr.call()
|
206
|
+
end
|
207
|
+
"
|
208
|
+
end
|
209
|
+
|
210
|
+
it "should allow splat arguments on proc block when no arguments are passed" do
|
211
|
+
::VO12.new.foo.should be == []
|
212
|
+
end
|
213
|
+
|
214
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "fastruby"
|
2
|
+
|
3
|
+
describe FastRuby, "fastruby" do
|
4
|
+
class ::VY7
|
5
|
+
def foo(a)
|
6
|
+
yield(a)
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
fastruby "
|
11
|
+
def bar(x,block)
|
12
|
+
foo(x){|a|'44'} #,&block)
|
13
|
+
end
|
14
|
+
"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should allow single arguments with block calling ruby methods" do
|
18
|
+
vy7 = ::VY7.new
|
19
|
+
|
20
|
+
block = proc do |a| "44" end
|
21
|
+
vy7.bar(44,block).should be == "44"
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "fastruby"
|
2
|
+
|
3
|
+
describe FastRuby, "fastruby retry statement" do
|
4
|
+
class ::WG2
|
5
|
+
attr_reader :a, :b
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@a = 0
|
9
|
+
@b = 0
|
10
|
+
end
|
11
|
+
|
12
|
+
fastruby "
|
13
|
+
def bar(x)
|
14
|
+
@a = @a + 1
|
15
|
+
|
16
|
+
yield(1)
|
17
|
+
yield(2)
|
18
|
+
yield(3)
|
19
|
+
ensure
|
20
|
+
@b = @b + 1
|
21
|
+
end
|
22
|
+
|
23
|
+
def foo
|
24
|
+
sum = 0
|
25
|
+
bar(0) do |x|
|
26
|
+
# sum = sum + 1
|
27
|
+
# retry if x == 3 and sum < 30
|
28
|
+
end
|
29
|
+
|
30
|
+
sum
|
31
|
+
end
|
32
|
+
"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should work with a method more arguments than zero" do
|
36
|
+
wg2 = ::WG2.new
|
37
|
+
wg2.foo.should be == 30
|
38
|
+
wg2.a.should be == 10
|
39
|
+
wg2.b.should be == 10
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
end
|