fastruby 0.0.20 → 0.0.21
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/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,291 +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
|
-
module FastRuby
|
22
|
-
class Context
|
23
|
-
define_translator_for(:iter, :arity => 1, :priority => 1) { |*x|
|
24
|
-
ret = nil
|
25
|
-
tree = x.first
|
26
|
-
enable_handler_group(:static_call) do
|
27
|
-
require "pry"; binding.pry
|
28
|
-
ret = x.size == 1 ? to_c(tree[3]) : to_c(tree[3], x.last)
|
29
|
-
end
|
30
|
-
ret
|
31
|
-
}.condition{ |*x|
|
32
|
-
tree = x.first
|
33
|
-
tree.node_type == :iter && tree[1][2] == :_static
|
34
|
-
}
|
35
|
-
|
36
|
-
define_translator_for(:iter, :arity => 1, :priority => 1) { |*x|
|
37
|
-
ret = nil
|
38
|
-
tree = x.first
|
39
|
-
|
40
|
-
disable_handler_group(:static_call) do
|
41
|
-
ret = x.size == 1 ? to_c(tree[3]) : to_c(tree[3], x.last)
|
42
|
-
end
|
43
|
-
ret
|
44
|
-
}.condition{ |*x|
|
45
|
-
tree = x.first
|
46
|
-
tree.node_type == :iter && tree[1][2] == :_dynamic
|
47
|
-
}
|
48
|
-
|
49
|
-
handler_scope(:group => :static_call, :priority => 1000) do
|
50
|
-
define_translator_for(:call) do |*x|
|
51
|
-
tree, result = x
|
52
|
-
|
53
|
-
method_name = tree[2].to_s
|
54
|
-
recv_tree = tree[1]
|
55
|
-
|
56
|
-
if method_name == "c_address_of"
|
57
|
-
arg = tree[3][1]
|
58
|
-
return "&"+to_c(arg)
|
59
|
-
end
|
60
|
-
|
61
|
-
if method_name == "inline_c"
|
62
|
-
arg = tree[3][1]
|
63
|
-
|
64
|
-
if arg.node_type != :str
|
65
|
-
raise RuntimeError, "invalid node for inline_c directive #{arg}"
|
66
|
-
end
|
67
|
-
|
68
|
-
next arg[1]
|
69
|
-
end
|
70
|
-
|
71
|
-
if recv_tree and recv_tree.node_type != :self
|
72
|
-
if (not tree[2].to_s =~ /^[a-zA-Z]/) and tree[2].to_s.size <= 3
|
73
|
-
c_op = tree[2].to_s
|
74
|
-
c_op = '==' if tree[2] == :===
|
75
|
-
code = "( ( #{to_c(tree[1])} )#{c_op}(#{to_c(tree[3][1])}) )"
|
76
|
-
elsif tree[2] == :_invariant
|
77
|
-
name = self.add_global_name("VALUE", "Qnil");
|
78
|
-
|
79
|
-
init_extra << "
|
80
|
-
#{name} = #{to_c tree[1]};
|
81
|
-
rb_funcall(#{name},#{intern_num :gc_register_object},0);
|
82
|
-
"
|
83
|
-
|
84
|
-
code = name;
|
85
|
-
else
|
86
|
-
args = tree[3][1..-1].map{|st| to_c(st)}.join(",")
|
87
|
-
code = "#{method_name}( #{args} )"
|
88
|
-
end
|
89
|
-
else
|
90
|
-
args = tree[3][1..-1].map{|st| to_c(st)}.join(",")
|
91
|
-
code = "#{method_name}( #{args} )"
|
92
|
-
end
|
93
|
-
|
94
|
-
if result
|
95
|
-
"#{result} = #{code};"
|
96
|
-
else
|
97
|
-
code
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
define_translator_for(:lit) do |*x|
|
102
|
-
tree, result = x
|
103
|
-
|
104
|
-
if result
|
105
|
-
"#{result} = #{tree[1]};"
|
106
|
-
else
|
107
|
-
tree[1].to_s
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
define_translator_for(:if) do |*x|
|
112
|
-
tree, result_variable_ = x
|
113
|
-
|
114
|
-
condition_tree = tree[1]
|
115
|
-
impl_tree = tree[2]
|
116
|
-
else_tree = tree[3]
|
117
|
-
|
118
|
-
result_variable = result_variable_ || "last_expression"
|
119
|
-
|
120
|
-
code = proc {"
|
121
|
-
{
|
122
|
-
VALUE condition_result;
|
123
|
-
#{to_c condition_tree, "condition_result"};
|
124
|
-
if (condition_result) {
|
125
|
-
#{to_c impl_tree, result_variable};
|
126
|
-
}#{else_tree ?
|
127
|
-
" else {
|
128
|
-
#{to_c else_tree, result_variable};
|
129
|
-
}
|
130
|
-
" : ""
|
131
|
-
}
|
132
|
-
}
|
133
|
-
"}
|
134
|
-
|
135
|
-
if result_variable_
|
136
|
-
code.call
|
137
|
-
else
|
138
|
-
inline_block(&code) + "; return last_expression;"
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
define_translator_for(:const) do |*x|
|
143
|
-
tree, result_var = x
|
144
|
-
|
145
|
-
if result_var
|
146
|
-
"#{result_var} = #{tree[1].to_s};"
|
147
|
-
else
|
148
|
-
"#{tree[1].to_s}"
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
define_translator_for(:while) do |*x|
|
153
|
-
tree, result_var = x
|
154
|
-
|
155
|
-
begin_while = "begin_while_"+rand(10000000).to_s
|
156
|
-
end_while = "end_while_"+rand(10000000).to_s
|
157
|
-
aux_varname = "_aux_" + rand(10000000).to_s
|
158
|
-
code = proc {"
|
159
|
-
{
|
160
|
-
VALUE while_condition;
|
161
|
-
VALUE #{aux_varname};
|
162
|
-
|
163
|
-
#{begin_while}:
|
164
|
-
#{to_c tree[1], "while_condition"};
|
165
|
-
if (!(while_condition)) goto #{end_while};
|
166
|
-
#{to_c tree[2], aux_varname};
|
167
|
-
goto #{begin_while};
|
168
|
-
#{end_while}:
|
169
|
-
|
170
|
-
#{
|
171
|
-
if result_var
|
172
|
-
"#{result_var} = Qnil;"
|
173
|
-
else
|
174
|
-
"return Qnil;"
|
175
|
-
end
|
176
|
-
}
|
177
|
-
}
|
178
|
-
"}
|
179
|
-
|
180
|
-
if result_var
|
181
|
-
code.call
|
182
|
-
else
|
183
|
-
inline_block &code
|
184
|
-
end
|
185
|
-
|
186
|
-
end
|
187
|
-
|
188
|
-
define_translator_for(:and) do |*x|
|
189
|
-
tree, return_var = x
|
190
|
-
|
191
|
-
if return_var
|
192
|
-
"
|
193
|
-
{
|
194
|
-
VALUE op1 = Qnil;
|
195
|
-
VALUE op2 = Qnil;
|
196
|
-
#{to_c tree[1], "op1"};
|
197
|
-
#{to_c tree[2], "op2"};
|
198
|
-
#{return_var} = ((op1) &&(op2));
|
199
|
-
}
|
200
|
-
"
|
201
|
-
else
|
202
|
-
"((#{to_c tree[1]}) && (#{to_c tree[2]}))"
|
203
|
-
end
|
204
|
-
|
205
|
-
end
|
206
|
-
|
207
|
-
define_translator_for(:or) do |*x|
|
208
|
-
tree, return_var = x
|
209
|
-
|
210
|
-
if return_var
|
211
|
-
"
|
212
|
-
{
|
213
|
-
VALUE op1 = Qnil;
|
214
|
-
VALUE op2 = Qnil;
|
215
|
-
#{to_c tree[1], "op1"};
|
216
|
-
#{to_c tree[2], "op2"};
|
217
|
-
#{return_var} = ((op1) ||(op2));
|
218
|
-
}
|
219
|
-
"
|
220
|
-
else
|
221
|
-
"((#{to_c tree[1]}) || (#{to_c tree[2]}))"
|
222
|
-
end
|
223
|
-
|
224
|
-
end
|
225
|
-
|
226
|
-
define_translator_for(:not) do |*x|
|
227
|
-
tree, return_var = x
|
228
|
-
|
229
|
-
if return_var
|
230
|
-
"
|
231
|
-
{
|
232
|
-
VALUE op1 = Qnil;
|
233
|
-
#{to_c tree[1], "op1"};
|
234
|
-
#{return_var} = ((op1) ? 0: 1);
|
235
|
-
}
|
236
|
-
"
|
237
|
-
else
|
238
|
-
"((#{to_c tree[1]}) ? 0 : 1)"
|
239
|
-
end
|
240
|
-
end
|
241
|
-
|
242
|
-
end
|
243
|
-
|
244
|
-
define_method_handler(:initialize_to_c){|*x|}.condition do |*x|
|
245
|
-
disable_handler_group(:static_call, :to_c); false
|
246
|
-
end
|
247
|
-
|
248
|
-
|
249
|
-
define_method_handler(:infer_value) { |*x| tree = x.first;
|
250
|
-
Value.new(eval(tree[1].to_s))
|
251
|
-
}.condition{|*x| tree = x.first; tree.node_type == :const}
|
252
|
-
|
253
|
-
define_method_handler(:infer_value) { |*x| tree = x.first;
|
254
|
-
args_tree = tree[3]
|
255
|
-
receiver_tree = tree[1]
|
256
|
-
|
257
|
-
value_1 = infer_value(receiver_tree)
|
258
|
-
value_2 = infer_value(args_tree[1])
|
259
|
-
|
260
|
-
next false unless (value_1 and value_2)
|
261
|
-
|
262
|
-
Value.new(value_1.value == value_2.value)
|
263
|
-
}.condition{|*x| tree = x.first;
|
264
|
-
next false unless tree.node_type == :call
|
265
|
-
|
266
|
-
args_tree = tree[3]
|
267
|
-
method_name = tree[2]
|
268
|
-
|
269
|
-
next false unless method_name == :==
|
270
|
-
next false if args_tree.size < 2
|
271
|
-
|
272
|
-
true
|
273
|
-
}
|
274
|
-
define_method_handler(:infer_value) { |*x| tree = x.first;
|
275
|
-
args_tree = tree[3]
|
276
|
-
receiver_tree = tree[1]
|
277
|
-
infered_type = infer_type(receiver_tree)
|
278
|
-
|
279
|
-
if infered_type
|
280
|
-
Value.new(infered_type)
|
281
|
-
else
|
282
|
-
nil
|
283
|
-
end
|
284
|
-
}.condition{|*x| tree = x.first;
|
285
|
-
next false unless tree.node_type == :call
|
286
|
-
method_name = tree[2]
|
287
|
-
next false unless method_name == :_class
|
288
|
-
true
|
289
|
-
}
|
290
|
-
end
|
291
|
-
end
|
@@ -1,280 +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
|
-
module FastRuby
|
22
|
-
class Context
|
23
|
-
define_translator_for(:cvar, :method => :to_c_cvar, :arity => 1)
|
24
|
-
def to_c_cvar(tree)
|
25
|
-
"rb_cvar_get(CLASS_OF(plocals->self) != rb_cClass ? CLASS_OF(plocals->self) : plocals->self,#{intern_num tree[1]})"
|
26
|
-
end
|
27
|
-
|
28
|
-
define_translator_for(:cvasgn, :method => :to_c_cvasgn)
|
29
|
-
def to_c_cvasgn(tree, result_var = nil)
|
30
|
-
if result_var
|
31
|
-
"
|
32
|
-
{
|
33
|
-
VALUE recv = CLASS_OF(plocals->self) != rb_cClass ? CLASS_OF(plocals->self) : plocals->self;
|
34
|
-
|
35
|
-
#{to_c tree[2], result_var};
|
36
|
-
|
37
|
-
#{if RUBY_VERSION =~ /^1\.9/
|
38
|
-
"rb_cvar_set(recv,#{intern_num tree[1]},#{result_var});"
|
39
|
-
elsif RUBY_VERSION =~ /^1\.8/
|
40
|
-
"rb_cvar_set(recv,#{intern_num tree[1]},#{result_var},Qfalse);"
|
41
|
-
else
|
42
|
-
raise RuntimeError, "unsupported ruby version #{RUBY_VERSION}"
|
43
|
-
end
|
44
|
-
}
|
45
|
-
}
|
46
|
-
"
|
47
|
-
else
|
48
|
-
"__rb_cvar_set(CLASS_OF(plocals->self) != rb_cClass ? CLASS_OF(plocals->self) : plocals->self,#{intern_num tree[1]},#{to_c tree[2]},Qfalse)"
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
define_translator_for(:gvar, :method => :to_c_gvar, :arity => 1)
|
53
|
-
def to_c_gvar(tree)
|
54
|
-
if (tree[1] == :$!)
|
55
|
-
"pframe->thread_data->exception"
|
56
|
-
else
|
57
|
-
"rb_gvar_get((struct global_entry*)#{global_entry(tree[1])})"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
define_translator_for(:gasgn, :method => :to_c_gasgn)
|
62
|
-
def to_c_gasgn(tree, result_var = nil)
|
63
|
-
if result_var
|
64
|
-
"
|
65
|
-
{
|
66
|
-
#{to_c tree[2], result_var};
|
67
|
-
rb_gvar_set((void*)#{global_entry(tree[1])},#{result_var});
|
68
|
-
}
|
69
|
-
"
|
70
|
-
else
|
71
|
-
"_rb_gvar_set((void*)#{global_entry(tree[1])}, #{to_c tree[2]})"
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
define_translator_for(:ivar, :method => :to_c_ivar, :arity => 1)
|
76
|
-
def to_c_ivar(tree)
|
77
|
-
"rb_ivar_get(#{locals_accessor}self,#{intern_num tree[1]})"
|
78
|
-
end
|
79
|
-
|
80
|
-
define_translator_for(:iasgn, :method => :to_c_iasgn)
|
81
|
-
def to_c_iasgn(tree, result_var = nil)
|
82
|
-
if result_var
|
83
|
-
"
|
84
|
-
{
|
85
|
-
#{to_c tree[2], result_var};
|
86
|
-
rb_ivar_set(#{locals_accessor}self,#{intern_num tree[1]},#{result_var});
|
87
|
-
}
|
88
|
-
"
|
89
|
-
else
|
90
|
-
"_rb_ivar_set(#{locals_accessor}self,#{intern_num tree[1]},#{to_c tree[2]})"
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
define_translator_for(:const, :arity => 1) do |tree|
|
95
|
-
"rb_const_get(CLASS_OF(plocals->self), #{intern_num(tree[1])})"
|
96
|
-
end
|
97
|
-
|
98
|
-
define_translator_for(:cdecl, :method => :to_c_cdecl)
|
99
|
-
def to_c_cdecl(tree, result_var_ = nil)
|
100
|
-
|
101
|
-
result_var = result_var_ || "value"
|
102
|
-
|
103
|
-
if tree[1].instance_of? Symbol
|
104
|
-
code = proc{"
|
105
|
-
{
|
106
|
-
// set constant #{tree[1].to_s}
|
107
|
-
#{to_c tree[2], result_var};
|
108
|
-
rb_const_set(rb_cObject, #{intern_num tree[1]}, #{result_var});
|
109
|
-
}
|
110
|
-
"}
|
111
|
-
elsif tree[1].instance_of? FastRuby::FastRubySexp
|
112
|
-
|
113
|
-
if tree[1].node_type == :colon2
|
114
|
-
code = proc{"
|
115
|
-
{
|
116
|
-
// set constant #{tree[1].to_s}
|
117
|
-
#{to_c tree[2], result_var};
|
118
|
-
VALUE klass = Qnil;
|
119
|
-
#{to_c tree[1][1], "klass"};
|
120
|
-
rb_const_set(klass, #{intern_num tree[1][2]}, #{result_var});
|
121
|
-
}
|
122
|
-
"}
|
123
|
-
elsif tree[1].node_type == :colon3
|
124
|
-
code = proc{"
|
125
|
-
{
|
126
|
-
// set constant #{tree[1].to_s}
|
127
|
-
#{to_c tree[2], result_var};
|
128
|
-
rb_const_set(rb_cObject, #{intern_num tree[1][1]}, #{result_var});
|
129
|
-
}
|
130
|
-
"}
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
if result_var_
|
135
|
-
code.call
|
136
|
-
else
|
137
|
-
inline_block{"VALUE #{result_var} = Qnil;\n" + code.call + "
|
138
|
-
return #{result_var};
|
139
|
-
"}
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
define_translator_for(:colon3, :method => :to_c_colon3, :arity => 1)
|
144
|
-
def to_c_colon3(tree)
|
145
|
-
"rb_const_get_from(rb_cObject, #{intern_num tree[1]})"
|
146
|
-
end
|
147
|
-
|
148
|
-
define_translator_for(:colon2, :method => :to_c_colon2)
|
149
|
-
def to_c_colon2(tree, result_var = nil)
|
150
|
-
code = proc{ "
|
151
|
-
{
|
152
|
-
VALUE klass = Qnil;
|
153
|
-
|
154
|
-
#{to_c tree[1],"klass"};
|
155
|
-
#{
|
156
|
-
if result_var
|
157
|
-
"#{result_var} = Qnil;"
|
158
|
-
end
|
159
|
-
}
|
160
|
-
|
161
|
-
if (rb_is_const_id(#{intern_num tree[2]})) {
|
162
|
-
switch (TYPE(klass)) {
|
163
|
-
case T_CLASS:
|
164
|
-
case T_MODULE:
|
165
|
-
#{
|
166
|
-
if result_var
|
167
|
-
"#{result_var} = rb_const_get_from(klass, #{intern_num tree[2]});"
|
168
|
-
else
|
169
|
-
"return rb_const_get_from(klass, #{intern_num tree[2]});"
|
170
|
-
end
|
171
|
-
}
|
172
|
-
break;
|
173
|
-
default:
|
174
|
-
#{_raise("rb_eTypeError","not a class/module")};
|
175
|
-
break;
|
176
|
-
}
|
177
|
-
}
|
178
|
-
else {
|
179
|
-
#{
|
180
|
-
if result_var
|
181
|
-
"#{result_var} = rb_funcall(klass, #{intern_num tree[2]}, 0, 0);"
|
182
|
-
else
|
183
|
-
"return rb_funcall(klass, #{intern_num tree[2]}, 0, 0);"
|
184
|
-
end
|
185
|
-
}
|
186
|
-
}
|
187
|
-
|
188
|
-
#{
|
189
|
-
unless result_var
|
190
|
-
"return Qnil;"
|
191
|
-
end
|
192
|
-
}
|
193
|
-
}
|
194
|
-
"}
|
195
|
-
|
196
|
-
if result_var
|
197
|
-
code.call
|
198
|
-
else
|
199
|
-
inline_block &code
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
define_translator_for(:lasgn, :method => :to_c_lasgn)
|
204
|
-
def to_c_lasgn(tree, result_var = nil)
|
205
|
-
code = "
|
206
|
-
{
|
207
|
-
#{to_c tree[2], result_var};
|
208
|
-
#{locals_accessor}#{tree[1]} = #{result_var};
|
209
|
-
}
|
210
|
-
"
|
211
|
-
|
212
|
-
if result_var
|
213
|
-
code
|
214
|
-
else
|
215
|
-
"_lvar_assing(&#{locals_accessor}#{tree[1]},#{to_c tree[2]})"
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
define_translator_for(:lvar, :arity => 1) do |tree|
|
220
|
-
locals_accessor + tree[1].to_s
|
221
|
-
end
|
222
|
-
|
223
|
-
define_translator_for(:defined, :method => :to_c_defined, :arity => 1)
|
224
|
-
def to_c_defined(tree)
|
225
|
-
obj_tree = tree[1]
|
226
|
-
|
227
|
-
if obj_tree[0] == :call && obj_tree[2] == :infer
|
228
|
-
obj_tree = obj_tree[1]
|
229
|
-
end
|
230
|
-
|
231
|
-
nt = obj_tree.node_type
|
232
|
-
|
233
|
-
if nt == :self
|
234
|
-
'rb_str_new2("self")'
|
235
|
-
elsif nt == :true
|
236
|
-
'rb_str_new2("true")'
|
237
|
-
elsif nt == :false
|
238
|
-
'rb_str_new2("false")'
|
239
|
-
elsif nt == :nil
|
240
|
-
'rb_str_new2("nil")'
|
241
|
-
elsif nt == :lvar
|
242
|
-
'rb_str_new2("local-variable")'
|
243
|
-
elsif nt == :gvar
|
244
|
-
"rb_gvar_defined((struct global_entry*)#{global_entry(obj_tree[1])}) ? #{literal_value "global-variable"} : Qnil"
|
245
|
-
elsif nt == :const
|
246
|
-
"rb_const_defined(rb_cObject, #{intern_num obj_tree[1]}) ? #{literal_value "constant"} : Qnil"
|
247
|
-
elsif nt == :call
|
248
|
-
if RUBY_VERSION =~ /^1\.8/
|
249
|
-
"rb_method_node(CLASS_OF(#{to_c obj_tree[1]}), #{intern_num obj_tree[2]}) ? #{literal_value "method"} : Qnil"
|
250
|
-
else
|
251
|
-
"rb_method_entry(CLASS_OF(#{to_c obj_tree[1]}), #{intern_num obj_tree[2]}) ? #{literal_value "method"} : Qnil"
|
252
|
-
end
|
253
|
-
elsif nt == :yield
|
254
|
-
"rb_block_given_p() ? #{literal_value "yield"} : Qnil"
|
255
|
-
elsif nt == :ivar
|
256
|
-
"rb_ivar_defined(plocals->self,#{intern_num obj_tree[1]}) ? #{literal_value "instance-variable"} : Qnil"
|
257
|
-
elsif nt == :attrset or
|
258
|
-
nt == :op_asgn1 or
|
259
|
-
nt == :op_asgn2 or
|
260
|
-
nt == :op_asgn_or or
|
261
|
-
nt == :op_asgn_and or
|
262
|
-
nt == :op_asgn_masgn or
|
263
|
-
nt == :masgn or
|
264
|
-
nt == :lasgn or
|
265
|
-
nt == :dasgn or
|
266
|
-
nt == :dasgn_curr or
|
267
|
-
nt == :gasgn or
|
268
|
-
nt == :iasgn or
|
269
|
-
nt == :cdecl or
|
270
|
-
nt == :cvdecl or
|
271
|
-
nt == :cvasgn
|
272
|
-
literal_value "assignment"
|
273
|
-
else
|
274
|
-
literal_value "expression"
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
|
279
|
-
end
|
280
|
-
end
|
data/lib/fastruby/set_tree.rb~
DELETED
@@ -1,71 +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/builder"
|
22
|
-
require "fastruby/getlocals"
|
23
|
-
require "fastruby/method_extension"
|
24
|
-
|
25
|
-
module FastRuby
|
26
|
-
|
27
|
-
def self.make_str_signature(method_name, signature)
|
28
|
-
"_" + method_name.to_s + signature.map(&:__id__).map(&:to_s).join
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.set_builder_module(klass)
|
32
|
-
klass.class_eval do
|
33
|
-
class << self
|
34
|
-
include FastRuby::BuilderModule
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def self.unset_tree(klass, method_name)
|
40
|
-
fastrubym = klass.fastruby_method(method_name)
|
41
|
-
fastrubym.tree = nil
|
42
|
-
fastrubym.tree_changed
|
43
|
-
nil
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.set_tree(klass, method_name, tree, options = {})
|
47
|
-
unless options[:skip_reduce]
|
48
|
-
unless defined? Reductor
|
49
|
-
require "fastruby/builder/reductor"
|
50
|
-
end
|
51
|
-
|
52
|
-
tree = Reductor.new.reduce(tree)
|
53
|
-
end
|
54
|
-
|
55
|
-
klass.class_eval do
|
56
|
-
class << self
|
57
|
-
include FastRuby::BuilderModule
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
fastrubym = klass.fastruby_method(method_name)
|
62
|
-
|
63
|
-
fastrubym.tree = tree
|
64
|
-
fastrubym.options = options
|
65
|
-
fastrubym.tree_changed
|
66
|
-
require "pry"; binding.pry
|
67
|
-
|
68
|
-
|
69
|
-
nil
|
70
|
-
end
|
71
|
-
end
|