fastruby 0.0.12 → 0.0.13

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.
@@ -0,0 +1,49 @@
1
+ =begin
2
+
3
+ This file is part of the fastruby project, http://github.com/tario/fastruby
4
+
5
+ Copyright (c) 2011 Roberto Dario Seminara <robertodarioseminara@gmail.com>
6
+
7
+ fastruby is free software: you can redistribute it and/or modify
8
+ it under the terms of the gnu general public license as published by
9
+ the free software foundation, either version 3 of the license, or
10
+ (at your option) any later version.
11
+
12
+ fastruby is distributed in the hope that it will be useful,
13
+ but without any warranty; without even the implied warranty of
14
+ merchantability or fitness for a particular purpose. see the
15
+ gnu general public license for more details.
16
+
17
+ you should have received a copy of the gnu general public license
18
+ along with fastruby. if not, see <http://www.gnu.org/licenses/>.
19
+
20
+ =end
21
+ require "singleton"
22
+
23
+ module FastRuby
24
+ class TranslatorModules
25
+ include Singleton
26
+
27
+ attr_accessor :modls
28
+
29
+ def initialize
30
+ @modls = Array.new
31
+ end
32
+
33
+ def register_translator_module(modl)
34
+ @modls << modl
35
+ end
36
+
37
+ def load_under(dir)
38
+ Dir.glob(dir + "/*.rb") do |x|
39
+ require x
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ module Kernel
46
+ def register_translator_module(modl)
47
+ FastRuby::TranslatorModules.instance.register_translator_module(modl)
48
+ end
49
+ end
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.12" unless defined? FastRuby::VERSION
36
+ VERSION = "0.0.13" unless defined? FastRuby::VERSION
37
37
  end
38
38
 
@@ -0,0 +1,87 @@
1
+ require "fastruby"
2
+
3
+ describe FastRuby, "fastruby" do
4
+ it "should allow basic array expansion" do
5
+ class ::CY1
6
+ def bar(*x)
7
+ x
8
+ end
9
+ fastruby "
10
+ def foo(x)
11
+ bar(*x)
12
+ end
13
+ "
14
+ end
15
+
16
+ ::CY1.new.foo([1,2,3]).should be == [1,2,3]
17
+ end
18
+
19
+ it "should allow basic array expansion plus single argument" do
20
+ class ::CY2
21
+ def bar(*x)
22
+ x
23
+ end
24
+ fastruby "
25
+ def foo(x)
26
+ bar(100,*x)
27
+ end
28
+ "
29
+ end
30
+
31
+ ::CY2.new.foo([1,2,3]).should be == [100,1,2,3]
32
+ end
33
+
34
+
35
+ it "should allow basic array expansion with block" do
36
+ class ::CY3
37
+ def bar(*x)
38
+ x
39
+ end
40
+ fastruby "
41
+ def foo(x)
42
+ bar(*x) do
43
+ end
44
+ end
45
+ "
46
+ end
47
+
48
+ ::CY3.new.foo([1,2,3]).should be == [1,2,3]
49
+ end
50
+
51
+ it "should allow basic array expansion plus single argument with block" do
52
+ class ::CY4
53
+ def bar(*x)
54
+ x
55
+ end
56
+ fastruby "
57
+ def foo(x)
58
+ bar(100,*x) do
59
+ end
60
+ end
61
+ "
62
+ end
63
+
64
+ ::CY4.new.foo([1,2,3]).should be == [100,1,2,3]
65
+ end
66
+
67
+ class ::CY5
68
+ def bar(*x)
69
+ x
70
+ end
71
+ fastruby "
72
+ def foo(x)
73
+ bar(*x)
74
+ end
75
+ "
76
+ end
77
+
78
+ it "should allow long array of 8192 elements" do
79
+ ::CY5.new.foo([0]*8192).should be == [0]*8192
80
+ end
81
+
82
+ it "should allow non-array element (should be converted to array)" do
83
+ ::CY5.new.foo(0).should be == [0]
84
+ end
85
+
86
+
87
+ end
@@ -0,0 +1,271 @@
1
+ require "fastruby"
2
+
3
+ describe FastRuby, "fastruby" do
4
+ it "should allow define method with array arguments" do
5
+ lambda {
6
+ fastruby "
7
+ class CF1
8
+ def foo(*x)
9
+ end
10
+ end
11
+ "
12
+ }.should_not raise_error
13
+ end
14
+
15
+ it "should allow define method with array arguments and call with no arguments" do
16
+ lambda {
17
+ fastruby "
18
+ class ::CF2
19
+ def foo(*x)
20
+ x
21
+ end
22
+ end
23
+ "
24
+
25
+ ::CF2.new.foo().should be == []
26
+ }.should_not raise_error
27
+ end
28
+
29
+ it "should allow define method with array arguments and call with one argument" do
30
+ lambda {
31
+ fastruby "
32
+ class ::CF3
33
+ def foo(*x)
34
+ x
35
+ end
36
+ end
37
+ "
38
+
39
+ ::CF3.new.foo(1).should be == [1]
40
+ }.should_not raise_error
41
+ end
42
+
43
+ it "should allow define method with array arguments and call with two arguments" do
44
+ lambda {
45
+ fastruby "
46
+ class ::CF4
47
+ def foo(*x)
48
+ x
49
+ end
50
+ end
51
+ "
52
+
53
+ ::CF4.new.foo(1,2).should be == [1,2]
54
+ }.should_not raise_error
55
+ end
56
+
57
+ it "should allow define method with normal argument plus array arguments and call with one argument" do
58
+ lambda {
59
+ fastruby "
60
+ class ::CF5
61
+ def foo(a, *x)
62
+ x
63
+ end
64
+ end
65
+ "
66
+
67
+ ::CF5.new.foo(1).should be == []
68
+ }.should_not raise_error
69
+ end
70
+
71
+ it "should allow define method with normal argument plus array arguments and call with two arguments" do
72
+ lambda {
73
+ fastruby "
74
+ class ::CF6
75
+ def foo(a, *x)
76
+ x
77
+ end
78
+ end
79
+ "
80
+
81
+ ::CF6.new.foo(1,2).should be == [2]
82
+ }.should_not raise_error
83
+ end
84
+
85
+ it "should allow define method with normal argument plus array arguments and call with one argument" do
86
+ lambda {
87
+ fastruby "
88
+ class ::CF7
89
+ def foo(a, *x)
90
+ a
91
+ end
92
+ end
93
+ "
94
+
95
+ ::CF7.new.foo(1).should be == 1
96
+ }.should_not raise_error
97
+ end
98
+
99
+ it "should allow define method with normal argument plus array arguments and call with two arguments" do
100
+ lambda {
101
+ fastruby "
102
+ class ::CF8
103
+ def foo(a, *x)
104
+ a
105
+ end
106
+ end
107
+ "
108
+
109
+ ::CF8.new.foo(1,2).should be == 1
110
+ }.should_not raise_error
111
+ end
112
+
113
+ it "should allow define method with array arguments and call with no arguments from fastruby" do
114
+ lambda {
115
+ fastruby "
116
+ class ::CF9
117
+ def foo(*x)
118
+ x
119
+ end
120
+
121
+ def bar
122
+ foo
123
+ end
124
+ end
125
+ "
126
+
127
+ ::CF9.new.bar.should be == []
128
+ }.should_not raise_error
129
+ end
130
+
131
+ it "should allow define method with array arguments and call with one argument from fastruby" do
132
+ lambda {
133
+ fastruby "
134
+ class ::CF10
135
+ def foo(*x)
136
+ x
137
+ end
138
+
139
+ def bar
140
+ foo(1)
141
+ end
142
+ end
143
+ "
144
+
145
+ ::CF10.new.bar.should be == [1]
146
+ }.should_not raise_error
147
+ end
148
+
149
+ it "should allow define method with array arguments and call with two arguments from fastruby" do
150
+ lambda {
151
+ fastruby "
152
+ class ::CF11
153
+ def foo(*x)
154
+ x
155
+ end
156
+
157
+ def bar
158
+ foo(1,2)
159
+ end
160
+ end
161
+ "
162
+
163
+ ::CF11.new.bar.should be == [1,2]
164
+ }.should_not raise_error
165
+ end
166
+
167
+ it "should allow define method with normal argument plus array arguments and call with one argument from fastruby" do
168
+ lambda {
169
+ fastruby "
170
+ class ::CF12
171
+ def foo(a, *x)
172
+ x
173
+ end
174
+
175
+ def bar
176
+ foo(1)
177
+ end
178
+ end
179
+ "
180
+
181
+ ::CF12.new.bar.should be == []
182
+ }.should_not raise_error
183
+ end
184
+
185
+ it "should allow define method with normal argument plus array arguments and call with two arguments from fastruby" do
186
+ lambda {
187
+ fastruby "
188
+ class ::CF13
189
+ def foo(a, *x)
190
+ x
191
+ end
192
+
193
+ def bar
194
+ foo(1,2)
195
+ end
196
+ end
197
+ "
198
+
199
+ ::CF13.new.bar.should be == [2]
200
+ }.should_not raise_error
201
+ end
202
+
203
+ it "should allow define method with normal argument plus array arguments and call with one argument from fastruby" do
204
+ lambda {
205
+ fastruby "
206
+ class ::CF14
207
+ def foo(a, *x)
208
+ a
209
+ end
210
+
211
+ def bar
212
+ foo(1)
213
+ end
214
+ end
215
+ "
216
+
217
+ ::CF14.new.bar.should be == 1
218
+ }.should_not raise_error
219
+ end
220
+
221
+ it "should allow define method with normal argument plus array arguments and call with two arguments from fastruby" do
222
+ lambda {
223
+ fastruby "
224
+ class ::CF15
225
+ def foo(a, *x)
226
+ a
227
+ end
228
+
229
+ def bar
230
+ foo(1.2)
231
+ end
232
+ end
233
+ "
234
+
235
+ ::CF15.new.foo(1,2).should be == 1
236
+ }.should_not raise_error
237
+ end
238
+
239
+ it "should raise ArgumentError when trying to call with too few arguments" do
240
+ lambda {
241
+ fastruby "
242
+ class ::CF16
243
+ def foo(a, *x)
244
+ a
245
+ end
246
+ end
247
+ "
248
+
249
+ ::CF16.new.foo
250
+ }.should raise_error(ArgumentError)
251
+ end
252
+
253
+ it "should raise ArgumentError when trying to call with too few arguments from fastruby" do
254
+ lambda {
255
+ fastruby "
256
+ class ::CF17
257
+ def foo(a, *x)
258
+ a
259
+ end
260
+
261
+ def bar
262
+ foo
263
+ end
264
+ end
265
+ "
266
+
267
+ ::CF17.new.bar
268
+ }.should raise_error(ArgumentError)
269
+ end
270
+
271
+ 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: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 12
10
- version: 0.0.12
9
+ - 13
10
+ version: 0.0.13
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-10-06 00:00:00 -03:00
18
+ date: 2011-10-09 00:00:00 -03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -77,10 +77,20 @@ files:
77
77
  - lib/fastruby/exceptions.rb
78
78
  - lib/fastruby/getlocals.rb
79
79
  - lib/fastruby/sexp_extension.rb
80
- - lib/fastruby/translator.rb
81
80
  - lib/fastruby/object.rb
82
- - lib/fastruby/translator/iter.rb
83
- - lib/fastruby/translator/call.rb
81
+ - lib/fastruby/translator/translator_modules.rb
82
+ - lib/fastruby/translator/modules/logical.rb
83
+ - lib/fastruby/translator/modules/flow.rb
84
+ - lib/fastruby/translator/modules/variable.rb
85
+ - lib/fastruby/translator/modules/exceptions.rb
86
+ - lib/fastruby/translator/modules/defn.rb
87
+ - lib/fastruby/translator/modules/method_group.rb
88
+ - lib/fastruby/translator/modules/iter.rb
89
+ - lib/fastruby/translator/modules/call.rb
90
+ - lib/fastruby/translator/modules/block.rb
91
+ - lib/fastruby/translator/modules/nonlocal.rb
92
+ - lib/fastruby/translator/modules/literal.rb
93
+ - lib/fastruby/translator/translator.rb
84
94
  - lib/fastruby/fastruby_sexp.rb
85
95
  - lib/fastruby/method_extension.rb
86
96
  - lib/fastruby/cache/cache.rb
@@ -89,6 +99,7 @@ files:
89
99
  - spec/control_spec.rb
90
100
  - spec/return_spec.rb
91
101
  - spec/expression_spec.rb
102
+ - spec/defn/multiple_args_spec.rb
92
103
  - spec/module_spec.rb
93
104
  - spec/jump/next_spec.rb
94
105
  - spec/base_spec.rb
@@ -110,6 +121,7 @@ files:
110
121
  - spec/literal_spec.rb
111
122
  - spec/singleton_spec.rb
112
123
  - spec/integrity_spec.rb
124
+ - spec/call/multiple_args_spec.rb
113
125
  - ext/fastruby_base/fastruby_base.inl
114
126
  - ext/fastruby_base/fastruby_base.c
115
127
  - ext/fastruby_base/extconf.rb