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.
Files changed (49) hide show
  1. data/Rakefile +1 -1
  2. data/benchmarks/benchmark.rb +3 -0
  3. data/benchmarks/benchmark.rb~ +3 -12
  4. data/benchmarks/benchmark8.rb +48 -0
  5. data/benchmarks/benchmark8.rb~ +46 -0
  6. data/lib/fastruby.rb +2 -1
  7. data/lib/fastruby.rb~ +2 -1
  8. data/lib/fastruby/builder.rb +18 -1
  9. data/lib/fastruby/builder.rb~ +18 -5
  10. data/lib/fastruby/modules/lvar_type/lasgn.rb~ +41 -0
  11. data/lib/fastruby/modules/translator/block.rb +1 -1
  12. data/lib/fastruby/modules/translator/block.rb~ +128 -0
  13. data/lib/fastruby/modules/translator/call.rb +62 -139
  14. data/lib/fastruby/modules/translator/call.rb~ +61 -140
  15. data/lib/fastruby/modules/translator/defn.rb +49 -105
  16. data/lib/fastruby/modules/translator/defn.rb~ +211 -0
  17. data/lib/fastruby/modules/translator/exceptions.rb +1 -0
  18. data/lib/fastruby/modules/translator/exceptions.rb~ +120 -0
  19. data/lib/fastruby/modules/translator/iter.rb +13 -20
  20. data/lib/fastruby/modules/translator/iter.rb~ +738 -0
  21. data/lib/fastruby/modules/translator/literal.rb +8 -1
  22. data/lib/fastruby/modules/translator/literal.rb~ +157 -0
  23. data/lib/fastruby/modules/translator/nonlocal.rb +7 -0
  24. data/lib/fastruby/modules/translator/nonlocal.rb~ +304 -0
  25. data/lib/fastruby/modules/translator/static.rb +1 -0
  26. data/lib/fastruby/modules/translator/static.rb~ +290 -0
  27. data/lib/fastruby/modules/translator/variable.rb +24 -6
  28. data/lib/fastruby/modules/translator/variable.rb~ +298 -0
  29. data/lib/fastruby/translator/translator.rb +411 -284
  30. data/lib/fastruby/translator/translator.rb~ +1728 -0
  31. data/spec/fastruby_only/base_spec.rb~ +74 -0
  32. data/spec/ruby/base_spec.rb~ +1 -338
  33. data/spec/ruby/block/break_spec.rb~ +21 -0
  34. data/spec/ruby/block/callcc_spec.rb~ +236 -0
  35. data/spec/ruby/block/lambda_spec.rb~ +1 -178
  36. data/spec/ruby/block/next_spec.rb~ +85 -0
  37. data/spec/ruby/block/proc_spec.rb~ +22 -0
  38. data/spec/ruby/block/redo_spec.rb~ +133 -0
  39. data/spec/ruby/block/retry_spec.rb~ +135 -0
  40. data/spec/ruby/block_spec.rb~ +494 -2
  41. data/spec/ruby/call/base_call_spec.rb~ +60 -2
  42. data/spec/ruby/defn/default_args_spec.rb~ +303 -0
  43. data/spec/ruby/defn/multiple_args_spec.rb~ +317 -0
  44. data/spec/ruby/defn/replacement_spec.rb +29 -1
  45. data/spec/ruby/defn/replacement_spec.rb~ +52 -21
  46. data/spec/ruby/exception/internal_ex_spec.rb~ +2 -2
  47. data/spec/ruby/variable_spec.rb~ +46 -23
  48. data/spec/static/flow_spec.rb~ +48 -0
  49. metadata +34 -12
@@ -0,0 +1,74 @@
1
+ require "fastruby"
2
+
3
+ describe FastRuby, "FastRuby" do
4
+ it "should accept fastruby_only option" do
5
+ fastruby "
6
+ class FRONLY1
7
+ def foo
8
+ 100
9
+ end
10
+ end
11
+ ", :fastruby_only => true
12
+ end
13
+
14
+ it "should accept fastruby_only option, methods defined with that option should not be callable from normal ruby" do
15
+ fastruby "
16
+ class FRONLY2
17
+ def fronly2_foo
18
+ 100
19
+ end
20
+ end
21
+ ", :fastruby_only => true
22
+
23
+ lambda {
24
+ FRONLY2.new.fronly2_foo
25
+ }.should raise_error(NoMethodError)
26
+ end
27
+
28
+ it "should accept fastruby_only option, methods defined with that option should be callable from fastruby" do
29
+ fastruby "
30
+ class FRONLY3
31
+ def foo
32
+ 100
33
+ end
34
+ end
35
+ ", :fastruby_only => true
36
+
37
+ fastruby "
38
+ class FRONLY3
39
+ def bar
40
+ foo
41
+ end
42
+ end
43
+ "
44
+
45
+ FRONLY3.new.bar.should be == 100
46
+ end
47
+
48
+ it "should accept fastruby_only option, and two versions of the same method" do
49
+ class FRONLY4
50
+ def foo
51
+ 200
52
+ end
53
+ end
54
+
55
+ fastruby "
56
+ class FRONLY4
57
+ def foo
58
+ 100
59
+ end
60
+ end
61
+ ", :fastruby_only => true
62
+
63
+ fastruby "
64
+ class FRONLY4
65
+ def bar
66
+ foo
67
+ end
68
+ end
69
+ "
70
+
71
+ FRONLY4.new.bar.should be == 100
72
+ FRONLY4.new.foo.should be == 200
73
+ end
74
+ end
@@ -20,302 +20,6 @@ end
20
20
 
21
21
  describe FastRuby, "fastruby" do
22
22
 
23
- def self.test_foo(a,b)
24
- it "should execute a method with + of #{a.class}" do
25
- x = X.new
26
- x.foo(a,b).should be == x.foo2(a,b)
27
- end
28
- end
29
-
30
- test_foo(5353531,6000000)
31
- test_foo("5353531","6000000")
32
- test_foo([1,2,3], [5,6])
33
-
34
- it "methods without return should return last expression result" do
35
- X.new.foo3(0).should be == 9
36
- end
37
-
38
- class ::X2
39
- fastruby "
40
- def foo
41
- 0
42
- end
43
- "
44
- end
45
-
46
- it "methods without arguments should be called" do
47
- ::X2.new.foo.should be == 0
48
- end
49
-
50
- class ::X3
51
- fastruby "
52
- def foo
53
- while false
54
- end
55
- 0
56
- end
57
- "
58
- end
59
-
60
- it "should execute methods with while" do
61
- ::X3.new.foo.should be == 0
62
- end
63
-
64
- class ::X4
65
- fastruby "
66
- def foo
67
- i = 10
68
- i
69
- end
70
- "
71
- end
72
-
73
- it "should assign and read locals" do
74
- ::X4.new.foo.should be == 10
75
- end
76
-
77
- class ::X5
78
- fastruby "
79
- def foo
80
- i = 10
81
- while i > 0
82
- i = i - 1
83
- end
84
- 0
85
- end
86
- "
87
- end
88
-
89
- it "should run 10 iterations" do
90
- ::X5.new.foo.should be == 0
91
- end
92
-
93
- class ::A1
94
- fastruby "
95
- def foo
96
- i = 9
97
- end
98
- "
99
- end
100
-
101
- it "should compile a methd with lvar assignment as the last instruction" do
102
- ::A1.new.foo.should be == 9
103
- end
104
-
105
- class ::B2
106
- fastruby "
107
- def foo
108
- self
109
- end
110
- "
111
- end
112
- class ::A2
113
- fastruby "
114
- def foo(b2)
115
- b2.foo
116
- end
117
- "
118
- end
119
-
120
- it "should read self of nested frame" do
121
- b2 = ::B2.new
122
- ::A2.new.foo(b2).should be == b2
123
- end
124
-
125
- class ::A3
126
- fastruby "
127
- def foo(x)
128
- x.to_i(16)
129
- end
130
- "
131
- end
132
-
133
- it "should execute native methods with variable arguments" do
134
- ::A3.new.foo("40").should be == 64
135
- end
136
-
137
- class ::A4
138
- fastruby "
139
- def foo(x)
140
- x.to_i
141
- end
142
- "
143
- end
144
-
145
- it "should execute native methods with variable arguments (and no arguments is passed)" do
146
- ::A4.new.foo("40").should be == 40
147
- end
148
-
149
- class ::A5
150
- fastruby "
151
- def bar(x)
152
- x
153
- end
154
- "
155
-
156
- fastruby "
157
- def foo(x,a,b)
158
- bar(
159
- if (x)
160
- a
161
- else
162
- b
163
- end
164
- )
165
- end
166
- "
167
- end
168
-
169
- it "should compile inline if when passed as argument in a method call" do
170
- ::A5.new.foo(true,11,12).should be == 11
171
- end
172
-
173
- class ::A6
174
- fastruby "
175
- def bar(x)
176
- x
177
- end
178
- "
179
-
180
- fastruby "
181
- def foo(x,a,b)
182
- bar(
183
- if (x)
184
- x.to_s
185
- a
186
- else
187
- x.to_s
188
- b
189
- end
190
- )
191
- end
192
- "
193
- end
194
-
195
- it "should compile inline if when passed as argument in a method call. if as many lines" do
196
- ::A6.new.foo(true,11,12).should be == 11
197
- end
198
-
199
- class ::A7
200
- fastruby "
201
- def bar(x)
202
- x
203
- end
204
- "
205
-
206
- fastruby "
207
- def foo(x,a,b)
208
- bar(
209
- if (x)
210
- x.to_s
211
- a
212
- else
213
- x.to_s
214
- b
215
- end
216
- ) {
217
- }
218
- end
219
- "
220
- end
221
-
222
- it "should compile inline if when passed as argument in a method call with block. if has many lines" do
223
- ::A7.new.foo(true,11,12).should be == 11
224
- end
225
-
226
- class ::A8
227
- fastruby "
228
- def foo(x)
229
- a = if (x)
230
- x.to_s
231
- 1
232
- else
233
- x.to_s
234
- 2
235
- end
236
-
237
- a
238
- end
239
- "
240
- end
241
-
242
- it "should compile inline if at lvar assignment" do
243
- ::A8.new.foo(true).should be == 1
244
- ::A8.new.foo(false).should be == 2
245
- end
246
-
247
- class ::A9
248
- fastruby "
249
- def foo(x)
250
- if (x)
251
- x.to_s
252
- 1
253
- else
254
- x.to_s
255
- 2
256
- end
257
- end
258
- "
259
- end
260
-
261
- it "should compile inline if at end of method" do
262
- ::A9.new.foo(true).should be == 1
263
- ::A9.new.foo(false).should be == 2
264
- end
265
-
266
- class ::A10
267
- fastruby '
268
- def foo
269
- a = nil
270
- inline_c "plocals->a = INT2FIX(143)"
271
- a
272
- end
273
- '
274
- end
275
-
276
- it "should compile inline C when using inline_c directive" do
277
- ::A10.new.foo().should be == 143;
278
- end
279
-
280
- class ::A11
281
- fastruby '
282
- def foo(b)
283
- a = b
284
- inline_c " if (plocals->a == Qnil) {
285
- plocals->a = INT2FIX(43);
286
- } else {
287
- plocals->a = INT2FIX(44);
288
- }
289
- "
290
- a
291
- end
292
- '
293
- end
294
-
295
- it "should compile inline C if when using inline_c directive" do
296
- ::A11.new.foo(nil).should be == 43;
297
- ::A11.new.foo(true).should be == 44;
298
- end
299
-
300
- class ::A12
301
- fastruby '
302
- def foo(b)
303
- a = b
304
- x = inline_c(" if (plocals->a == Qnil) {
305
- plocals->a = INT2FIX(43);
306
- } else {
307
- plocals->a = INT2FIX(44);
308
- }
309
- ")
310
- a
311
- end
312
- '
313
- end
314
-
315
- it "should compile inline C when it is used as rvalue and return nil when no return is specified" do
316
- ::A12.new.foo(55).should be == 44;
317
- end
318
-
319
23
  class ::A13
320
24
  fastruby '
321
25
  def foo(b)
@@ -350,45 +54,4 @@ describe FastRuby, "fastruby" do
350
54
  '
351
55
  end
352
56
 
353
- it "should compile inline C when it is used as rvalue and assign the returned expression" do
354
- ::A14.new.foo(55).should be == 44;
355
- end
356
-
357
- it "should do nothing when execute fastruby with nothing" do
358
- lambda {
359
- fastruby ""
360
- }.should_not raise_error
361
- end
362
-
363
- it "should allow basic inheritance" do
364
- fastruby "
365
- class J56
366
- def foo
367
- 43
368
- end
369
- end
370
-
371
- class ::K56 < J56
372
- end
373
- "
374
-
375
- ::K56.new.foo.should be == 43
376
- end
377
-
378
- it "should allow call to self method" do
379
- fastruby "
380
- class J57
381
- def foo
382
- 43
383
- end
384
- def bar
385
- foo
386
- end
387
- end
388
- "
389
-
390
- ::J57.new.foo.should be == 43
391
- ::J57.new.bar.should be == 43
392
- end
393
-
394
- end
57
+ end
@@ -0,0 +1,21 @@
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 + 1
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
+ end
@@ -0,0 +1,236 @@
1
+ require "fastruby"
2
+ if RUBY_VERSION =~ /^1\.9/
3
+ require "continuation"
4
+ end
5
+
6
+ describe FastRuby, "fastruby" do
7
+ class ::N1
8
+ fastruby "
9
+ def bar(cc)
10
+ cc.call(75)
11
+ end
12
+
13
+ def foo
14
+ callcc do |cc|
15
+ bar(cc)
16
+ end
17
+ end
18
+ "
19
+ end
20
+
21
+ it "should execute callcc on fastruby" do
22
+ ::N1.new.foo.should be == 75
23
+ end
24
+
25
+ class ::N2
26
+ def bar(cc)
27
+ cc.call(76)
28
+ end
29
+
30
+ fastruby "
31
+ def foo
32
+ callcc do |cc|
33
+ bar(cc)
34
+ end
35
+ end
36
+ "
37
+ end
38
+
39
+ it "should execute callcc from ruby" do
40
+ ::N2.new.foo.should be == 76
41
+ end
42
+
43
+ class ::N3
44
+ fastruby "
45
+ def foo(n_)
46
+ n = n_
47
+
48
+ val = 0
49
+ cc = nil
50
+
51
+ x = callcc{|c| cc = c; nil}
52
+
53
+ val = val + x if x
54
+ n = n - 1
55
+
56
+ cc.call(n) if n > 0
57
+
58
+ val
59
+ end
60
+ "
61
+ end
62
+
63
+ it "should execute callcc from ruby using local variables" do
64
+ ::N3.new.foo(4).should be == 6
65
+ end
66
+
67
+ class ::N4
68
+ fastruby "
69
+ def foo(n_)
70
+ $n = n_
71
+
72
+ $val = 0
73
+ c = 0
74
+
75
+
76
+ x = callcc{|c| $cc_n4 = c; nil}
77
+
78
+ $val = $val + x if x
79
+ $n = $n - 1
80
+
81
+ $cc_n4.call($n) if $n > 0
82
+
83
+ $val
84
+ end
85
+ "
86
+ end
87
+
88
+ it "should execute callcc from ruby using global variables" do
89
+ ::N4.new.foo(4).should be == 6
90
+ end
91
+
92
+ class ::N5
93
+ fastruby "
94
+ def foo(n_)
95
+ $n = n_
96
+
97
+ $val = 0
98
+ c = 0
99
+ u = nil
100
+
101
+ x = callcc{|c| $cc_n4 = c; u = 44; nil}
102
+
103
+ $val = $val + x if x
104
+ $n = $n - 1
105
+
106
+ $cc_n4.call($n) if $n > 0
107
+
108
+ u
109
+ end
110
+ "
111
+ end
112
+
113
+ it "should execute callcc loops and preserve local variables" do
114
+ ::N5.new.foo(4).should be == 44
115
+ end
116
+
117
+ class ::N6
118
+ fastruby "
119
+
120
+ def bar
121
+ a = 5555
122
+
123
+ callcc do |cc|
124
+ $cc = cc
125
+ end
126
+
127
+ a
128
+ end
129
+
130
+ def another_method(n)
131
+ a = 9999
132
+ another_method(n-1) if n>0
133
+ end
134
+
135
+ def foo
136
+
137
+ $called = nil
138
+
139
+ ret = bar
140
+ another_method(200)
141
+
142
+ unless $called
143
+ $called = 1
144
+ $cc.call
145
+ end
146
+
147
+ ret
148
+ end
149
+ "
150
+ end
151
+
152
+ it "should execute callcc loops and preserve local variables when another method is called after callcc" do
153
+ ::N6.new.foo.should be == 5555
154
+ end
155
+
156
+
157
+ it "shouldn't raise LocalJumpError from proc being called on callcc de-initialized stack" do
158
+
159
+ fastruby <<ENDSTR
160
+
161
+ class ::N7
162
+ def foo
163
+ val = nil
164
+
165
+ pr = Proc.new do
166
+ return val
167
+ end
168
+
169
+ val = callcc do |cc|
170
+ $cc = cc
171
+ end
172
+
173
+ pr.call
174
+ end
175
+
176
+ def bar
177
+ ret = foo
178
+
179
+ if ret.instance_of? Continuation
180
+ ret.call(4)
181
+ else
182
+ $cc.call(ret-1) if ret > 0
183
+ end
184
+ end
185
+ end
186
+
187
+ ENDSTR
188
+
189
+
190
+ n7 = ::N7.new
191
+ lambda {
192
+ n7.bar
193
+ }.should_not raise_error(LocalJumpError)
194
+ end
195
+
196
+ it "should raise LocalJumpError from proc defined on abandoned stack after Continuation#call" do
197
+
198
+ fastruby <<ENDSTR
199
+ class ::N8
200
+ def bar
201
+ ret = callcc do |cc|
202
+ $cc_n8 = cc
203
+ end
204
+
205
+ if ret == 9
206
+ $pr_n8.call
207
+ end
208
+
209
+ ret
210
+ end
211
+
212
+ def foo3
213
+ $cc_n8.call(9)
214
+ end
215
+
216
+ def foo2
217
+ $pr_n8 = Proc.new do
218
+ return
219
+ end
220
+
221
+ foo3
222
+ end
223
+
224
+ def foo
225
+ return if bar == 9
226
+ foo2
227
+ end
228
+ end
229
+ ENDSTR
230
+
231
+ n8 = ::N8.new
232
+ lambda {
233
+ n8.foo
234
+ }.should raise_error(LocalJumpError)
235
+ end
236
+ end