fastruby 0.0.16 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +17 -1
- data/Rakefile +1 -1
- data/ext/fastruby_base/fastruby_base.inl +81 -3
- data/lib/fastruby/fastruby_sexp.rb +21 -0
- data/lib/fastruby/getlocals.rb +2 -1
- data/lib/fastruby/object.rb +1 -1
- data/lib/fastruby/sexp_extension.rb +189 -0
- data/lib/fastruby/sexp_extension_edges.rb +210 -0
- data/lib/fastruby/translator/modules/block.rb +29 -22
- data/lib/fastruby/translator/modules/call.rb +211 -34
- data/lib/fastruby/translator/modules/defn.rb +64 -29
- data/lib/fastruby/translator/modules/exceptions.rb +1 -1
- data/lib/fastruby/translator/modules/flow.rb +93 -31
- data/lib/fastruby/translator/modules/iter.rb +277 -340
- data/lib/fastruby/translator/modules/literal.rb +97 -20
- data/lib/fastruby/translator/modules/logical.rb +40 -5
- data/lib/fastruby/translator/modules/method_group.rb +41 -19
- data/lib/fastruby/translator/modules/nonlocal.rb +74 -29
- data/lib/fastruby/translator/modules/variable.rb +151 -42
- data/lib/fastruby/translator/scope_mode_helper.rb +161 -0
- data/lib/fastruby/translator/translator.rb +389 -302
- data/lib/fastruby.rb +1 -1
- data/lib/fastruby.rb~ +36 -0
- data/spec/edges_helper.rb +91 -0
- data/spec/graph/base_spec.rb +35 -0
- data/spec/graph/path_spec.rb +48 -0
- data/spec/graph/vertex_spec.rb +58 -0
- data/spec/ruby/block/proc_as_block_spec.rb +214 -0
- data/spec/ruby/block/redo_spec.rb +133 -0
- data/spec/ruby/defn/single_function_spec.rb +50 -0
- data/spec/scope_mode/base_spec.rb +55 -0
- data/spec/scope_mode/block_spec.rb +105 -0
- data/spec/scope_mode/call_spec.rb +24 -0
- data/spec/scope_mode/exception_spec.rb +34 -0
- data/spec/scope_mode/flow_spec.rb +99 -0
- data/spec/scope_mode/optimization_spec.rb +130 -0
- data/spec/sexp2graph/base_spec.rb +36 -0
- data/spec/sexp2graph/exception_spec.rb +172 -0
- data/spec/sexp2graph/flow_spec.rb +67 -0
- data/spec/sexp2graph/logical_spec.rb +21 -0
- data/spec/sexp2graph/variable_spec.rb +26 -0
- metadata +110 -120
- data/lib/fastruby/self +0 -82
- data/lib/len +0 -280
- data/spec/block/proc_as_block_spec.rb +0 -111
- data/spec/block/redo_spec.rb +0 -67
- /data/spec/{base_spec.rb → ruby/base_spec.rb} +0 -0
- /data/spec/{block → ruby/block}/arguments_spec.rb +0 -0
- /data/spec/{block → ruby/block}/block_as_proc_spec.rb +0 -0
- /data/spec/{block → ruby/block}/break_spec.rb +0 -0
- /data/spec/{block → ruby/block}/callcc_spec.rb +0 -0
- /data/spec/{block → ruby/block}/lambda_spec.rb +0 -0
- /data/spec/{block → ruby/block}/next_spec.rb +0 -0
- /data/spec/{block → ruby/block}/proc_spec.rb +0 -0
- /data/spec/{block → ruby/block}/retry_spec.rb +0 -0
- /data/spec/{block_spec.rb → ruby/block_spec.rb} +0 -0
- /data/spec/{call → ruby/call}/base_call_spec.rb +0 -0
- /data/spec/{call → ruby/call}/multiple_args_spec.rb +0 -0
- /data/spec/{control_spec.rb → ruby/control_spec.rb} +0 -0
- /data/spec/{defn → ruby/defn}/default_args_spec.rb +0 -0
- /data/spec/{defn → ruby/defn}/multiple_args_spec.rb +0 -0
- /data/spec/{defn → ruby/defn}/replacement_spec.rb +0 -0
- /data/spec/{exception → ruby/exception}/base_spec.rb +0 -0
- /data/spec/{exception → ruby/exception}/ensure_spec.rb +0 -0
- /data/spec/{exception → ruby/exception}/exc_trap_spec.rb +0 -0
- /data/spec/{exception → ruby/exception}/internal_ex_spec.rb +0 -0
- /data/spec/{exception → ruby/exception}/syntaxis_spec.rb +0 -0
- /data/spec/{expression_spec.rb → ruby/expression_spec.rb} +0 -0
- /data/spec/{flow_control → ruby/flow_control}/case_spec.rb +0 -0
- /data/spec/{flow_control → ruby/flow_control}/for_spec.rb +0 -0
- /data/spec/{integrity_spec.rb → ruby/integrity_spec.rb} +0 -0
- /data/spec/{jump → ruby/jump}/next_spec.rb +0 -0
- /data/spec/{literal_spec.rb → ruby/literal_spec.rb} +0 -0
- /data/spec/{module_spec.rb → ruby/module_spec.rb} +0 -0
- /data/spec/{return_spec.rb → ruby/return_spec.rb} +0 -0
- /data/spec/{singleton_spec.rb → ruby/singleton_spec.rb} +0 -0
- /data/spec/{sugar_spec.rb → ruby/sugar_spec.rb} +0 -0
- /data/spec/{variable_spec.rb → ruby/variable_spec.rb} +0 -0
data/lib/fastruby.rb
CHANGED
data/lib/fastruby.rb~
ADDED
@@ -0,0 +1,36 @@
|
|
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 "fastruby/exceptions"
|
22
|
+
require "fastruby/object"
|
23
|
+
require "fastruby/exceptions"
|
24
|
+
require "fastruby/custom_require"
|
25
|
+
require "fastruby/set_tree"
|
26
|
+
require "base64"
|
27
|
+
|
28
|
+
class Object
|
29
|
+
def self.decode64(value)
|
30
|
+
Base64.decode64(value)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module FastRuby
|
35
|
+
VERSION = "0.0.16" unless defined? FastRuby::VERSION
|
36
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module EdgesHelper
|
2
|
+
|
3
|
+
class GraphEdges < Array
|
4
|
+
def initialize(sexp); @sexp = sexp; end
|
5
|
+
|
6
|
+
def to_sexp(obj, &blk)
|
7
|
+
if obj.instance_of? Symbol
|
8
|
+
blk.call @sexp.find_tree{|st| st.node_type == :call and st[2] == obj}
|
9
|
+
elsif obj.instance_of? Array
|
10
|
+
obj.each do |element|
|
11
|
+
to_sexp(element,&blk)
|
12
|
+
end
|
13
|
+
else
|
14
|
+
blk.call obj
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def tr_edges(hash)
|
19
|
+
hash.each do |k,v|
|
20
|
+
to_sexp(k) do |a|
|
21
|
+
to_sexp(v) do |b|
|
22
|
+
yield(a,b)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_defn_edges(code)
|
30
|
+
sexp = FastRuby::FastRubySexp.parse(code)
|
31
|
+
|
32
|
+
edges = GraphEdges.new(sexp)
|
33
|
+
sexp[3].edges.each do |tree_orig, tree_dest|
|
34
|
+
edges << [tree_orig, tree_dest]
|
35
|
+
end
|
36
|
+
|
37
|
+
yield(sexp, edges)
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_edges(code)
|
41
|
+
sexp = FastRuby::FastRubySexp.parse(code)
|
42
|
+
|
43
|
+
edges = GraphEdges.new(sexp)
|
44
|
+
sexp.edges.each do |tree_orig, tree_dest|
|
45
|
+
edges << [tree_orig, tree_dest]
|
46
|
+
end
|
47
|
+
|
48
|
+
yield(sexp, edges)
|
49
|
+
end
|
50
|
+
|
51
|
+
module KlassLevelHelper
|
52
|
+
def assert_graph(assert_name, code, node_count = nil)
|
53
|
+
it assert_name do
|
54
|
+
get_edges(code) do |sexp, edges|
|
55
|
+
condition_tree = sexp[1]
|
56
|
+
execution_tree = sexp[2]
|
57
|
+
|
58
|
+
if node_count
|
59
|
+
edges.count.should be == node_count
|
60
|
+
end
|
61
|
+
|
62
|
+
edges.tr_edges yield(sexp,edges) do |a,b|
|
63
|
+
edges.should include([a,b])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def assert_graph_defn(assert_name, code, node_count = nil)
|
70
|
+
it assert_name do
|
71
|
+
get_defn_edges(code) do |sexp, edges|
|
72
|
+
condition_tree = sexp[1]
|
73
|
+
execution_tree = sexp[2]
|
74
|
+
|
75
|
+
if node_count
|
76
|
+
edges.count.should be == node_count
|
77
|
+
end
|
78
|
+
|
79
|
+
edges.tr_edges yield(sexp,edges) do |a,b|
|
80
|
+
edges.should include([a,b])
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.included(klass)
|
88
|
+
klass.extend KlassLevelHelper
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "fastruby"
|
2
|
+
require "fastruby/sexp_extension"
|
3
|
+
|
4
|
+
describe FastRuby::Graph, "fastruby sexp graph" do
|
5
|
+
include FastRuby
|
6
|
+
it "should allow create empty graph" do
|
7
|
+
graph = Graph.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should allow add edges with add_edge" do
|
11
|
+
graph = Graph.new
|
12
|
+
graph.add_edge(1,2)
|
13
|
+
graph.edges.count.should be == 1
|
14
|
+
graph.edges.first.should be == [1,2]
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return 0 edges for an empty graph" do
|
18
|
+
graph = Graph.new
|
19
|
+
graph.edges.count.should be == 0
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should allow creation of graphs using hashes" do
|
23
|
+
graph = Graph.new 3 => [4]
|
24
|
+
graph.edges.count.should be == 1
|
25
|
+
graph.edges.should include([3,4])
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should allow creation of graphs using hashes with multiple nodes" do
|
29
|
+
graph = Graph.new 3 => [4,5,6]
|
30
|
+
graph.edges.count.should be == 3
|
31
|
+
graph.edges.should include([3,4])
|
32
|
+
graph.edges.should include([3,5])
|
33
|
+
graph.edges.should include([3,6])
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "fastruby"
|
2
|
+
require "fastruby/sexp_extension"
|
3
|
+
|
4
|
+
describe FastRuby::Graph, "fastruby sexp graph" do
|
5
|
+
include FastRuby
|
6
|
+
|
7
|
+
def self.assert_graph_paths(origin, paths, graph_hash)
|
8
|
+
it "should read paths #{paths.inspect} for graph #{graph_hash} from #{origin}" do
|
9
|
+
graph = Graph.new graph_hash
|
10
|
+
|
11
|
+
array = []
|
12
|
+
graph.each_path_from(origin) do |path|
|
13
|
+
path_array = []
|
14
|
+
path.each(&path_array.method(:<<))
|
15
|
+
array << path_array
|
16
|
+
end
|
17
|
+
|
18
|
+
paths.each do |path|
|
19
|
+
array.should include(path)
|
20
|
+
end
|
21
|
+
array.count.should be == paths.count
|
22
|
+
|
23
|
+
array
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
assert_graph_paths(1, [[1,2]], 1 => [2] )
|
28
|
+
assert_graph_paths(1, [[1,3]], 1 => [3] )
|
29
|
+
assert_graph_paths(1, [[1,4]], 1 => [4] )
|
30
|
+
assert_graph_paths(3, [[3,2]], 3 => [2] )
|
31
|
+
assert_graph_paths(4, [[4,2]], 4 => [2] )
|
32
|
+
|
33
|
+
assert_graph_paths(1, [[1,2],[1,3]], 1 => [2,3] )
|
34
|
+
|
35
|
+
assert_graph_paths(1, [[1,2,3]], 1 => [2], 2 => [3] )
|
36
|
+
assert_graph_paths(1, [[1,2,3],[1,2,4]], 1 => [2], 2 => [3,4] )
|
37
|
+
assert_graph_paths(1, [[1,2,4],[1,3,4]], 1 => [2,3], 2 => [4],3 => [4] )
|
38
|
+
assert_graph_paths(1, [[1,2,3,4,5],[1,2,3,5],[1,3,5],[1,3,4,5]], 1 => [2,3], 2 => [3],3 => [4,5],4 => [5] )
|
39
|
+
|
40
|
+
# cyclic paths
|
41
|
+
assert_graph_paths(1, [[1]], 1 => [1] )
|
42
|
+
assert_graph_paths(1, [[1,2,1]], 1 => [2], 2 => [1] )
|
43
|
+
assert_graph_paths(2, [[2,1,2]], 1 => [2], 2 => [1] )
|
44
|
+
|
45
|
+
# cyclyc paths with repeated vertexes
|
46
|
+
assert_graph_paths(1, [[1,2,4],[1,2,3,2,4]], 1 => [2], 2 => [3,4], 3 => [2])
|
47
|
+
end
|
48
|
+
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "fastruby"
|
2
|
+
require "fastruby/sexp_extension"
|
3
|
+
|
4
|
+
describe FastRuby::Graph, "fastruby sexp graph" do
|
5
|
+
include FastRuby
|
6
|
+
it "should allow read vertex from empty graph" do
|
7
|
+
graph = Graph.new
|
8
|
+
graph.vertexes
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should allow read vertex from empty graph and it must be empty" do
|
12
|
+
graph = Graph.new
|
13
|
+
graph.vertexes.count.should be == 0
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should allow read vertex from graph with one vertex" do
|
17
|
+
graph = Graph.new 1 => [1]
|
18
|
+
graph.vertexes.count.should be == 1
|
19
|
+
graph.vertexes.should include(1)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should allow read vertex from graph with two vertexes" do
|
23
|
+
graph = Graph.new 1 => [1,2]
|
24
|
+
graph.vertexes.count.should be == 2
|
25
|
+
graph.vertexes.should include(1)
|
26
|
+
graph.vertexes.should include(2)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should allow allow read vertex outputs" do
|
30
|
+
graph = Graph.new 1 => [1]
|
31
|
+
|
32
|
+
array = []
|
33
|
+
graph.each_vertex_output(1, &array.method(:<<))
|
34
|
+
|
35
|
+
array.should include(1)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should allow read vertex outputs" do
|
39
|
+
graph = Graph.new 1 => [2]
|
40
|
+
|
41
|
+
array = []
|
42
|
+
graph.each_vertex_output(1, &array.method(:<<))
|
43
|
+
|
44
|
+
array.should include(2)
|
45
|
+
|
46
|
+
array = []
|
47
|
+
graph.each_vertex_output(2, &array.method(:<<))
|
48
|
+
|
49
|
+
array.should be == []
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
it "should allow read vertex outputs with no blocks (returning sets)" do
|
54
|
+
graph = Graph.new 1 => [2]
|
55
|
+
graph.each_vertex_output(1).should include(2)
|
56
|
+
graph.each_vertex_output(2).count.should == 0
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,214 @@
|
|
1
|
+
require "fastruby"
|
2
|
+
|
3
|
+
describe FastRuby, "fastruby" do
|
4
|
+
class ::VY1
|
5
|
+
fastruby "
|
6
|
+
def foo
|
7
|
+
yield
|
8
|
+
end
|
9
|
+
"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should allow block as proc when calling from normal ruby" do
|
13
|
+
executed = 0
|
14
|
+
|
15
|
+
block = proc do
|
16
|
+
executed = 1
|
17
|
+
end
|
18
|
+
|
19
|
+
::VY1.new.foo(&block)
|
20
|
+
|
21
|
+
executed.should be == 1
|
22
|
+
end
|
23
|
+
|
24
|
+
class ::VY2
|
25
|
+
fastruby "
|
26
|
+
def foo
|
27
|
+
yield
|
28
|
+
end
|
29
|
+
|
30
|
+
def bar(block)
|
31
|
+
foo(&block)
|
32
|
+
end
|
33
|
+
"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should allow block as proc when calling from fastruby" do
|
37
|
+
executed = 0
|
38
|
+
|
39
|
+
block = proc do
|
40
|
+
executed = 1
|
41
|
+
end
|
42
|
+
|
43
|
+
::VY2.new.bar(block)
|
44
|
+
|
45
|
+
executed.should be == 1
|
46
|
+
end
|
47
|
+
|
48
|
+
class ::VY3
|
49
|
+
fastruby "
|
50
|
+
def foo
|
51
|
+
yield(1)
|
52
|
+
end
|
53
|
+
|
54
|
+
def bar(block)
|
55
|
+
foo(&block)
|
56
|
+
end
|
57
|
+
"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should allow block as proc when calling from fastruby with arguments" do
|
61
|
+
executed = 0
|
62
|
+
recv_x = nil
|
63
|
+
|
64
|
+
block = proc do |x|
|
65
|
+
recv_x = x
|
66
|
+
executed = 1
|
67
|
+
end
|
68
|
+
|
69
|
+
::VY3.new.bar(block)
|
70
|
+
|
71
|
+
recv_x.should be == 1
|
72
|
+
executed.should be == 1
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
class ::VY4
|
77
|
+
def foo(a,b,c)
|
78
|
+
yield(a,b,c)
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
fastruby "
|
83
|
+
def bar(x,block)
|
84
|
+
foo(*x,&block)
|
85
|
+
end
|
86
|
+
"
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should allow block as proc when calling from fastruby with splat arguments" do
|
90
|
+
executed = 0
|
91
|
+
recv_a = nil
|
92
|
+
recv_b = nil
|
93
|
+
recv_c = nil
|
94
|
+
|
95
|
+
block = proc do |a,b,c|
|
96
|
+
recv_a = a
|
97
|
+
recv_b = b
|
98
|
+
recv_c = c
|
99
|
+
executed = 1
|
100
|
+
end
|
101
|
+
|
102
|
+
::VY4.new.bar([1,2,3],block)
|
103
|
+
|
104
|
+
recv_a.should be == 1
|
105
|
+
recv_b.should be == 2
|
106
|
+
recv_c.should be == 3
|
107
|
+
executed.should be == 1
|
108
|
+
end
|
109
|
+
|
110
|
+
class ::VY5
|
111
|
+
def foo(a)
|
112
|
+
yield(a)
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
fastruby "
|
117
|
+
def bar(x,block)
|
118
|
+
foo(*x,&block)
|
119
|
+
end
|
120
|
+
"
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should allow pass symbols as blocks" do
|
124
|
+
vy5 = ::VY5.new
|
125
|
+
vy5.bar([44],:to_s).should be == "44"
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
class ::VY6
|
130
|
+
fastruby "
|
131
|
+
def foo(a)
|
132
|
+
yield(a)
|
133
|
+
end
|
134
|
+
|
135
|
+
def bar(x,block)
|
136
|
+
foo(x,&block)
|
137
|
+
end
|
138
|
+
"
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should allow single arguments with block" do
|
142
|
+
vy6 = ::VY6.new
|
143
|
+
|
144
|
+
block = proc do |a| "44" end
|
145
|
+
vy6.bar(44,block).should be == "44"
|
146
|
+
end
|
147
|
+
|
148
|
+
class ::VY7
|
149
|
+
def foo(a)
|
150
|
+
yield(a)
|
151
|
+
end
|
152
|
+
|
153
|
+
|
154
|
+
fastruby "
|
155
|
+
def bar(x,block)
|
156
|
+
foo(x,&block)
|
157
|
+
end
|
158
|
+
"
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should allow single arguments with block calling ruby methods" do
|
162
|
+
vy7 = ::VY7.new
|
163
|
+
|
164
|
+
block = proc do |a| "44" end
|
165
|
+
vy7.bar(44,block).should be == "44"
|
166
|
+
end
|
167
|
+
|
168
|
+
|
169
|
+
class ::VY8
|
170
|
+
def foo(a)
|
171
|
+
yield(a)
|
172
|
+
end
|
173
|
+
|
174
|
+
|
175
|
+
fastruby "
|
176
|
+
def bar(x,block)
|
177
|
+
foo(x,&block)
|
178
|
+
end
|
179
|
+
"
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should allow single arguments with block calling ruby methods and read block arguments" do
|
183
|
+
vy8 = ::VY8.new
|
184
|
+
|
185
|
+
block = proc do |a| a.to_s end
|
186
|
+
vy8.bar(555,block).should be == "555"
|
187
|
+
end
|
188
|
+
|
189
|
+
it "should allow single arguments with block calling ruby methods and read array block arguments" do
|
190
|
+
vy8 = ::VY8.new
|
191
|
+
|
192
|
+
block = proc do |a| a end
|
193
|
+
vy8.bar([555],block).should be == [555]
|
194
|
+
end
|
195
|
+
|
196
|
+
class ::VY9
|
197
|
+
def foo(a)
|
198
|
+
yield(a)
|
199
|
+
end
|
200
|
+
|
201
|
+
fastruby "
|
202
|
+
def bar(vy9,x,block)
|
203
|
+
vy9.first.foo(x,&block)
|
204
|
+
end
|
205
|
+
"
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should allow block as proc with no type inference of the receiver" do
|
209
|
+
vy9 = ::VY9.new
|
210
|
+
|
211
|
+
block = proc do |a| a end
|
212
|
+
vy9.bar([vy9],555,block).should be == 555
|
213
|
+
end
|
214
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require "fastruby"
|
2
|
+
|
3
|
+
describe FastRuby, "fastruby redo statement" do
|
4
|
+
class ::WB1
|
5
|
+
fastruby "
|
6
|
+
def bar
|
7
|
+
yield
|
8
|
+
end
|
9
|
+
|
10
|
+
def foo
|
11
|
+
sum = 0
|
12
|
+
bar do
|
13
|
+
sum = sum + 1
|
14
|
+
redo if sum<10
|
15
|
+
end
|
16
|
+
|
17
|
+
sum
|
18
|
+
end
|
19
|
+
"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should execute basic redo" do
|
23
|
+
wb1 = ::WB1.new
|
24
|
+
wb1.foo.should be == 10
|
25
|
+
end
|
26
|
+
|
27
|
+
class ::WB2
|
28
|
+
def bar
|
29
|
+
yield
|
30
|
+
end
|
31
|
+
|
32
|
+
fastruby "
|
33
|
+
|
34
|
+
def foo
|
35
|
+
sum = 0
|
36
|
+
bar do
|
37
|
+
sum = sum + 1
|
38
|
+
redo if sum<10
|
39
|
+
end
|
40
|
+
|
41
|
+
sum
|
42
|
+
end
|
43
|
+
"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should execute basic redo (called method is in ruby)" do
|
47
|
+
wb2 = ::WB2.new
|
48
|
+
wb2.foo.should be == 10
|
49
|
+
end
|
50
|
+
|
51
|
+
class ::WB3
|
52
|
+
fastruby "
|
53
|
+
def foo
|
54
|
+
redo
|
55
|
+
end
|
56
|
+
"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should raise LocalJumpError when invoked illegal redo" do
|
60
|
+
wb3 = ::WB3.new
|
61
|
+
|
62
|
+
lambda {
|
63
|
+
wb3.foo
|
64
|
+
}.should raise_error(LocalJumpError)
|
65
|
+
end
|
66
|
+
|
67
|
+
class ::WB4
|
68
|
+
fastruby <<EOS
|
69
|
+
def foo
|
70
|
+
yield(5)
|
71
|
+
end
|
72
|
+
|
73
|
+
def bar
|
74
|
+
a = true
|
75
|
+
foo do |n|
|
76
|
+
if a
|
77
|
+
a = false
|
78
|
+
n = 555
|
79
|
+
redo
|
80
|
+
end
|
81
|
+
n
|
82
|
+
end
|
83
|
+
end
|
84
|
+
EOS
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should NOT restore variable arguments on block when calling redo" do
|
88
|
+
wb4 = ::WB4.new
|
89
|
+
wb4.bar.should be == 555
|
90
|
+
end
|
91
|
+
|
92
|
+
class ::WB5
|
93
|
+
fastruby <<EOS
|
94
|
+
def bar
|
95
|
+
a = true
|
96
|
+
proc do |n|
|
97
|
+
if a
|
98
|
+
a = false
|
99
|
+
n = 555
|
100
|
+
redo
|
101
|
+
end
|
102
|
+
n
|
103
|
+
end
|
104
|
+
end
|
105
|
+
EOS
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should NOT restore variable arguments on block when calling redo (lambda block)" do
|
109
|
+
wb5 = ::WB5.new
|
110
|
+
wb5.bar.call(5).should be == 555
|
111
|
+
end
|
112
|
+
|
113
|
+
class ::WB6
|
114
|
+
fastruby <<EOS
|
115
|
+
def bar
|
116
|
+
a = true
|
117
|
+
Proc.new do |n|
|
118
|
+
if a
|
119
|
+
a = false
|
120
|
+
n = 555
|
121
|
+
redo
|
122
|
+
end
|
123
|
+
n
|
124
|
+
end
|
125
|
+
end
|
126
|
+
EOS
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should NOT restore variable arguments on block when calling redo (Proc.new block)" do
|
130
|
+
wb6 = ::WB6.new
|
131
|
+
wb6.bar.call(5).should be == 555
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "fastruby"
|
2
|
+
|
3
|
+
describe FastRuby, "fastruby" do
|
4
|
+
it "should allow define single method (without class)" do
|
5
|
+
fastruby "
|
6
|
+
def foo
|
7
|
+
end
|
8
|
+
"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should allow define and call single method (without class)" do
|
12
|
+
fastruby "
|
13
|
+
def foo
|
14
|
+
|
15
|
+
end
|
16
|
+
"
|
17
|
+
foo
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should allow define method from inside another method" do
|
21
|
+
class ::YZU1
|
22
|
+
fastruby "
|
23
|
+
def foo
|
24
|
+
def bar
|
25
|
+
77
|
26
|
+
end
|
27
|
+
end
|
28
|
+
"
|
29
|
+
end
|
30
|
+
|
31
|
+
::YZU1.new.foo
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should allow define and call method from inside another method" do
|
35
|
+
class ::YZU2
|
36
|
+
fastruby "
|
37
|
+
def foo
|
38
|
+
def bar
|
39
|
+
99
|
40
|
+
end
|
41
|
+
end
|
42
|
+
"
|
43
|
+
end
|
44
|
+
|
45
|
+
yzu2 = ::YZU2.new
|
46
|
+
yzu2.foo
|
47
|
+
yzu2.bar.should be == 99
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|