fastruby 0.0.9 → 0.0.10
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 +6 -0
- data/Rakefile +1 -1
- data/lib/fastruby/exceptions.rb +0 -10
- data/lib/fastruby/translator.rb +333 -382
- data/lib/fastruby.rb +1 -1
- data/spec/block/redo_spec.rb +67 -0
- data/spec/block/retry_spec.rb +135 -0
- data/spec/exception/base_spec.rb +39 -0
- data/spec/exception/ensure_spec.rb +52 -0
- data/spec/{exception_spec.rb → exception/exc_trap_spec.rb} +0 -154
- data/spec/exception/syntaxis_spec.rb +89 -0
- data/spec/flow_control/for_spec.rb +40 -0
- data/spec/jump/next_spec.rb +36 -0
- metadata +12 -6
- data/spec/block/callcc_spec.rb +0 -115
data/lib/fastruby.rb
CHANGED
@@ -33,6 +33,6 @@ module FastRuby
|
|
33
33
|
FastRuby.fastruby_script_path = File.expand_path(__FILE__)
|
34
34
|
FastRuby.fastruby_load_path = File.expand_path(File.dirname(__FILE__))
|
35
35
|
|
36
|
-
VERSION = "0.0.
|
36
|
+
VERSION = "0.0.10" unless defined? FastRuby::VERSION
|
37
37
|
end
|
38
38
|
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require "fastruby"
|
2
|
+
|
3
|
+
describe FastRuby, "fastruby redo statement" do
|
4
|
+
class ::WB1
|
5
|
+
fastruby "
|
6
|
+
def bar
|
7
|
+
yield
|
8
|
+
end
|
9
|
+
|
10
|
+
def foo
|
11
|
+
sum = 0
|
12
|
+
bar do
|
13
|
+
sum = sum + 1
|
14
|
+
redo if sum<10
|
15
|
+
end
|
16
|
+
|
17
|
+
sum
|
18
|
+
end
|
19
|
+
"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should execute basic redo" do
|
23
|
+
wb1 = ::WB1.new
|
24
|
+
wb1.foo.should be == 10
|
25
|
+
end
|
26
|
+
|
27
|
+
class ::WB2
|
28
|
+
def bar
|
29
|
+
yield
|
30
|
+
end
|
31
|
+
|
32
|
+
fastruby "
|
33
|
+
|
34
|
+
def foo
|
35
|
+
sum = 0
|
36
|
+
bar do
|
37
|
+
sum = sum + 1
|
38
|
+
redo if sum<10
|
39
|
+
end
|
40
|
+
|
41
|
+
sum
|
42
|
+
end
|
43
|
+
"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should execute basic redo (called method is in ruby)" do
|
47
|
+
wb2 = ::WB2.new
|
48
|
+
wb2.foo.should be == 10
|
49
|
+
end
|
50
|
+
|
51
|
+
class ::WB3
|
52
|
+
fastruby "
|
53
|
+
def foo
|
54
|
+
redo
|
55
|
+
end
|
56
|
+
"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should raise LocalJumpError when invoked illegal redo" do
|
60
|
+
wb3 = ::WB3.new
|
61
|
+
|
62
|
+
lambda {
|
63
|
+
wb3.foo
|
64
|
+
}.should raise_error(LocalJumpError)
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require "fastruby"
|
2
|
+
|
3
|
+
describe FastRuby, "fastruby retry statement" do
|
4
|
+
class ::WG1
|
5
|
+
attr_reader :a, :b
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@a = 0
|
9
|
+
@b = 0
|
10
|
+
end
|
11
|
+
|
12
|
+
fastruby "
|
13
|
+
def bar
|
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 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 execute basic retry" do
|
36
|
+
wg1 = ::WG1.new
|
37
|
+
wg1.foo.should be == 30
|
38
|
+
wg1.a.should be == 10
|
39
|
+
wg1.b.should be == 10
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
class ::WG2
|
44
|
+
attr_reader :a, :b
|
45
|
+
|
46
|
+
def initialize
|
47
|
+
@a = 0
|
48
|
+
@b = 0
|
49
|
+
end
|
50
|
+
|
51
|
+
fastruby "
|
52
|
+
def bar(x)
|
53
|
+
@a = @a + 1
|
54
|
+
|
55
|
+
yield(1)
|
56
|
+
yield(2)
|
57
|
+
yield(3)
|
58
|
+
ensure
|
59
|
+
@b = @b + 1
|
60
|
+
end
|
61
|
+
|
62
|
+
def foo
|
63
|
+
sum = 0
|
64
|
+
bar(0) do |x|
|
65
|
+
sum = sum + 1
|
66
|
+
retry if x == 3 and sum < 30
|
67
|
+
end
|
68
|
+
|
69
|
+
sum
|
70
|
+
end
|
71
|
+
"
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should work with a method more arguments than zero" do
|
75
|
+
wg2 = ::WG2.new
|
76
|
+
wg2.foo.should be == 30
|
77
|
+
wg2.a.should be == 10
|
78
|
+
wg2.b.should be == 10
|
79
|
+
end
|
80
|
+
|
81
|
+
class ::WG3
|
82
|
+
fastruby "
|
83
|
+
def foo
|
84
|
+
sum = 0
|
85
|
+
begin
|
86
|
+
sum = sum + 1
|
87
|
+
raise RuntimeError
|
88
|
+
rescue RuntimeError
|
89
|
+
retry if sum < 10
|
90
|
+
end
|
91
|
+
|
92
|
+
sum
|
93
|
+
end
|
94
|
+
"
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should work with rescue" do
|
98
|
+
::WG3.new.foo.should be == 10
|
99
|
+
end
|
100
|
+
|
101
|
+
class ::WG4
|
102
|
+
fastruby "
|
103
|
+
def foo
|
104
|
+
retry
|
105
|
+
end
|
106
|
+
"
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should raise LocalJumpError when there is no block" do
|
110
|
+
lambda {
|
111
|
+
::WG4.new.foo
|
112
|
+
}.should raise_error(LocalJumpError)
|
113
|
+
end
|
114
|
+
|
115
|
+
class ::WG5
|
116
|
+
attr_accessor :a
|
117
|
+
|
118
|
+
fastruby "
|
119
|
+
def foo
|
120
|
+
retry
|
121
|
+
ensure
|
122
|
+
@a = 1
|
123
|
+
end
|
124
|
+
"
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should trap exceptions generated by illegal retry's" do
|
128
|
+
wg5 = ::WG5.new
|
129
|
+
lambda {
|
130
|
+
wg5.foo
|
131
|
+
}.should raise_error(LocalJumpError)
|
132
|
+
|
133
|
+
wg5.a.should be == 1
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "fastruby"
|
2
|
+
|
3
|
+
describe FastRuby, "fastruby" do
|
4
|
+
it "should allow basic exception control" do
|
5
|
+
fastruby "
|
6
|
+
class ::L1
|
7
|
+
def foo
|
8
|
+
begin
|
9
|
+
rescue
|
10
|
+
end
|
11
|
+
|
12
|
+
0
|
13
|
+
end
|
14
|
+
end
|
15
|
+
"
|
16
|
+
::L1.new.foo.should be == 0
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should allow basic exception control and catch exception" do
|
20
|
+
fastruby "
|
21
|
+
class ::L2
|
22
|
+
def foo
|
23
|
+
begin
|
24
|
+
raise RuntimeError
|
25
|
+
rescue RuntimeError
|
26
|
+
return 1
|
27
|
+
end
|
28
|
+
|
29
|
+
0
|
30
|
+
end
|
31
|
+
end
|
32
|
+
"
|
33
|
+
|
34
|
+
lambda {
|
35
|
+
::L2.new.foo.should be == 1
|
36
|
+
}.should_not raise_exception
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "fastruby"
|
2
|
+
|
3
|
+
describe FastRuby, "fastruby" do
|
4
|
+
it "should allow basic exception control and ensure" do
|
5
|
+
fastruby "
|
6
|
+
class ::L3
|
7
|
+
def foo
|
8
|
+
|
9
|
+
a = 0
|
10
|
+
|
11
|
+
begin
|
12
|
+
raise RuntimeError
|
13
|
+
rescue RuntimeError
|
14
|
+
ensure
|
15
|
+
a = 2
|
16
|
+
end
|
17
|
+
|
18
|
+
a
|
19
|
+
end
|
20
|
+
end
|
21
|
+
"
|
22
|
+
|
23
|
+
lambda {
|
24
|
+
::L3.new.foo.should be == 2
|
25
|
+
}.should_not raise_exception
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should allow basic exception control and ensure without rescue" do
|
29
|
+
class ::L4
|
30
|
+
attr_reader :a
|
31
|
+
|
32
|
+
fastruby "
|
33
|
+
def foo
|
34
|
+
begin
|
35
|
+
raise RuntimeError
|
36
|
+
ensure
|
37
|
+
@a = 2
|
38
|
+
end
|
39
|
+
end
|
40
|
+
"
|
41
|
+
end
|
42
|
+
|
43
|
+
l4 = ::L4.new
|
44
|
+
|
45
|
+
lambda {
|
46
|
+
l4.foo
|
47
|
+
}.should raise_exception(Exception)
|
48
|
+
|
49
|
+
l4.a.should be == 2
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -1,88 +1,6 @@
|
|
1
1
|
require "fastruby"
|
2
2
|
|
3
3
|
describe FastRuby, "fastruby" do
|
4
|
-
it "should allow basic exception control" do
|
5
|
-
fastruby "
|
6
|
-
class ::L1
|
7
|
-
def foo
|
8
|
-
begin
|
9
|
-
rescue
|
10
|
-
end
|
11
|
-
|
12
|
-
0
|
13
|
-
end
|
14
|
-
end
|
15
|
-
"
|
16
|
-
::L1.new.foo.should be == 0
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should allow basic exception control and catch exception" do
|
20
|
-
fastruby "
|
21
|
-
class ::L2
|
22
|
-
def foo
|
23
|
-
begin
|
24
|
-
raise RuntimeError
|
25
|
-
rescue RuntimeError
|
26
|
-
return 1
|
27
|
-
end
|
28
|
-
|
29
|
-
0
|
30
|
-
end
|
31
|
-
end
|
32
|
-
"
|
33
|
-
|
34
|
-
lambda {
|
35
|
-
::L2.new.foo.should be == 1
|
36
|
-
}.should_not raise_exception
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should allow basic exception control and ensure" do
|
40
|
-
fastruby "
|
41
|
-
class ::L3
|
42
|
-
def foo
|
43
|
-
|
44
|
-
a = 0
|
45
|
-
|
46
|
-
begin
|
47
|
-
raise RuntimeError
|
48
|
-
rescue RuntimeError
|
49
|
-
ensure
|
50
|
-
a = 2
|
51
|
-
end
|
52
|
-
|
53
|
-
a
|
54
|
-
end
|
55
|
-
end
|
56
|
-
"
|
57
|
-
|
58
|
-
lambda {
|
59
|
-
::L3.new.foo.should be == 2
|
60
|
-
}.should_not raise_exception
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should allow basic exception control and ensure without rescue" do
|
64
|
-
class ::L4
|
65
|
-
attr_reader :a
|
66
|
-
|
67
|
-
fastruby "
|
68
|
-
def foo
|
69
|
-
begin
|
70
|
-
raise RuntimeError
|
71
|
-
ensure
|
72
|
-
@a = 2
|
73
|
-
end
|
74
|
-
end
|
75
|
-
"
|
76
|
-
end
|
77
|
-
|
78
|
-
l4 = ::L4.new
|
79
|
-
|
80
|
-
lambda {
|
81
|
-
l4.foo
|
82
|
-
}.should raise_exception(Exception)
|
83
|
-
|
84
|
-
l4.a.should be == 2
|
85
|
-
end
|
86
4
|
|
87
5
|
class BahException < Exception
|
88
6
|
end
|
@@ -356,17 +274,6 @@ describe FastRuby, "fastruby" do
|
|
356
274
|
l2.foo("").foo(l1)
|
357
275
|
}.should_not raise_exception
|
358
276
|
end
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
277
|
end
|
371
278
|
end
|
372
279
|
|
@@ -375,66 +282,5 @@ describe FastRuby, "fastruby" do
|
|
375
282
|
basic_unhandled_exception("4", "StandardError")
|
376
283
|
basic_unhandled_exception("5", "Errno::ENOENT")
|
377
284
|
|
378
|
-
it "should accept else with rescue" do
|
379
|
-
|
380
|
-
random_name = "::L11_1"
|
381
|
-
fastruby "
|
382
|
-
class #{random_name}
|
383
|
-
def foo
|
384
|
-
begin
|
385
|
-
raise Exception
|
386
|
-
rescue Exception
|
387
|
-
return 111
|
388
|
-
else
|
389
|
-
return 222
|
390
|
-
end
|
391
|
-
end
|
392
|
-
end
|
393
|
-
"
|
394
|
-
|
395
|
-
l = eval(random_name).new
|
396
|
-
l.foo.should be == 111
|
397
|
-
end
|
398
|
-
|
399
|
-
it "should accept else with rescue, when no exception is raised" do
|
400
|
-
|
401
|
-
random_name = "::L12_1"
|
402
|
-
fastruby "
|
403
|
-
class #{random_name}
|
404
|
-
def foo
|
405
|
-
begin
|
406
|
-
rescue Exception
|
407
|
-
return 111
|
408
|
-
else
|
409
|
-
return 222
|
410
|
-
end
|
411
|
-
end
|
412
|
-
end
|
413
|
-
"
|
414
|
-
|
415
|
-
l = eval(random_name).new
|
416
|
-
l.foo.should be == 222
|
417
|
-
end
|
418
|
-
|
419
|
-
it "should accept else with rescue, when no exception is raised and begin has body" do
|
420
|
-
|
421
|
-
random_name = "::L13_1"
|
422
|
-
fastruby "
|
423
|
-
class #{random_name}
|
424
|
-
def foo
|
425
|
-
begin
|
426
|
-
a = 77
|
427
|
-
rescue Exception
|
428
|
-
return 111
|
429
|
-
else
|
430
|
-
return 222
|
431
|
-
end
|
432
|
-
end
|
433
|
-
end
|
434
|
-
"
|
435
|
-
|
436
|
-
l = eval(random_name).new
|
437
|
-
l.foo.should be == 222
|
438
|
-
end
|
439
285
|
|
440
286
|
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require "fastruby"
|
2
|
+
|
3
|
+
describe FastRuby, "fastruby" do
|
4
|
+
|
5
|
+
it "should accept else with rescue" do
|
6
|
+
|
7
|
+
random_name = "::L11_1"
|
8
|
+
fastruby "
|
9
|
+
class #{random_name}
|
10
|
+
def foo
|
11
|
+
begin
|
12
|
+
raise Exception
|
13
|
+
rescue Exception
|
14
|
+
return 111
|
15
|
+
else
|
16
|
+
return 222
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
"
|
21
|
+
|
22
|
+
l = eval(random_name).new
|
23
|
+
l.foo.should be == 111
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should accept else with rescue, when no exception is raised" do
|
27
|
+
|
28
|
+
random_name = "::L12_1"
|
29
|
+
fastruby "
|
30
|
+
class #{random_name}
|
31
|
+
def foo
|
32
|
+
begin
|
33
|
+
rescue Exception
|
34
|
+
return 111
|
35
|
+
else
|
36
|
+
return 222
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
"
|
41
|
+
|
42
|
+
l = eval(random_name).new
|
43
|
+
l.foo.should be == 222
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should accept else with rescue, when no exception is raised and begin has body" do
|
47
|
+
|
48
|
+
random_name = "::L13_1"
|
49
|
+
fastruby "
|
50
|
+
class #{random_name}
|
51
|
+
def foo
|
52
|
+
begin
|
53
|
+
a = 77
|
54
|
+
rescue Exception
|
55
|
+
return 111
|
56
|
+
else
|
57
|
+
return 222
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
"
|
62
|
+
|
63
|
+
l = eval(random_name).new
|
64
|
+
l.foo.should be == 222
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.argumentless_rescue(exceptionname)
|
68
|
+
fastruby "
|
69
|
+
class ::L15_#{exceptionname}
|
70
|
+
def foo
|
71
|
+
begin
|
72
|
+
raise #{exceptionname}
|
73
|
+
rescue
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
"
|
78
|
+
|
79
|
+
it "should argumentless rescue catch #{exceptionname}" do
|
80
|
+
l15 = eval("::L15_#{exceptionname}").new
|
81
|
+
lambda {
|
82
|
+
l15.foo
|
83
|
+
}.should_not raise_exception
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
argumentless_rescue("RuntimeError")
|
88
|
+
|
89
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "fastruby"
|
2
|
+
|
3
|
+
describe FastRuby, "for statement" do
|
4
|
+
class ::OX1
|
5
|
+
fastruby '
|
6
|
+
def foo(a)
|
7
|
+
for i in a
|
8
|
+
end
|
9
|
+
end
|
10
|
+
'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should invoke each" do
|
14
|
+
ox1 = ::OX1.new
|
15
|
+
a = [1,2,3]
|
16
|
+
a.should_receive(:each)
|
17
|
+
ox1.foo(a)
|
18
|
+
end
|
19
|
+
|
20
|
+
class ::OX2
|
21
|
+
fastruby '
|
22
|
+
def foo(a)
|
23
|
+
ret = 0
|
24
|
+
|
25
|
+
for i in a
|
26
|
+
ret = ret + i
|
27
|
+
end
|
28
|
+
|
29
|
+
ret
|
30
|
+
end
|
31
|
+
'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should read i on each for iteration" do
|
35
|
+
ox2 = ::OX2.new
|
36
|
+
a = [1,2,3]
|
37
|
+
ox2.foo(a).should be == 6
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "fastruby"
|
2
|
+
|
3
|
+
describe FastRuby, "fastruby" do
|
4
|
+
it "should next on block throught multiple frames" do
|
5
|
+
fastruby "
|
6
|
+
class ::PX1
|
7
|
+
attr_accessor :a,:b
|
8
|
+
|
9
|
+
def bar
|
10
|
+
yield
|
11
|
+
end
|
12
|
+
|
13
|
+
def foo
|
14
|
+
bar do
|
15
|
+
begin
|
16
|
+
begin
|
17
|
+
next 72
|
18
|
+
ensure
|
19
|
+
@a = 1
|
20
|
+
end
|
21
|
+
ensure
|
22
|
+
@b = 2
|
23
|
+
end
|
24
|
+
|
25
|
+
87
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
"
|
30
|
+
px1= ::PX1.new
|
31
|
+
px1.foo.should be == 72
|
32
|
+
px1.a.should be == 1
|
33
|
+
px1.b.should be == 2
|
34
|
+
|
35
|
+
end
|
36
|
+
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: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 10
|
10
|
+
version: 0.0.10
|
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-10-02 00:00:00 -03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -88,15 +88,21 @@ files:
|
|
88
88
|
- spec/return_spec.rb
|
89
89
|
- spec/expression_spec.rb
|
90
90
|
- spec/module_spec.rb
|
91
|
-
- spec/
|
91
|
+
- spec/jump/next_spec.rb
|
92
92
|
- spec/base_spec.rb
|
93
|
+
- spec/block/redo_spec.rb
|
94
|
+
- spec/block/retry_spec.rb
|
93
95
|
- spec/block/lambda_spec.rb
|
94
96
|
- spec/block/next_spec.rb
|
95
97
|
- spec/block/break_spec.rb
|
96
|
-
- spec/block/callcc_spec.rb
|
97
98
|
- spec/block/proc_spec.rb
|
99
|
+
- spec/exception/exc_trap_spec.rb
|
100
|
+
- spec/exception/syntaxis_spec.rb
|
101
|
+
- spec/exception/base_spec.rb
|
102
|
+
- spec/exception/ensure_spec.rb
|
98
103
|
- spec/block_spec.rb
|
99
104
|
- spec/flow_control/case_spec.rb
|
105
|
+
- spec/flow_control/for_spec.rb
|
100
106
|
- spec/sugar_spec.rb
|
101
107
|
- spec/literal_spec.rb
|
102
108
|
- spec/singleton_spec.rb
|