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
data/spec/ruby/block_spec.rb~
CHANGED
|
@@ -1,286 +1,6 @@
|
|
|
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
|
|
284
4
|
|
|
285
5
|
class ::Y22
|
|
286
6
|
fastruby "
|
|
@@ -292,7 +12,7 @@ describe FastRuby, "fastruby" do
|
|
|
292
12
|
fastruby "
|
|
293
13
|
def bar(x)
|
|
294
14
|
i = 10
|
|
295
|
-
lvar_type(i,Fixnum)
|
|
15
|
+
#lvar_type(i,Fixnum)
|
|
296
16
|
x.foo do
|
|
297
17
|
i = i - 1
|
|
298
18
|
end
|
|
@@ -305,216 +25,4 @@ describe FastRuby, "fastruby" do
|
|
|
305
25
|
y22 = ::Y22.new
|
|
306
26
|
y22.bar(y22).should be == 9
|
|
307
27
|
end
|
|
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
|
|
28
|
+
end
|
|
@@ -1,36 +1,7 @@
|
|
|
1
1
|
require "fastruby"
|
|
2
2
|
|
|
3
3
|
describe FastRuby, "fastruby" do
|
|
4
|
-
|
|
5
|
-
it "should allow #{x} arguments calling to cfunc" do
|
|
6
|
-
|
|
7
|
-
arguments = (0..x).map(&:to_s).join(",")
|
|
8
|
-
|
|
9
|
-
fastruby "
|
|
10
|
-
class ::CYR#{x}
|
|
11
|
-
def foo
|
|
12
|
-
a = []
|
|
13
|
-
a.infer(Array).push(#{arguments})
|
|
14
|
-
a
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
eval("::CYR#{x}").new.foo.should be == eval("[#{arguments}]")
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
test_arguments(10)
|
|
24
|
-
test_arguments(15)
|
|
25
|
-
test_arguments(20)
|
|
26
|
-
|
|
27
|
-
(23..27).each do |i|
|
|
28
|
-
test_arguments(i)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
test_arguments(20)
|
|
32
|
-
|
|
33
|
-
|
|
4
|
+
|
|
34
5
|
def self.test_fastruby_arguments(argnum)
|
|
35
6
|
it "should allow #{argnum} arguments calling fastruby" do
|
|
36
7
|
|
|
@@ -50,34 +21,5 @@ describe FastRuby, "fastruby" do
|
|
|
50
21
|
eval("::CYR1_#{argnum}").new.foo(*array).should be == array
|
|
51
22
|
end
|
|
52
23
|
end
|
|
53
|
-
|
|
54
|
-
(8..12).each do |i|
|
|
55
|
-
test_fastruby_arguments(i)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def self.test_invalid_fastruby_arguments(argnum)
|
|
59
|
-
it "should allow #{argnum} arguments calling fastruby" do
|
|
60
|
-
|
|
61
|
-
arguments_name = (0..argnum-1).map{|x| "a"+x.to_s}.join(",")
|
|
62
|
-
arguments = (0..argnum-1).map(&:to_s).join(",")
|
|
63
|
-
|
|
64
|
-
fastruby "
|
|
65
|
-
class ::CYR1_#{argnum}
|
|
66
|
-
def foo(#{arguments_name})
|
|
67
|
-
[#{arguments_name}]
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
"
|
|
71
|
-
|
|
72
|
-
array = eval("[#{arguments}]")
|
|
73
|
-
|
|
74
|
-
lambda {
|
|
75
|
-
eval("::CYR1_#{argnum}").new.foo(*array).should be == array
|
|
76
|
-
}.should raise_error(ArgumentError)
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
#test_invalid_fastruby_arguments(15)
|
|
81
|
-
|
|
82
|
-
test_fastruby_arguments(1)
|
|
24
|
+
test_fastruby_arguments(1024)
|
|
83
25
|
end
|
|
@@ -131,22 +131,34 @@ describe FastRuby, "fastruby" do
|
|
|
131
131
|
end
|
|
132
132
|
|
|
133
133
|
it "should allow replace CFUNC methods using ruby after they are called and compiled at runtime (through other method)" do
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
def foo(a)
|
|
137
|
-
a.conj
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
"
|
|
141
|
-
|
|
142
|
-
::JU6.new.foo(0)
|
|
143
|
-
|
|
134
|
+
begin
|
|
135
|
+
|
|
144
136
|
class Fixnum
|
|
145
|
-
|
|
146
|
-
|
|
137
|
+
alias original_round round
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
fastruby "
|
|
141
|
+
class ::JU6
|
|
142
|
+
def foo(a)
|
|
143
|
+
a.round
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
"
|
|
147
|
+
|
|
148
|
+
::JU6.new.foo(0)
|
|
149
|
+
|
|
150
|
+
class Fixnum
|
|
151
|
+
def round
|
|
152
|
+
86
|
|
153
|
+
end
|
|
147
154
|
end
|
|
155
|
+
|
|
156
|
+
::JU6.new.foo(0).should be == 86
|
|
157
|
+
|
|
158
|
+
ensure
|
|
159
|
+
class Fixnum
|
|
160
|
+
alias round original_round
|
|
148
161
|
end
|
|
149
|
-
|
|
150
|
-
::JU6.new.foo(0).should be == 86
|
|
162
|
+
end
|
|
151
163
|
end
|
|
152
164
|
end
|
|
@@ -131,10 +131,14 @@ describe FastRuby, "fastruby" do
|
|
|
131
131
|
end
|
|
132
132
|
|
|
133
133
|
it "should allow replace CFUNC methods using ruby after they are called and compiled at runtime (through other method)" do
|
|
134
|
-
|
|
134
|
+
class Fixnum
|
|
135
|
+
alias original_round round
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
fastruby "
|
|
135
139
|
class ::JU6
|
|
136
140
|
def foo(a)
|
|
137
|
-
a.
|
|
141
|
+
a.round
|
|
138
142
|
end
|
|
139
143
|
end
|
|
140
144
|
"
|
|
@@ -142,11 +146,17 @@ describe FastRuby, "fastruby" do
|
|
|
142
146
|
::JU6.new.foo(0)
|
|
143
147
|
|
|
144
148
|
class Fixnum
|
|
145
|
-
def
|
|
149
|
+
def round
|
|
146
150
|
86
|
|
147
151
|
end
|
|
148
152
|
end
|
|
149
153
|
|
|
150
154
|
::JU6.new.foo(0).should be == 86
|
|
155
|
+
|
|
156
|
+
ensure
|
|
157
|
+
class Fixnum
|
|
158
|
+
alias round original_round
|
|
159
|
+
end
|
|
160
|
+
|
|
151
161
|
end
|
|
152
162
|
end
|