fastruby 0.0.21 → 0.0.22
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/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
@@ -1,190 +1,13 @@
|
|
1
1
|
require "fastruby"
|
2
2
|
|
3
3
|
describe FastRuby, "fastruby" do
|
4
|
-
class ::LL1
|
5
|
-
fastruby "
|
6
|
-
def foo
|
7
|
-
a = 16
|
8
|
-
lambda {|x|
|
9
|
-
a+x
|
10
|
-
}
|
11
|
-
end
|
12
|
-
"
|
13
|
-
end
|
14
|
-
|
15
|
-
it "lambda must be able to access local variables" do
|
16
|
-
::LL1.new.foo.call(16).should be == 32
|
17
|
-
end
|
18
|
-
|
19
|
-
fastruby "
|
20
|
-
class ::LL2
|
21
|
-
def foo
|
22
|
-
a = 16
|
23
|
-
lambda {|x|
|
24
|
-
a+x
|
25
|
-
}
|
26
|
-
end
|
27
|
-
|
28
|
-
def bar
|
29
|
-
end
|
30
|
-
end
|
31
|
-
"
|
32
|
-
|
33
|
-
it "lambda must be able to access local variables, after another unrelated method is called" do
|
34
|
-
ll2 = ::LL2.new
|
35
|
-
lambda_object = ll2.foo
|
36
|
-
::LL2.new.bar
|
37
|
-
lambda_object.call(16).should be == 32
|
38
|
-
end
|
39
|
-
|
40
|
-
fastruby "
|
41
|
-
class ::LL3
|
42
|
-
def foo(a)
|
43
|
-
lambda {|x|
|
44
|
-
a+x
|
45
|
-
}
|
46
|
-
end
|
47
|
-
|
48
|
-
def bar(y)
|
49
|
-
lambda_object = foo(16)
|
50
|
-
foo(160)
|
51
|
-
lambda_object.call(y)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
"
|
55
|
-
|
56
|
-
it "lambda must be able to access local variables, after another unrelated method is called (from fastruby)" do
|
57
|
-
ll3 = ::LL3.new
|
58
|
-
ll3.bar(1).should be == 17
|
59
|
-
end
|
60
|
-
|
61
|
-
fastruby "
|
62
|
-
class ::LL4
|
63
|
-
def foo
|
64
|
-
lambda {|x|
|
65
|
-
yield(x)
|
66
|
-
}
|
67
|
-
end
|
68
|
-
|
69
|
-
def bar
|
70
|
-
z = 99
|
71
|
-
foo do |x|
|
72
|
-
x+z
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def xt
|
77
|
-
lambda_object = bar()
|
78
|
-
lambda_object.call(1)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
"
|
82
|
-
|
83
|
-
it "lambda must be able to access local variables of parent scopes through yield (from fastruby)" do
|
84
|
-
ll4 = ::LL4.new
|
85
|
-
ll4.xt.should be == 100
|
86
|
-
end
|
87
|
-
|
88
|
-
it "lambda must be able to access local variables of parent scopes through yield" do
|
89
|
-
ll4 = ::LL4.new
|
90
|
-
lambda_object = ll4.bar
|
91
|
-
lambda_object.call(1).should be == 100
|
92
|
-
end
|
93
|
-
|
94
|
-
it "lambda must be able to access local variables of parent scopes through yield on ruby" do
|
95
|
-
ll4 = ::LL4.new
|
96
|
-
|
97
|
-
a = 99
|
98
|
-
|
99
|
-
lambda_object = ll4.foo do |x|
|
100
|
-
x+a
|
101
|
-
end
|
102
|
-
lambda_object.call(1).should be == 100
|
103
|
-
end
|
104
|
-
|
105
|
-
def self.next_sentence(sname)
|
106
|
-
fastruby "
|
107
|
-
class ::LL5#{sname}
|
108
|
-
def foo
|
109
|
-
lambda {
|
110
|
-
#{sname} 100
|
111
|
-
}
|
112
|
-
end
|
113
|
-
end
|
114
|
-
"
|
115
|
-
|
116
|
-
it "lambda #{sname}'s must act as block next" do
|
117
|
-
eval("LL5"+sname).new.foo.call.should be == 100
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
next_sentence("next")
|
122
|
-
next_sentence("break")
|
123
|
-
next_sentence("return")
|
124
|
-
|
125
|
-
def self.illegal_jump(sname)
|
126
|
-
eval "
|
127
|
-
class ::LL6#{sname}
|
128
|
-
def foo
|
129
|
-
lambda {
|
130
|
-
yield
|
131
|
-
}
|
132
|
-
end
|
133
|
-
|
134
|
-
def bar
|
135
|
-
foo do
|
136
|
-
#{sname} 9
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
"
|
141
|
-
|
142
|
-
it "#{sname} inside block should raise LocalJumpError" do
|
143
|
-
ll6 = eval("::LL6"+sname).new
|
144
|
-
lambda {
|
145
|
-
ll6.bar.call
|
146
|
-
}.should raise_error(LocalJumpError)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
# illegal_jump("return")
|
151
|
-
illegal_jump("break")
|
152
|
-
|
153
|
-
|
154
|
-
fastruby "
|
155
|
-
class ::LL7
|
156
|
-
|
157
|
-
def bar(l)
|
158
|
-
l.call
|
159
|
-
yield
|
160
|
-
end
|
161
|
-
|
162
|
-
def foo
|
163
|
-
lambda_obj = lambda {
|
164
|
-
}
|
165
|
-
|
166
|
-
bar(lambda_obj) do
|
167
|
-
break 0
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
"
|
172
|
-
|
173
|
-
it "should break from block after calling lambda" do
|
174
|
-
ll7 = ::LL7.new
|
175
|
-
lambda {
|
176
|
-
ll7.foo.should be == 0
|
177
|
-
}.should_not raise_error
|
178
|
-
end
|
179
|
-
|
180
|
-
|
181
4
|
class ::LL8
|
182
5
|
|
183
6
|
alias alt_lambda lambda
|
184
7
|
|
185
8
|
fastruby "
|
186
9
|
def foo
|
187
|
-
lambda_obj =
|
10
|
+
lambda_obj = lambda {
|
188
11
|
return 9
|
189
12
|
}
|
190
13
|
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require "fastruby"
|
2
|
+
|
3
|
+
describe FastRuby, "fastruby" do
|
4
|
+
class ::W1
|
5
|
+
fastruby "
|
6
|
+
def foo(ary)
|
7
|
+
sum = 0
|
8
|
+
ary.each do |a|
|
9
|
+
next if a == 2
|
10
|
+
sum = sum + a
|
11
|
+
end
|
12
|
+
|
13
|
+
sum
|
14
|
+
end
|
15
|
+
"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should execute basic test iterating an array" do
|
19
|
+
::W1.new.foo([1,2,3]).should be == 4
|
20
|
+
end
|
21
|
+
|
22
|
+
class ::W2
|
23
|
+
fastruby "
|
24
|
+
def foo
|
25
|
+
next
|
26
|
+
end
|
27
|
+
"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should raise LocalJumpError with illegal next" do
|
31
|
+
lambda {
|
32
|
+
::W2.new.foo
|
33
|
+
}.should raise_error(LocalJumpError)
|
34
|
+
end
|
35
|
+
|
36
|
+
class ::W3
|
37
|
+
attr_reader :x, :y
|
38
|
+
|
39
|
+
fastruby "
|
40
|
+
def bar
|
41
|
+
@x = yield(1)
|
42
|
+
@y = yield(2)
|
43
|
+
end
|
44
|
+
|
45
|
+
def foo
|
46
|
+
bar do |a|
|
47
|
+
next 16 if a == 1
|
48
|
+
next 32 if a == 2
|
49
|
+
end
|
50
|
+
end
|
51
|
+
"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should return values on block using next" do
|
55
|
+
x = ::W3.new
|
56
|
+
x.foo
|
57
|
+
x.x.should be == 16
|
58
|
+
x.y.should be == 32
|
59
|
+
end
|
60
|
+
|
61
|
+
class ::W4
|
62
|
+
attr_reader :x, :y
|
63
|
+
|
64
|
+
fastruby "
|
65
|
+
def foo(ary)
|
66
|
+
sum = 0
|
67
|
+
ary.each do |a|
|
68
|
+
begin
|
69
|
+
next if a == 2
|
70
|
+
ensure
|
71
|
+
sum = sum + a
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
sum
|
76
|
+
end
|
77
|
+
"
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should execute ensure when using next" do
|
81
|
+
x = ::W4.new
|
82
|
+
x.foo([1,2,3]).should be == 6
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "fastruby"
|
2
|
+
|
3
|
+
describe FastRuby, "fastruby" do
|
4
|
+
|
5
|
+
eval "
|
6
|
+
class LN9
|
7
|
+
def foo
|
8
|
+
f = Proc.new { return 'return from foo from inside proc' }
|
9
|
+
f.call
|
10
|
+
return 'return from foo'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
"
|
14
|
+
|
15
|
+
it "should return from proc using Proc.new" do
|
16
|
+
ll9 = ::LN9.new
|
17
|
+
lambda {
|
18
|
+
ll9.foo.should be == 'return from foo from inside proc'
|
19
|
+
}.should_not raise_error
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,133 @@
|
|
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
|
+
class ::WB4
|
68
|
+
fastruby <<EOS
|
69
|
+
def foo
|
70
|
+
yield(5)
|
71
|
+
end
|
72
|
+
|
73
|
+
def bar
|
74
|
+
a = true
|
75
|
+
foo do |n|
|
76
|
+
if a
|
77
|
+
a = false
|
78
|
+
n = 555
|
79
|
+
redo
|
80
|
+
end
|
81
|
+
n
|
82
|
+
end
|
83
|
+
end
|
84
|
+
EOS
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should NOT restore variable arguments on block when calling redo" do
|
88
|
+
wb4 = ::WB4.new
|
89
|
+
wb4.bar.should be == 555
|
90
|
+
end
|
91
|
+
|
92
|
+
class ::WB5
|
93
|
+
fastruby <<EOS
|
94
|
+
def bar
|
95
|
+
a = true
|
96
|
+
proc do |n|
|
97
|
+
if a
|
98
|
+
a = false
|
99
|
+
n = 555
|
100
|
+
|
101
|
+
end
|
102
|
+
n
|
103
|
+
end
|
104
|
+
end
|
105
|
+
EOS
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should NOT restore variable arguments on block when calling redo (lambda block)" do
|
109
|
+
wb5 = ::WB5.new
|
110
|
+
wb5.bar.call(5).should be == 555
|
111
|
+
end
|
112
|
+
|
113
|
+
class ::WB6
|
114
|
+
fastruby <<EOS
|
115
|
+
def bar
|
116
|
+
a = true
|
117
|
+
Proc.new do |n|
|
118
|
+
if a
|
119
|
+
a = false
|
120
|
+
n = 555
|
121
|
+
redo
|
122
|
+
end
|
123
|
+
n
|
124
|
+
end
|
125
|
+
end
|
126
|
+
EOS
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should NOT restore variable arguments on block when calling redo (Proc.new block)" do
|
130
|
+
wb6 = ::WB6.new
|
131
|
+
wb6.bar.call(5).should be == 555
|
132
|
+
end
|
133
|
+
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
|