fastruby 0.0.19 → 0.0.20
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 +8 -0
- data/{README → README.rdoc} +6 -1
- data/Rakefile +7 -7
- data/benchmarks/benchmark.rb~ +14 -2
- data/ext/fastruby_base/fastruby_base.inl +8 -4
- data/lib/fastruby/builder/inference_updater.rb +76 -0
- data/lib/fastruby/builder/inference_updater.rb~ +76 -0
- data/lib/fastruby/builder/inferencer.rb +38 -0
- data/lib/fastruby/{inliner → builder}/inliner.rb +16 -27
- data/lib/fastruby/builder/inliner.rb~ +60 -0
- data/lib/fastruby/builder/locals_inference.rb +53 -0
- data/lib/fastruby/builder/lvar_type.rb +43 -0
- data/lib/fastruby/builder/lvar_type.rb~ +44 -0
- data/lib/fastruby/builder/pipeline.rb +43 -0
- data/lib/fastruby/builder/pipeline.rb~ +43 -0
- data/lib/fastruby/{reductor → builder}/reductor.rb +6 -3
- data/lib/fastruby/builder/reductor.rb~ +42 -0
- data/lib/fastruby/builder.rb +73 -25
- data/lib/fastruby/builder.rb~ +311 -0
- data/lib/fastruby/corelib/fixnum.rb +75 -0
- data/lib/fastruby/corelib/fixnum.rb~ +146 -0
- data/lib/fastruby/corelib/integer.rb +96 -0
- data/lib/fastruby/corelib/integer.rb~ +96 -0
- data/lib/fastruby/corelib.rb +23 -0
- data/lib/fastruby/corelib.rb~ +23 -0
- data/lib/fastruby/getlocals.rb +3 -1
- data/lib/fastruby/logging.rb +2 -2
- data/lib/fastruby/modules/inferencer/infer.rb +31 -0
- data/lib/fastruby/modules/inferencer/literal.rb +42 -0
- data/lib/fastruby/modules/inliner/call.rb +327 -0
- data/lib/fastruby/{inliner/modules/call.rb → modules/inliner/call.rb~} +14 -24
- data/lib/fastruby/modules/inliner/defn.rb +41 -0
- data/lib/fastruby/modules/inliner/defn.rb~ +29 -0
- data/lib/fastruby/modules/inliner/recursive.rb +40 -0
- data/lib/fastruby/{inliner/modules/recursive.rb → modules/inliner/recursive.rb~} +1 -1
- data/lib/fastruby/modules/lvar_type/call.rb +36 -0
- data/lib/fastruby/modules/lvar_type/call.rb~ +36 -0
- data/lib/fastruby/modules/lvar_type/defn.rb +42 -0
- data/lib/fastruby/modules/lvar_type/defn.rb~ +42 -0
- data/lib/fastruby/modules/lvar_type/lasgn.rb +41 -0
- data/lib/fastruby/modules/lvar_type/lasgn.rb~ +42 -0
- data/lib/fastruby/modules/lvar_type/recursive.rb +33 -0
- data/lib/fastruby/modules/lvar_type/recursive.rb~ +33 -0
- data/lib/fastruby/{reductor/modules → modules/reductor}/case.rb +0 -0
- data/lib/fastruby/modules/reductor/fastruby_flag.rb +33 -0
- data/lib/fastruby/{reductor/modules → modules/reductor}/for.rb +0 -0
- data/lib/fastruby/{reductor/modules → modules/reductor}/nontree.rb +0 -0
- data/lib/fastruby/modules/reductor/nontree.rb~ +32 -0
- data/lib/fastruby/{reductor/modules → modules/reductor}/recursive.rb +1 -1
- data/lib/fastruby/modules/reductor/recursive.rb~ +31 -0
- data/lib/fastruby/{translator/modules → modules/translator}/block.rb +0 -0
- data/lib/fastruby/modules/translator/call.rb +344 -0
- data/lib/fastruby/{translator/modules/call.rb → modules/translator/call.rb~} +24 -3
- data/lib/fastruby/{translator/modules → modules/translator}/defn.rb +10 -9
- data/lib/fastruby/modules/translator/defn.rb~ +267 -0
- data/lib/fastruby/{translator/modules → modules/translator}/directive.rb +3 -1
- data/lib/fastruby/modules/translator/directive.rb~ +44 -0
- data/lib/fastruby/{translator/modules → modules/translator}/exceptions.rb +3 -1
- data/lib/fastruby/modules/translator/exceptions.rb~ +120 -0
- data/lib/fastruby/{translator/modules → modules/translator}/flow.rb +0 -0
- data/lib/fastruby/modules/translator/iter.rb +745 -0
- data/lib/fastruby/{translator/modules/iter.rb → modules/translator/iter.rb~} +103 -48
- data/lib/fastruby/modules/translator/literal.rb +150 -0
- data/lib/fastruby/{translator/modules/literal.rb → modules/translator/literal.rb~} +3 -3
- data/lib/fastruby/{translator/modules → modules/translator}/logical.rb +0 -0
- data/lib/fastruby/{translator/modules → modules/translator}/method_group.rb +0 -0
- data/lib/fastruby/{translator/modules → modules/translator}/nonlocal.rb +18 -6
- data/lib/fastruby/modules/translator/nonlocal.rb~ +298 -0
- data/lib/fastruby/modules/translator/static.rb +290 -0
- data/lib/fastruby/{translator/modules/static.rb → modules/translator/static.rb~} +66 -17
- data/lib/fastruby/modules/translator/variable.rb +280 -0
- data/lib/fastruby/{translator/modules/variable.rb → modules/translator/variable.rb~} +14 -44
- data/lib/fastruby/modules.rb +30 -0
- data/lib/fastruby/object.rb +42 -6
- data/lib/fastruby/object.rb~ +159 -0
- data/lib/fastruby/set_tree.rb +7 -11
- data/lib/fastruby/set_tree.rb~ +71 -0
- data/lib/fastruby/sexp_extension.rb +29 -7
- data/lib/fastruby/sexp_extension.rb~ +262 -0
- data/lib/fastruby/translator/scope_mode_helper.rb~ +138 -0
- data/lib/fastruby/translator/translator.rb +87 -92
- data/lib/fastruby/translator/translator.rb~ +1600 -0
- data/lib/fastruby/translator/translator_modules.rb +3 -1
- data/lib/fastruby/translator/translator_modules.rb~ +53 -0
- data/lib/fastruby.rb +3 -1
- data/lib/fastruby.rb~ +3 -1
- data/lib/fastruby_only/base.rb +1 -0
- data/spec/corelib/numeric/fixnum_spec.rb +110 -0
- data/spec/corelib/numeric/fixnum_spec.rb~ +104 -0
- data/spec/corelib/numeric/integer_spec.rb +173 -0
- data/spec/corelib/numeric/integer_spec.rb~ +173 -0
- data/spec/fastruby_only/base_spec.rb +74 -0
- data/spec/graph/base_spec.rb +2 -1
- data/spec/graph/base_spec.rb~ +35 -0
- data/spec/graph/path_spec.rb +2 -2
- data/spec/graph/path_spec.rb~ +48 -0
- data/spec/graph/vertex_spec.rb +2 -1
- data/spec/graph/vertex_spec.rb~ +58 -0
- data/spec/reductor/base_spec.rb +1 -1
- data/spec/ruby/block/lambda_spec.rb~ +163 -0
- data/spec/ruby/block/proc_as_block_spec.rb~ +69 -1
- data/spec/ruby/block_spec.rb~ +2 -494
- data/spec/ruby/call/base_call_spec.rb +1 -1
- data/spec/ruby/call/base_call_spec.rb~ +2 -60
- data/spec/ruby/defn/replacement_spec.rb +26 -14
- data/spec/ruby/defn/replacement_spec.rb~ +13 -3
- data/spec/ruby/exception/internal_ex_spec.rb~ +86 -0
- data/spec/ruby/integrity_spec.rb~ +35 -1
- data/spec/ruby/variable_spec.rb~ +31 -0
- data/spec/scope_mode/flow_spec.rb +1 -1
- data/spec/scope_mode/flow_spec.rb~ +109 -0
- data/spec/sugar/base_spec.rb +29 -0
- data/spec/sugar/base_spec.rb~ +16 -0
- metadata +100 -43
- data/spec/fastruby/inliner/modules/call_spec.rb +0 -0
- data/spec/fastruby/translator/modules/nonlocal_spec.rb +0 -0
- data/spec/fastruby/translator/translator_spec.rb +0 -0
- data/spec/ruby/block/arguments_spec.rb~ +0 -214
- data/spec/ruby/block/break_spec.rb~ +0 -236
- data/spec/ruby/block/next_spec.rb~ +0 -85
- data/spec/ruby/block/retry_spec.rb~ +0 -43
|
@@ -1,214 +0,0 @@
|
|
|
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
|
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
require "fastruby"
|
|
2
|
-
|
|
3
|
-
describe FastRuby, "fastruby" do
|
|
4
|
-
class ::V1
|
|
5
|
-
fastruby "
|
|
6
|
-
def foo(ary)
|
|
7
|
-
sum = 0
|
|
8
|
-
ary.each do |a|
|
|
9
|
-
sum = sum + a
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
sum
|
|
13
|
-
end
|
|
14
|
-
"
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it "should execute basic test iterating an array" do
|
|
18
|
-
::V1.new.foo([1,2,3]).should be == 6
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
class ::V2
|
|
22
|
-
fastruby "
|
|
23
|
-
def foo(ary)
|
|
24
|
-
sum = 0
|
|
25
|
-
ary.each do |a|
|
|
26
|
-
sum = sum + a
|
|
27
|
-
break
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
sum
|
|
31
|
-
end
|
|
32
|
-
"
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
it "should execute basic test iterating an array with a break" do
|
|
36
|
-
::V2.new.foo([1,2,3]).should be == 1
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
class ::V3
|
|
40
|
-
fastruby "
|
|
41
|
-
def foo(ary)
|
|
42
|
-
sum = 0
|
|
43
|
-
ary.each do |a|
|
|
44
|
-
sum = sum + a
|
|
45
|
-
break if a == 2
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
sum
|
|
49
|
-
end
|
|
50
|
-
"
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
it "should execute basic test iterating an array with a conditional break" do
|
|
54
|
-
::V3.new.foo([1,2,3]).should be == 3
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
class ::V4
|
|
58
|
-
fastruby "
|
|
59
|
-
def foo
|
|
60
|
-
break
|
|
61
|
-
end
|
|
62
|
-
"
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it "should raise LocalJumpError with illegal break" do
|
|
66
|
-
lambda {
|
|
67
|
-
::V4.new.foo
|
|
68
|
-
}.should raise_error(LocalJumpError)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
class ::V5
|
|
72
|
-
fastruby "
|
|
73
|
-
|
|
74
|
-
def each
|
|
75
|
-
yield(1)
|
|
76
|
-
yield(2)
|
|
77
|
-
yield(3)
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def foo
|
|
81
|
-
sum = 0
|
|
82
|
-
each do |a|
|
|
83
|
-
sum = sum + a
|
|
84
|
-
break if a == 2
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
sum
|
|
88
|
-
end
|
|
89
|
-
"
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
it "should execute basic test iterating an array with a conditional break (method with block on fastruby)" do
|
|
93
|
-
::V5.new.foo.should be == 3
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
class ::V6
|
|
97
|
-
fastruby "
|
|
98
|
-
def foo(ary)
|
|
99
|
-
ary.each do |a|
|
|
100
|
-
break 85 if a == 2
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
"
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
it "should allow return value on parent method using break" do
|
|
107
|
-
::V6.new.foo([1,2,3]).should be == 85
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
class ::V7
|
|
111
|
-
|
|
112
|
-
attr_reader :a
|
|
113
|
-
|
|
114
|
-
fastruby "
|
|
115
|
-
|
|
116
|
-
def each
|
|
117
|
-
yield(1)
|
|
118
|
-
yield(2)
|
|
119
|
-
yield(3)
|
|
120
|
-
ensure
|
|
121
|
-
@a = 87
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
def foo
|
|
125
|
-
each do |a|
|
|
126
|
-
break if a == 2
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
"
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
it "should execute ensure on parent frame when using break" do
|
|
133
|
-
x = ::V7.new
|
|
134
|
-
|
|
135
|
-
x.foo
|
|
136
|
-
x.a.should be == 87
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
class ::V8
|
|
141
|
-
|
|
142
|
-
attr_reader :a
|
|
143
|
-
|
|
144
|
-
def each
|
|
145
|
-
yield(1)
|
|
146
|
-
yield(2)
|
|
147
|
-
yield(3)
|
|
148
|
-
ensure
|
|
149
|
-
@a = 87
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
fastruby "
|
|
153
|
-
|
|
154
|
-
def foo
|
|
155
|
-
each do |x|
|
|
156
|
-
break if x == 2
|
|
157
|
-
end
|
|
158
|
-
end
|
|
159
|
-
"
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
it "should execute ensure on parent frame when using break (and called method is ruby)" do
|
|
163
|
-
x = ::V8.new
|
|
164
|
-
|
|
165
|
-
x.foo
|
|
166
|
-
x.a.should be == 87
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
class ::V9
|
|
170
|
-
fastruby "
|
|
171
|
-
def each
|
|
172
|
-
yield(1)
|
|
173
|
-
yield(2)
|
|
174
|
-
yield(3)
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
def foo
|
|
178
|
-
each do |a|
|
|
179
|
-
break 85
|
|
180
|
-
end
|
|
181
|
-
end
|
|
182
|
-
"
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
it "should allow return value on parent method using break when called method is fastruby" do
|
|
186
|
-
::V9.new.foo.should be == 85
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
class ::V10
|
|
192
|
-
|
|
193
|
-
attr_accessor :a, :b, :c, :c_e, :b_e
|
|
194
|
-
|
|
195
|
-
fastruby "
|
|
196
|
-
|
|
197
|
-
def moo
|
|
198
|
-
yield(1)
|
|
199
|
-
@c = 32 # this should't be executed
|
|
200
|
-
ensure
|
|
201
|
-
@c_e = 4
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
def bar
|
|
205
|
-
yield(2)
|
|
206
|
-
@b = 16 # this should't be executed
|
|
207
|
-
ensure
|
|
208
|
-
@b_e = 4
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
def foo
|
|
212
|
-
ret = moo do |x|
|
|
213
|
-
bar do |y|
|
|
214
|
-
break 9
|
|
215
|
-
end
|
|
216
|
-
@a = 111
|
|
217
|
-
break 10
|
|
218
|
-
end
|
|
219
|
-
ret + 1
|
|
220
|
-
end
|
|
221
|
-
|
|
222
|
-
"
|
|
223
|
-
end
|
|
224
|
-
|
|
225
|
-
it "should break for nested blocks" do
|
|
226
|
-
v10 = ::V10.new
|
|
227
|
-
v10.foo.should be == 11
|
|
228
|
-
v10.a.should be == 111
|
|
229
|
-
v10.b.should be == nil
|
|
230
|
-
v10.c.should be == nil
|
|
231
|
-
v10.b_e.should be == 4
|
|
232
|
-
v10.c_e.should be == 4
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
end
|
|
@@ -1,85 +0,0 @@
|
|
|
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
|
|
@@ -1,43 +0,0 @@
|
|
|
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
|