fastruby 0.0.20 → 0.0.21
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/fastruby/builder.rb~ +5 -1
- data/lib/fastruby/corelib/fixnum.rb +1 -1
- data/lib/fastruby/corelib/fixnum.rb~ +0 -71
- data/lib/fastruby/corelib.rb~ +1 -1
- data/lib/fastruby/modules/inliner/call.rb~ +3 -1
- data/lib/fastruby/modules/translator/call.rb +1 -1
- data/lib/fastruby/modules/translator/call.rb~ +1 -1
- data/lib/fastruby/object.rb~ +0 -6
- data/lib/fastruby.rb +1 -1
- data/lib/fastruby.rb~ +1 -1
- data/spec/corelib/numeric/fixnum_spec.rb +1 -1
- data/spec/corelib/numeric/fixnum_spec.rb~ +7 -1
- metadata +12 -40
- data/lib/fastruby/builder/inference_updater.rb~ +0 -76
- data/lib/fastruby/builder/inliner.rb~ +0 -60
- data/lib/fastruby/builder/lvar_type.rb~ +0 -44
- data/lib/fastruby/builder/pipeline.rb~ +0 -43
- data/lib/fastruby/builder/reductor.rb~ +0 -42
- data/lib/fastruby/corelib/integer.rb~ +0 -96
- data/lib/fastruby/modules/inliner/defn.rb~ +0 -29
- data/lib/fastruby/modules/inliner/recursive.rb~ +0 -40
- data/lib/fastruby/modules/lvar_type/call.rb~ +0 -36
- data/lib/fastruby/modules/lvar_type/defn.rb~ +0 -42
- data/lib/fastruby/modules/lvar_type/lasgn.rb~ +0 -42
- data/lib/fastruby/modules/lvar_type/recursive.rb~ +0 -33
- data/lib/fastruby/modules/reductor/nontree.rb~ +0 -32
- data/lib/fastruby/modules/reductor/recursive.rb~ +0 -31
- data/lib/fastruby/modules/translator/defn.rb~ +0 -267
- data/lib/fastruby/modules/translator/directive.rb~ +0 -44
- data/lib/fastruby/modules/translator/exceptions.rb~ +0 -120
- data/lib/fastruby/modules/translator/iter.rb~ +0 -745
- data/lib/fastruby/modules/translator/literal.rb~ +0 -150
- data/lib/fastruby/modules/translator/nonlocal.rb~ +0 -298
- data/lib/fastruby/modules/translator/static.rb~ +0 -291
- data/lib/fastruby/modules/translator/variable.rb~ +0 -280
- data/lib/fastruby/set_tree.rb~ +0 -71
- data/lib/fastruby/sexp_extension.rb~ +0 -262
- data/lib/fastruby/translator/scope_mode_helper.rb~ +0 -138
- data/lib/fastruby/translator/translator.rb~ +0 -1600
- data/lib/fastruby/translator/translator_modules.rb~ +0 -53
- data/lib/fastruby_only/base.rb +0 -1
@@ -1,262 +0,0 @@
|
|
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/fastruby_sexp"
|
22
|
-
require "fastruby/sexp_extension_edges"
|
23
|
-
require "ruby_parser"
|
24
|
-
require "set"
|
25
|
-
|
26
|
-
class Object
|
27
|
-
def to_fastruby_sexp
|
28
|
-
self
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def fs(*args)
|
33
|
-
if String === args.first
|
34
|
-
tree = FastRuby::FastRubySexp.parse(args.first)
|
35
|
-
|
36
|
-
if args.size > 1
|
37
|
-
replacement_hash = {}
|
38
|
-
args[1..-1].each do |arg|
|
39
|
-
replacement_hash.merge!(arg)
|
40
|
-
end
|
41
|
-
|
42
|
-
tree = tree.transform{|subtree|
|
43
|
-
if subtree.node_type == :call
|
44
|
-
next replacement_hash[subtree[2]]
|
45
|
-
elsif subtree.node_type == :lvar
|
46
|
-
next replacement_hash[subtree[1]]
|
47
|
-
else
|
48
|
-
next nil
|
49
|
-
end
|
50
|
-
}
|
51
|
-
end
|
52
|
-
|
53
|
-
tree
|
54
|
-
else
|
55
|
-
sexp = FastRuby::FastRubySexp.new
|
56
|
-
args.each &sexp.method(:<<)
|
57
|
-
sexp
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
module FastRuby
|
62
|
-
class Graph
|
63
|
-
attr_reader :edges
|
64
|
-
attr_reader :vertexes
|
65
|
-
|
66
|
-
def initialize(hash = {})
|
67
|
-
@edges = []
|
68
|
-
@vertexes = Set.new
|
69
|
-
@vertex_output = Hash.new
|
70
|
-
|
71
|
-
hash.each do |orig,v|
|
72
|
-
v.each do |dest|
|
73
|
-
add_edge(orig,dest)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def add_edge(orig,dest)
|
79
|
-
@vertexes << orig
|
80
|
-
@vertexes << dest
|
81
|
-
|
82
|
-
@vertex_output[orig.object_id] ||= Set.new
|
83
|
-
@vertex_output[orig.object_id] << dest
|
84
|
-
|
85
|
-
@edges << [orig,dest]
|
86
|
-
end
|
87
|
-
|
88
|
-
def each_vertex_output(vertex,&blk)
|
89
|
-
outputs = @vertex_output[vertex.object_id]
|
90
|
-
if outputs
|
91
|
-
blk ? outputs.each(&blk) : outputs
|
92
|
-
else
|
93
|
-
Set.new
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def each_path_from(vertex, history = [])
|
98
|
-
outputs = each_vertex_output(vertex) - history.select{|h| h[0] == vertex }.map(&:last)
|
99
|
-
outputs.delete(vertex)
|
100
|
-
|
101
|
-
if outputs.count == 0
|
102
|
-
yield [vertex]
|
103
|
-
return
|
104
|
-
end
|
105
|
-
|
106
|
-
outputs.each do |vo|
|
107
|
-
each_path_from(vo,history+[[vertex,vo]]) do |subpath|
|
108
|
-
yield [vertex]+subpath
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
class FastRubySexp
|
115
|
-
def self.from_sexp(value)
|
116
|
-
return nil if value == nil
|
117
|
-
return value if value.kind_of? FastRubySexp
|
118
|
-
|
119
|
-
ary = FastRuby::FastRubySexp.new
|
120
|
-
value.each do |x|
|
121
|
-
ary << x.to_fastruby_sexp
|
122
|
-
end
|
123
|
-
ary
|
124
|
-
end
|
125
|
-
|
126
|
-
def transform(&blk)
|
127
|
-
ret = FastRuby::FastRubySexp.from_sexp( blk.call(self) )
|
128
|
-
unless ret
|
129
|
-
ret = FastRuby::FastRubySexp.new
|
130
|
-
each{|st2|
|
131
|
-
if st2.respond_to?(:transform)
|
132
|
-
ret << st2.transform(&blk)
|
133
|
-
else
|
134
|
-
ret << st2
|
135
|
-
end
|
136
|
-
}
|
137
|
-
end
|
138
|
-
|
139
|
-
ret
|
140
|
-
end
|
141
|
-
|
142
|
-
def self.parse(code)
|
143
|
-
from_sexp(RubyParser.new.parse(code))
|
144
|
-
end
|
145
|
-
|
146
|
-
def to_graph
|
147
|
-
graph = Graph.new
|
148
|
-
self.edges.each &graph.method(:add_edge)
|
149
|
-
|
150
|
-
if ENV['FASTRUBY_GRAPH_VERTEX_CHECK'] == '1'
|
151
|
-
output_vertexes = [];
|
152
|
-
|
153
|
-
self.walk_tree do |subtree|
|
154
|
-
if graph.each_vertex_output(subtree).count == 0
|
155
|
-
# vertexes with no output
|
156
|
-
unless [:arglist,:scope].include? subtree.node_type
|
157
|
-
output_vertexes << subtree
|
158
|
-
if output_vertexes.count > 1
|
159
|
-
raise RuntimeError, "invalid output vertexes #{output_vertexes.map &:node_type}"
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
graph
|
167
|
-
end
|
168
|
-
|
169
|
-
def edges
|
170
|
-
Edges.new(self)
|
171
|
-
end
|
172
|
-
|
173
|
-
def first_tree
|
174
|
-
if respond_to? "first_tree_#{node_type}"
|
175
|
-
send("first_tree_#{node_type}")
|
176
|
-
else
|
177
|
-
return self[1].first_tree if self.count == 2 and self[1].respond_to? :node_type
|
178
|
-
return self[1].first_tree if [:if,:block,:while,:until,:or,:and,:ensure].include? node_type
|
179
|
-
return self[2].first_tree if [:lasgn,:iasgn,:gasgn,:cdecl].include? node_type
|
180
|
-
|
181
|
-
self
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
def first_tree_rescue
|
186
|
-
if self[1].node_type == :resbody
|
187
|
-
return self
|
188
|
-
else
|
189
|
-
return self[1].first_tree
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
def first_tree_return
|
194
|
-
self[1] ? self[1].first_tree : self
|
195
|
-
end
|
196
|
-
|
197
|
-
alias first_tree_break first_tree_return
|
198
|
-
alias first_tree_next first_tree_return
|
199
|
-
|
200
|
-
def first_tree_yield
|
201
|
-
if self.size > 1
|
202
|
-
self[-1].first_tree
|
203
|
-
else
|
204
|
-
self
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
def first_tree_iter
|
209
|
-
call_tree = self[1]
|
210
|
-
recv = call_tree[1]
|
211
|
-
if recv
|
212
|
-
recv.first_tree
|
213
|
-
else
|
214
|
-
args_tree = call_tree[3]
|
215
|
-
if args_tree.size > 1
|
216
|
-
args_tree[1].first_tree
|
217
|
-
else
|
218
|
-
call_tree
|
219
|
-
end
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
def first_tree_call
|
224
|
-
recv = self[1]
|
225
|
-
if recv
|
226
|
-
recv.first_tree
|
227
|
-
else
|
228
|
-
args_tree = self[3]
|
229
|
-
if args_tree.size > 1
|
230
|
-
args_tree[1].first_tree
|
231
|
-
else
|
232
|
-
self
|
233
|
-
end
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
def find_break(&blk)
|
238
|
-
subarray = if node_type == :while
|
239
|
-
[]
|
240
|
-
elsif node_type == :iter
|
241
|
-
self[1..-2]
|
242
|
-
elsif node_type == :break
|
243
|
-
blk.call(self)
|
244
|
-
return; nil
|
245
|
-
else
|
246
|
-
self[1..-1]
|
247
|
-
end
|
248
|
-
|
249
|
-
subarray.each do |subtree|
|
250
|
-
if subtree.respond_to? :find_break
|
251
|
-
subtree.find_break(&blk)
|
252
|
-
end
|
253
|
-
end
|
254
|
-
end
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
class Sexp
|
259
|
-
def to_fastruby_sexp
|
260
|
-
FastRuby::FastRubySexp.from_sexp(self)
|
261
|
-
end
|
262
|
-
end
|
@@ -1,138 +0,0 @@
|
|
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/sexp_extension"
|
22
|
-
|
23
|
-
module FastRuby
|
24
|
-
class ScopeModeHelper
|
25
|
-
def self.get_scope_mode(tree_)
|
26
|
-
new.get_scope_mode(tree_)
|
27
|
-
end
|
28
|
-
|
29
|
-
def get_scope_mode(tree_)
|
30
|
-
tree = FastRuby::FastRubySexp.from_sexp(tree_)
|
31
|
-
|
32
|
-
if tree.node_type == :defn
|
33
|
-
args_tree = tree[2]
|
34
|
-
impl_tree = tree[3]
|
35
|
-
elsif tree.node_type == :defs
|
36
|
-
args_tree = tree[3]
|
37
|
-
impl_tree = tree[4]
|
38
|
-
end
|
39
|
-
|
40
|
-
|
41
|
-
p $search_array.call(impl_tree)
|
42
|
-
graph = impl_tree.to_graph
|
43
|
-
|
44
|
-
args_tree[1..-1].each do |subtree|
|
45
|
-
return :dag if subtree.to_s =~ /^\&/
|
46
|
-
end
|
47
|
-
|
48
|
-
tree.walk_tree do |subtree|
|
49
|
-
if subtree.node_type == :iter
|
50
|
-
iter_impl = subtree[3]
|
51
|
-
|
52
|
-
return :dag if has_local_variable_access?(subtree[3])
|
53
|
-
return :dag if subtree[2]
|
54
|
-
|
55
|
-
if iter_impl
|
56
|
-
return_node = iter_impl.find_tree{|st2| st2.node_type == :return}
|
57
|
-
|
58
|
-
if return_node
|
59
|
-
return :dag
|
60
|
-
end
|
61
|
-
end
|
62
|
-
elsif subtree.node_type == :block_pass
|
63
|
-
return :dag
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
impl_tree.walk_tree do |subtree|
|
68
|
-
graph.each_path_from(subtree) do |path|
|
69
|
-
# verify path prohibitive for :linear scope (local variable read after call)
|
70
|
-
has_call = false
|
71
|
-
writes = Set.new
|
72
|
-
|
73
|
-
path.each do |st2|
|
74
|
-
next unless st2
|
75
|
-
if st2.node_type == :call
|
76
|
-
if has_call and st2[1] == nil
|
77
|
-
return :dag
|
78
|
-
end
|
79
|
-
|
80
|
-
writes.clear
|
81
|
-
has_call = true
|
82
|
-
elsif st2.node_type == :iter
|
83
|
-
if has_call and st2[1][1] == nil
|
84
|
-
return :dag
|
85
|
-
end
|
86
|
-
|
87
|
-
writes.clear
|
88
|
-
has_call = true
|
89
|
-
elsif st2.node_type == :lasgn
|
90
|
-
writes << st2[1] # record local writes
|
91
|
-
elsif st2.node_type == :lvar or st2.node_type == :self or
|
92
|
-
st2.node_type == :return or st2.node_type == :yield
|
93
|
-
|
94
|
-
if has_call
|
95
|
-
if st2.node_type == :lvar
|
96
|
-
if writes.include? st2[1]
|
97
|
-
# no problem
|
98
|
-
else
|
99
|
-
# read after call, the scope of this function must be implemented on heap
|
100
|
-
return :dag
|
101
|
-
end
|
102
|
-
else
|
103
|
-
return :dag
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
:linear
|
112
|
-
end
|
113
|
-
|
114
|
-
private
|
115
|
-
def has_local_variable_access?(*trees)
|
116
|
-
trees.each do |tree|
|
117
|
-
return false unless tree.kind_of? FastRuby::FastRubySexp
|
118
|
-
|
119
|
-
tree.walk_tree do |subtree|
|
120
|
-
if subtree.node_type == :lvar or
|
121
|
-
subtree.node_type == :self or
|
122
|
-
subtree.node_type == :yield or
|
123
|
-
subtree.node_type == :return or
|
124
|
-
subtree.node_type == :lasgn
|
125
|
-
return true
|
126
|
-
end
|
127
|
-
|
128
|
-
if subtree.node_type == :call
|
129
|
-
if subtree[1] == nil
|
130
|
-
return true
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
false
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|