fastruby 0.0.21 → 0.0.22
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/benchmarks/benchmark.rb +3 -0
- data/benchmarks/benchmark.rb~ +3 -12
- data/benchmarks/benchmark8.rb +48 -0
- data/benchmarks/benchmark8.rb~ +46 -0
- data/lib/fastruby.rb +2 -1
- data/lib/fastruby.rb~ +2 -1
- data/lib/fastruby/builder.rb +18 -1
- data/lib/fastruby/builder.rb~ +18 -5
- data/lib/fastruby/modules/lvar_type/lasgn.rb~ +41 -0
- data/lib/fastruby/modules/translator/block.rb +1 -1
- data/lib/fastruby/modules/translator/block.rb~ +128 -0
- data/lib/fastruby/modules/translator/call.rb +62 -139
- data/lib/fastruby/modules/translator/call.rb~ +61 -140
- data/lib/fastruby/modules/translator/defn.rb +49 -105
- data/lib/fastruby/modules/translator/defn.rb~ +211 -0
- data/lib/fastruby/modules/translator/exceptions.rb +1 -0
- data/lib/fastruby/modules/translator/exceptions.rb~ +120 -0
- data/lib/fastruby/modules/translator/iter.rb +13 -20
- data/lib/fastruby/modules/translator/iter.rb~ +738 -0
- data/lib/fastruby/modules/translator/literal.rb +8 -1
- data/lib/fastruby/modules/translator/literal.rb~ +157 -0
- data/lib/fastruby/modules/translator/nonlocal.rb +7 -0
- data/lib/fastruby/modules/translator/nonlocal.rb~ +304 -0
- data/lib/fastruby/modules/translator/static.rb +1 -0
- data/lib/fastruby/modules/translator/static.rb~ +290 -0
- data/lib/fastruby/modules/translator/variable.rb +24 -6
- data/lib/fastruby/modules/translator/variable.rb~ +298 -0
- data/lib/fastruby/translator/translator.rb +411 -284
- data/lib/fastruby/translator/translator.rb~ +1728 -0
- data/spec/fastruby_only/base_spec.rb~ +74 -0
- data/spec/ruby/base_spec.rb~ +1 -338
- data/spec/ruby/block/break_spec.rb~ +21 -0
- data/spec/ruby/block/callcc_spec.rb~ +236 -0
- data/spec/ruby/block/lambda_spec.rb~ +1 -178
- data/spec/ruby/block/next_spec.rb~ +85 -0
- data/spec/ruby/block/proc_spec.rb~ +22 -0
- data/spec/ruby/block/redo_spec.rb~ +133 -0
- data/spec/ruby/block/retry_spec.rb~ +135 -0
- data/spec/ruby/block_spec.rb~ +494 -2
- data/spec/ruby/call/base_call_spec.rb~ +60 -2
- data/spec/ruby/defn/default_args_spec.rb~ +303 -0
- data/spec/ruby/defn/multiple_args_spec.rb~ +317 -0
- data/spec/ruby/defn/replacement_spec.rb +29 -1
- data/spec/ruby/defn/replacement_spec.rb~ +52 -21
- data/spec/ruby/exception/internal_ex_spec.rb~ +2 -2
- data/spec/ruby/variable_spec.rb~ +46 -23
- data/spec/static/flow_spec.rb~ +48 -0
- metadata +34 -12
data/spec/ruby/block_spec.rb~
CHANGED
@@ -1,6 +1,286 @@
|
|
1
1
|
require "fastruby"
|
2
2
|
|
3
3
|
describe FastRuby, "fastruby" do
|
4
|
+
class ::X6
|
5
|
+
fastruby "
|
6
|
+
def foo(ary)
|
7
|
+
ary.each do |a|
|
8
|
+
end
|
9
|
+
0
|
10
|
+
end
|
11
|
+
"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should compile blocks" do
|
15
|
+
::X6.new.foo([1,2,3]).should be == 0
|
16
|
+
end
|
17
|
+
|
18
|
+
class ::X7
|
19
|
+
fastruby "
|
20
|
+
def foo(ary)
|
21
|
+
ary.map do |a|
|
22
|
+
0
|
23
|
+
end
|
24
|
+
end
|
25
|
+
"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should compile blocks with code inside" do
|
29
|
+
::X7.new.foo([1,2,3]).should be == [0,0,0]
|
30
|
+
end
|
31
|
+
|
32
|
+
class ::X8
|
33
|
+
fastruby "
|
34
|
+
def foo(ary)
|
35
|
+
ary.map do |a|
|
36
|
+
a
|
37
|
+
end
|
38
|
+
end
|
39
|
+
"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should compile blocks with code inside refering block arguments" do
|
43
|
+
::X8.new.foo([1,2,3]).should be == [1,2,3]
|
44
|
+
end
|
45
|
+
|
46
|
+
class ::X9
|
47
|
+
fastruby "
|
48
|
+
def foo(hash)
|
49
|
+
hash.map do |k,v|
|
50
|
+
k+v
|
51
|
+
end
|
52
|
+
end
|
53
|
+
"
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should compile blocks with code inside refering multiple block arguments" do
|
57
|
+
::X9.new.foo({1 => 2, 3 => 4}).sort.should be == [3,7]
|
58
|
+
end
|
59
|
+
|
60
|
+
class ::X9_11
|
61
|
+
fastruby "
|
62
|
+
def foo
|
63
|
+
proc do |k,v|
|
64
|
+
k+v
|
65
|
+
end
|
66
|
+
end
|
67
|
+
"
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should compile blocks with code inside refering multiple block arguments (proc)" do
|
71
|
+
pr = ::X9_11.new.foo
|
72
|
+
{1 => 2, 3 => 4}.map(&pr).sort.should be == [3,7]
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
class ::Y10
|
77
|
+
def bar(arg1)
|
78
|
+
yield
|
79
|
+
arg1
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class ::X10
|
84
|
+
fastruby "
|
85
|
+
def foo(obj, arg1)
|
86
|
+
obj.bar(arg1) do |a|
|
87
|
+
end
|
88
|
+
end
|
89
|
+
"
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should compile iter calls with arguments" do
|
93
|
+
::X10.new.foo(::Y10.new, 10).should be == 10
|
94
|
+
end
|
95
|
+
|
96
|
+
class ::Y11
|
97
|
+
def bar(arg1, arg2)
|
98
|
+
yield
|
99
|
+
arg1+arg2
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
class ::X11
|
104
|
+
fastruby "
|
105
|
+
def foo(obj, arg1, arg2)
|
106
|
+
obj.bar(arg1, arg2) do |a|
|
107
|
+
end
|
108
|
+
end
|
109
|
+
"
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should compile iter calls with multiple arguments" do
|
113
|
+
::X11.new.foo(::Y11.new, 10, 9).should be == 19
|
114
|
+
end
|
115
|
+
|
116
|
+
class ::X12
|
117
|
+
fastruby "
|
118
|
+
def foo(ary)
|
119
|
+
a = 1
|
120
|
+
ary.map do |x|
|
121
|
+
a
|
122
|
+
end
|
123
|
+
end
|
124
|
+
"
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should allow accessing local variables from block" do
|
128
|
+
::X12.new.foo([1,2,3,4]).should be == [1,1,1,1]
|
129
|
+
end
|
130
|
+
|
131
|
+
class ::X13
|
132
|
+
fastruby "
|
133
|
+
def foo(ary)
|
134
|
+
a = 1
|
135
|
+
ary.map do |x|
|
136
|
+
a+x
|
137
|
+
end
|
138
|
+
end
|
139
|
+
"
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should allow accessing local variables and block parameters from block" do
|
143
|
+
::X13.new.foo([1,2,3,4]).should be == [2,3,4,5]
|
144
|
+
end
|
145
|
+
|
146
|
+
class ::Y14
|
147
|
+
fastruby "
|
148
|
+
def bar
|
149
|
+
block_given?
|
150
|
+
end
|
151
|
+
"
|
152
|
+
end
|
153
|
+
|
154
|
+
class ::X14
|
155
|
+
fastruby "
|
156
|
+
def foo(y)
|
157
|
+
y.bar
|
158
|
+
end
|
159
|
+
"
|
160
|
+
end
|
161
|
+
|
162
|
+
it "method calls should not repass blocks" do
|
163
|
+
::X14.new.foo(::Y14.new){ }.should be == false
|
164
|
+
end
|
165
|
+
|
166
|
+
class ::X15
|
167
|
+
fastruby "
|
168
|
+
def foo
|
169
|
+
bar
|
170
|
+
end
|
171
|
+
"
|
172
|
+
|
173
|
+
private
|
174
|
+
def bar
|
175
|
+
true
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should allow calls to private methods" do
|
180
|
+
::X15.new.foo.should be == true
|
181
|
+
end
|
182
|
+
|
183
|
+
class ::X16
|
184
|
+
fastruby "
|
185
|
+
def foo
|
186
|
+
bar do
|
187
|
+
12
|
188
|
+
end
|
189
|
+
end
|
190
|
+
"
|
191
|
+
|
192
|
+
def bar
|
193
|
+
yield
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should allow calls with block to self methods" do
|
198
|
+
::X16.new.foo.should be == 12
|
199
|
+
end
|
200
|
+
|
201
|
+
class ::X17
|
202
|
+
fastruby "
|
203
|
+
def foo(z)
|
204
|
+
i = 9
|
205
|
+
z.each do |x|
|
206
|
+
i = x
|
207
|
+
0
|
208
|
+
end
|
209
|
+
i
|
210
|
+
end
|
211
|
+
"
|
212
|
+
end
|
213
|
+
|
214
|
+
it "should allow assignment of locals from blocks" do
|
215
|
+
::X17.new.foo([1,2,3]).should be == 3
|
216
|
+
end
|
217
|
+
|
218
|
+
class ::X18
|
219
|
+
fastruby "
|
220
|
+
def foo
|
221
|
+
yield
|
222
|
+
end
|
223
|
+
"
|
224
|
+
end
|
225
|
+
|
226
|
+
it "should allow block calls" do
|
227
|
+
::X18.new.foo{ 9 }.should be == 9
|
228
|
+
end
|
229
|
+
|
230
|
+
class ::Y19
|
231
|
+
fastruby "
|
232
|
+
def bar
|
233
|
+
yield
|
234
|
+
end
|
235
|
+
"
|
236
|
+
end
|
237
|
+
|
238
|
+
class ::X19
|
239
|
+
fastruby "
|
240
|
+
def foo(y)
|
241
|
+
y.bar {
|
242
|
+
9
|
243
|
+
}
|
244
|
+
end
|
245
|
+
"
|
246
|
+
end
|
247
|
+
|
248
|
+
it "should execute block class between fastruby methods when no block is passed" do
|
249
|
+
::X19.new.foo(::Y19.new).should be == 9
|
250
|
+
end
|
251
|
+
|
252
|
+
it "should execute block class between fastruby methods when block is passed" do
|
253
|
+
::X19.new.foo(::Y19.new){}.should be == 9
|
254
|
+
end
|
255
|
+
|
256
|
+
class ::X20
|
257
|
+
fastruby "
|
258
|
+
def foo
|
259
|
+
yield(1)
|
260
|
+
end
|
261
|
+
"
|
262
|
+
end
|
263
|
+
|
264
|
+
it "should execute block from fastruby methods with one argument" do
|
265
|
+
::X20.new.foo do |n1|
|
266
|
+
n1.should be == 1
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
class ::X21
|
271
|
+
fastruby "
|
272
|
+
def foo
|
273
|
+
yield(1,2)
|
274
|
+
end
|
275
|
+
"
|
276
|
+
end
|
277
|
+
|
278
|
+
it "should execute block from fastruby methods with two arguments" do
|
279
|
+
::X21.new.foo do |n1,n2|
|
280
|
+
n1.should be == 1
|
281
|
+
n2.should be == 2
|
282
|
+
end
|
283
|
+
end
|
4
284
|
|
5
285
|
class ::Y22
|
6
286
|
fastruby "
|
@@ -12,7 +292,7 @@ describe FastRuby, "fastruby" do
|
|
12
292
|
fastruby "
|
13
293
|
def bar(x)
|
14
294
|
i = 10
|
15
|
-
|
295
|
+
lvar_type(i,Fixnum)
|
16
296
|
x.foo do
|
17
297
|
i = i - 1
|
18
298
|
end
|
@@ -25,4 +305,216 @@ describe FastRuby, "fastruby" do
|
|
25
305
|
y22 = ::Y22.new
|
26
306
|
y22.bar(y22).should be == 9
|
27
307
|
end
|
28
|
-
|
308
|
+
|
309
|
+
class ::Y23
|
310
|
+
def foo
|
311
|
+
yield
|
312
|
+
end
|
313
|
+
|
314
|
+
def foo2
|
315
|
+
77
|
316
|
+
end
|
317
|
+
|
318
|
+
fastruby "
|
319
|
+
def bar(x)
|
320
|
+
i = 0
|
321
|
+
x.foo do
|
322
|
+
i = foo2
|
323
|
+
end
|
324
|
+
i
|
325
|
+
end
|
326
|
+
"
|
327
|
+
end
|
328
|
+
|
329
|
+
it "should call self methods from inside a block" do
|
330
|
+
y23 = ::Y23.new
|
331
|
+
y23.bar(y23).should be == 77
|
332
|
+
end
|
333
|
+
|
334
|
+
class ::Y24
|
335
|
+
def foo
|
336
|
+
yield
|
337
|
+
end
|
338
|
+
|
339
|
+
fastruby "
|
340
|
+
def bar(x)
|
341
|
+
i = 0
|
342
|
+
x.foo do
|
343
|
+
i = block_given?
|
344
|
+
end
|
345
|
+
i
|
346
|
+
end
|
347
|
+
"
|
348
|
+
end
|
349
|
+
|
350
|
+
it "should call block_given? from inside a block when a block is not passed should return false" do
|
351
|
+
y24 = ::Y24.new
|
352
|
+
y24.bar(y24).should be == false
|
353
|
+
end
|
354
|
+
|
355
|
+
it "should call block_given? from inside a block when a block is not passed should return true" do
|
356
|
+
y24 = ::Y24.new
|
357
|
+
y24.bar(y24){}.should be == true
|
358
|
+
end
|
359
|
+
|
360
|
+
class ::Y25
|
361
|
+
def foo
|
362
|
+
yield
|
363
|
+
end
|
364
|
+
|
365
|
+
fastruby "
|
366
|
+
def bar(x)
|
367
|
+
i = 0
|
368
|
+
x.foo do
|
369
|
+
i = block_given? do
|
370
|
+
end
|
371
|
+
end
|
372
|
+
i
|
373
|
+
end
|
374
|
+
"
|
375
|
+
end
|
376
|
+
|
377
|
+
it "should call block_given? with block from inside a block when a block is not passed should return false " do
|
378
|
+
y25 = ::Y25.new
|
379
|
+
y25.bar(y25).should be == false
|
380
|
+
end
|
381
|
+
|
382
|
+
it "should call block_given? with block from inside a block when a block is not passed should return true" do
|
383
|
+
y25 = ::Y25.new
|
384
|
+
y25.bar(y25){}.should be == true
|
385
|
+
end
|
386
|
+
|
387
|
+
class ::Y26
|
388
|
+
def bar
|
389
|
+
yield
|
390
|
+
end
|
391
|
+
|
392
|
+
fastruby "
|
393
|
+
def foo
|
394
|
+
bar do
|
395
|
+
yield
|
396
|
+
end
|
397
|
+
end
|
398
|
+
"
|
399
|
+
end
|
400
|
+
|
401
|
+
it "should call yield from inside a block" do
|
402
|
+
y26 = ::Y26.new
|
403
|
+
|
404
|
+
block_num_calls = 0
|
405
|
+
|
406
|
+
y26.foo do
|
407
|
+
block_num_calls = block_num_calls + 1
|
408
|
+
end
|
409
|
+
|
410
|
+
block_num_calls.should be == 1
|
411
|
+
end
|
412
|
+
|
413
|
+
class ::Y27
|
414
|
+
fastruby "
|
415
|
+
def foo(x)
|
416
|
+
x
|
417
|
+
end
|
418
|
+
"
|
419
|
+
end
|
420
|
+
|
421
|
+
class ::Y28
|
422
|
+
fastruby "
|
423
|
+
def foo(y27, a)
|
424
|
+
y27.foo(a) do
|
425
|
+
end
|
426
|
+
end
|
427
|
+
"
|
428
|
+
end
|
429
|
+
|
430
|
+
it "should pass arguments when call with block" do
|
431
|
+
y28 = ::Y28.new
|
432
|
+
y28.foo(::Y27.new, 713).should be == 713
|
433
|
+
end
|
434
|
+
|
435
|
+
class ::Y29
|
436
|
+
fastruby "
|
437
|
+
def foo(ary)
|
438
|
+
cc = nil
|
439
|
+
ary.each do |x|
|
440
|
+
cc = x
|
441
|
+
end
|
442
|
+
cc
|
443
|
+
end
|
444
|
+
"
|
445
|
+
end
|
446
|
+
|
447
|
+
it "should assign variables from inside a block" do
|
448
|
+
::Y29.new.foo([1,2,3]).should be == 3
|
449
|
+
end
|
450
|
+
|
451
|
+
|
452
|
+
class ::Y30
|
453
|
+
attr_accessor :a, :b, :c
|
454
|
+
|
455
|
+
def bar
|
456
|
+
begin
|
457
|
+
doo do
|
458
|
+
yield
|
459
|
+
end
|
460
|
+
ensure
|
461
|
+
@a = 15
|
462
|
+
end
|
463
|
+
end
|
464
|
+
|
465
|
+
fastruby "
|
466
|
+
|
467
|
+
def doo
|
468
|
+
begin
|
469
|
+
yield
|
470
|
+
ensure
|
471
|
+
@b = 16
|
472
|
+
end
|
473
|
+
end
|
474
|
+
|
475
|
+
def foo
|
476
|
+
cc = nil
|
477
|
+
bar do
|
478
|
+
return
|
479
|
+
end
|
480
|
+
ensure
|
481
|
+
@c = 17
|
482
|
+
end
|
483
|
+
"
|
484
|
+
end
|
485
|
+
|
486
|
+
it "should assign variables from inside a block" do
|
487
|
+
y = ::Y30.new
|
488
|
+
y.foo
|
489
|
+
|
490
|
+
y.a.should be == 15
|
491
|
+
y.b.should be == 16
|
492
|
+
y.c.should be == 17
|
493
|
+
end
|
494
|
+
|
495
|
+
class ::Y31
|
496
|
+
fastruby "
|
497
|
+
|
498
|
+
def bar
|
499
|
+
begin
|
500
|
+
yield
|
501
|
+
rescue
|
502
|
+
end
|
503
|
+
end
|
504
|
+
|
505
|
+
def foo
|
506
|
+
bar do
|
507
|
+
return 8
|
508
|
+
end
|
509
|
+
return 0
|
510
|
+
end
|
511
|
+
"
|
512
|
+
end
|
513
|
+
|
514
|
+
it "should return values from block through rescue" do
|
515
|
+
y = ::Y31.new
|
516
|
+
y.foo.should be == 8
|
517
|
+
end
|
518
|
+
|
519
|
+
|
520
|
+
end
|