fastruby 0.0.7 → 0.0.8

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/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.7" unless defined? FastRuby::VERSION
36
+ VERSION = "0.0.8" unless defined? FastRuby::VERSION
37
37
  end
38
38
 
@@ -187,4 +187,50 @@ describe FastRuby, "fastruby" do
187
187
  end
188
188
 
189
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
+
190
236
  end
@@ -0,0 +1,115 @@
1
+ require "fastruby"
2
+
3
+ describe FastRuby, "fastruby" do
4
+ class ::N1
5
+ fastruby "
6
+ def bar(cc)
7
+ cc.call(75)
8
+ end
9
+
10
+ def foo
11
+ callcc do |cc|
12
+ bar(cc)
13
+ end
14
+ end
15
+ "
16
+ end
17
+
18
+ it "should execute callcc on fastruby" do
19
+ ::N1.new.foo.should be == 75
20
+ end
21
+
22
+ class ::N2
23
+ def bar(cc)
24
+ cc.call(76)
25
+ end
26
+
27
+ fastruby "
28
+ def foo
29
+ callcc do |cc|
30
+ bar(cc)
31
+ end
32
+ end
33
+ "
34
+ end
35
+
36
+ it "should execute callcc from ruby" do
37
+ ::N2.new.foo.should be == 76
38
+ end
39
+
40
+ class ::N3
41
+ fastruby "
42
+ def foo(n_)
43
+ n = n_
44
+
45
+ val = 0
46
+ cc = nil
47
+
48
+ x = callcc{|c| cc = c; nil}
49
+
50
+ val = val + x if x
51
+ n = n - 1
52
+
53
+ cc.call(n) if n > 0
54
+
55
+ val
56
+ end
57
+ "
58
+ end
59
+
60
+ it "should execute callcc from ruby using local variables" do
61
+ ::N3.new.foo(4).should be == 6
62
+ end
63
+
64
+ class ::N4
65
+ fastruby "
66
+ def foo(n_)
67
+ $n = n_
68
+
69
+ $val = 0
70
+ c = 0
71
+
72
+
73
+ x = callcc{|c| $cc_n4 = c; nil}
74
+
75
+ $val = $val + x if x
76
+ $n = $n - 1
77
+
78
+ $cc_n4.call($n) if $n > 0
79
+
80
+ $val
81
+ end
82
+ "
83
+ end
84
+
85
+ it "should execute callcc from ruby using global variables" do
86
+ ::N4.new.foo(4).should be == 6
87
+ end
88
+
89
+ class ::N5
90
+ fastruby "
91
+ def foo(n_)
92
+ $n = n_
93
+
94
+ $val = 0
95
+ c = 0
96
+ u = nil
97
+
98
+ x = callcc{|c| $cc_n4 = c; u = 44; nil}
99
+
100
+ $val = $val + x if x
101
+ $n = $n - 1
102
+
103
+ $cc_n4.call($n) if $n > 0
104
+
105
+ u
106
+ end
107
+ "
108
+ end
109
+
110
+ it "should execute callcc loops and preserve local variables" do
111
+ ::N5.new.foo(4).should be == 44
112
+ end
113
+
114
+
115
+ end
@@ -0,0 +1,181 @@
1
+ require "fastruby"
2
+
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
+ fastruby "
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
+ 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: 17
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 7
10
- version: 0.0.7
9
+ - 8
10
+ version: 0.0.8
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-09-02 00:00:00 -03:00
18
+ date: 2011-09-22 00:00:00 -03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -54,8 +54,8 @@ description:
54
54
  email: robertodarioseminara@gmail.com
55
55
  executables: []
56
56
 
57
- extensions: []
58
-
57
+ extensions:
58
+ - ext/fastruby_base/extconf.rb
59
59
  extra_rdoc_files:
60
60
  - README
61
61
  files:
@@ -90,14 +90,18 @@ files:
90
90
  - spec/module_spec.rb
91
91
  - spec/exception_spec.rb
92
92
  - spec/base_spec.rb
93
+ - spec/block/lambda_spec.rb
93
94
  - spec/block/next_spec.rb
94
95
  - spec/block/break_spec.rb
96
+ - spec/block/callcc_spec.rb
95
97
  - spec/block_spec.rb
96
98
  - spec/flow_control/case_spec.rb
97
99
  - spec/sugar_spec.rb
98
100
  - spec/literal_spec.rb
99
101
  - spec/singleton_spec.rb
100
102
  - spec/integrity_spec.rb
103
+ - ext/fastruby_base/fastruby_base.c
104
+ - ext/fastruby_base/extconf.rb
101
105
  - LICENSE
102
106
  - AUTHORS
103
107
  - README