fastruby 0.0.20 → 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/Rakefile +1 -1
  2. data/lib/fastruby/builder.rb~ +5 -1
  3. data/lib/fastruby/corelib/fixnum.rb +1 -1
  4. data/lib/fastruby/corelib/fixnum.rb~ +0 -71
  5. data/lib/fastruby/corelib.rb~ +1 -1
  6. data/lib/fastruby/modules/inliner/call.rb~ +3 -1
  7. data/lib/fastruby/modules/translator/call.rb +1 -1
  8. data/lib/fastruby/modules/translator/call.rb~ +1 -1
  9. data/lib/fastruby/object.rb~ +0 -6
  10. data/lib/fastruby.rb +1 -1
  11. data/lib/fastruby.rb~ +1 -1
  12. data/spec/corelib/numeric/fixnum_spec.rb +1 -1
  13. data/spec/corelib/numeric/fixnum_spec.rb~ +7 -1
  14. metadata +12 -40
  15. data/lib/fastruby/builder/inference_updater.rb~ +0 -76
  16. data/lib/fastruby/builder/inliner.rb~ +0 -60
  17. data/lib/fastruby/builder/lvar_type.rb~ +0 -44
  18. data/lib/fastruby/builder/pipeline.rb~ +0 -43
  19. data/lib/fastruby/builder/reductor.rb~ +0 -42
  20. data/lib/fastruby/corelib/integer.rb~ +0 -96
  21. data/lib/fastruby/modules/inliner/defn.rb~ +0 -29
  22. data/lib/fastruby/modules/inliner/recursive.rb~ +0 -40
  23. data/lib/fastruby/modules/lvar_type/call.rb~ +0 -36
  24. data/lib/fastruby/modules/lvar_type/defn.rb~ +0 -42
  25. data/lib/fastruby/modules/lvar_type/lasgn.rb~ +0 -42
  26. data/lib/fastruby/modules/lvar_type/recursive.rb~ +0 -33
  27. data/lib/fastruby/modules/reductor/nontree.rb~ +0 -32
  28. data/lib/fastruby/modules/reductor/recursive.rb~ +0 -31
  29. data/lib/fastruby/modules/translator/defn.rb~ +0 -267
  30. data/lib/fastruby/modules/translator/directive.rb~ +0 -44
  31. data/lib/fastruby/modules/translator/exceptions.rb~ +0 -120
  32. data/lib/fastruby/modules/translator/iter.rb~ +0 -745
  33. data/lib/fastruby/modules/translator/literal.rb~ +0 -150
  34. data/lib/fastruby/modules/translator/nonlocal.rb~ +0 -298
  35. data/lib/fastruby/modules/translator/static.rb~ +0 -291
  36. data/lib/fastruby/modules/translator/variable.rb~ +0 -280
  37. data/lib/fastruby/set_tree.rb~ +0 -71
  38. data/lib/fastruby/sexp_extension.rb~ +0 -262
  39. data/lib/fastruby/translator/scope_mode_helper.rb~ +0 -138
  40. data/lib/fastruby/translator/translator.rb~ +0 -1600
  41. data/lib/fastruby/translator/translator_modules.rb~ +0 -53
  42. data/lib/fastruby_only/base.rb +0 -1
@@ -1,150 +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
-
24
- define_translator_for(:lit, :arity => 1){|*x| tree = x.first; literal_value tree[1]}
25
- define_translator_for(:nil, :arity => 1){|*x| tree = x.first; "Qnil"}
26
- define_translator_for(:str, :arity => 1){|*x| tree = x.first; literal_value tree[1]}
27
-
28
- define_translator_for(:hash, :method => :to_c_hash)
29
- def to_c_hash(tree, result_var = nil)
30
-
31
- hash_tmp_var = "_hash_"+rand(1000000).to_s
32
- key_tmp_var = "_key_"+rand(1000000).to_s
33
- value_tmp_var = "_value_"+rand(1000000).to_s
34
-
35
- code = proc{
36
- hash_aset_code = ""
37
- (0..(tree.size-3)/2).each do |i|
38
- strkey = to_c tree[1 + i * 2]
39
- strvalue = to_c tree[2 + i * 2]
40
- hash_aset_code << "
41
- {
42
- VALUE #{key_tmp_var} = Qnil;
43
- VALUE #{value_tmp_var} = Qnil;
44
-
45
- #{to_c tree[1 + i * 2], key_tmp_var};
46
- #{to_c tree[2 + i * 2], value_tmp_var};
47
-
48
- rb_hash_aset(#{hash_tmp_var}, #{key_tmp_var}, #{value_tmp_var});
49
- }
50
- "
51
- end
52
-
53
- "
54
- {
55
- VALUE #{hash_tmp_var} = rb_hash_new();
56
- #{hash_aset_code};
57
- #{
58
- if result_var
59
- "#{result_var} = #{hash_tmp_var}"
60
- else
61
- "return #{hash_tmp_var}"
62
- end
63
- };
64
- }
65
- "}
66
-
67
- if result_var
68
- code.call
69
- else
70
- inline_block &code
71
- end
72
- end
73
-
74
- define_translator_for(:array, :method => :to_c_array)
75
- def to_c_array(tree, result_var = nil)
76
- if tree.size > 1
77
- if result_var
78
- prefix = "_array_element_" + rand(10000000).to_s + "_"
79
- "
80
- {
81
- #{
82
- (0..tree.size-2).map{|x|
83
- "VALUE #{prefix}#{x};"
84
- }.join("\n");
85
- }
86
-
87
- #{
88
- (0..tree.size-2).map{|x|
89
- to_c(tree[x+1], prefix+x.to_s)
90
- }.join("\n");
91
- }
92
-
93
- #{result_var} = rb_ary_new3(#{tree.size-1}, #{(0..tree.size-2).map{|x| prefix+x.to_s}.join(",")} );
94
- }
95
- "
96
- else
97
- strargs = tree[1..-1].map{|subtree| to_c subtree}.join(",")
98
- "rb_ary_new3(#{tree.size-1}, #{strargs})"
99
- end
100
- else
101
- if result_var
102
- "#{result_var} = rb_ary_new3(0);"
103
- else
104
- "rb_ary_new3(0)"
105
- end
106
- end
107
- end
108
-
109
- define_translator_for(:self, :arity => 1){|tree| locals_accessor + "self"}
110
- define_translator_for(:false, :arity => 1){|tree| "Qfalse"}
111
- define_translator_for(:true, :arity => 1){|tree| "Qtrue"}
112
-
113
- define_translator_for(:dot2, :method => :to_c_dot2)
114
- def to_c_dot2(tree, result_var = nil)
115
-
116
- begin_var = "_begin"+rand(10000000).to_s
117
- end_var = "_end"+rand(10000000).to_s
118
-
119
- if result_var
120
- "
121
- {
122
- VALUE #{begin_var} = Qnil;
123
- VALUE #{end_var} = Qnil;
124
-
125
- #{to_c tree[1], begin_var};
126
- #{to_c tree[2], end_var};
127
-
128
- #{result_var} = rb_range_new(#{begin_var}, #{end_var},0);
129
- }
130
- "
131
- else
132
- if result_var
133
- "
134
- {
135
- VALUE #{begin_var} = Qnil;
136
- VALUE #{end_var} = Qnil;
137
- #{to_c tree[1], begin_var};
138
- #{to_c tree[2], end_var};
139
-
140
- #{result_var} = rb_range_new(#{begin_var}, #{end_var},0)
141
- }
142
- "
143
- else
144
- "rb_range_new(#{to_c tree[1]}, #{to_c tree[2]},0)"
145
- end
146
- end
147
- end
148
-
149
- end
150
- end
@@ -1,298 +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
-
24
- define_translator_for(:return, :method => :to_c_return)
25
- def to_c_return(tree, return_variable = nil)
26
- code = proc{"
27
- #{to_c(tree[1],"last_expression")};
28
- goto local_return;
29
- return Qnil;
30
- "}
31
-
32
- if return_variable
33
- code.call
34
- else
35
- inline_block &code
36
- end
37
- end
38
-
39
- define_translator_for(:break, :method => :to_c_break)
40
- def to_c_break(tree, result_var = nil)
41
-
42
- value_tmp_var = "value_" + rand(10000000).to_s
43
-
44
- code = proc{"
45
-
46
- {
47
- VALUE #{value_tmp_var} = Qnil;
48
- #{
49
- if tree[1]
50
- to_c(tree[1], value_tmp_var)
51
- end
52
- };
53
-
54
- typeof(pframe) target_frame_;
55
- target_frame_ = (void*)plocals->call_frame;
56
-
57
- if (target_frame_ == 0) {
58
- #{_raise("rb_eLocalJumpError","illegal break_")};
59
- }
60
-
61
- plocals->call_frame = 0;
62
-
63
- target_frame_->return_value = #{value_tmp_var};
64
- target_frame_->targetted = 1;
65
- pframe->thread_data->exception = Qnil;
66
-
67
- longjmp(pframe->jmp,FASTRUBY_TAG_BREAK);
68
-
69
- }
70
- "}
71
-
72
- if result_var
73
- code.call
74
- else
75
- inline_block code
76
- end
77
- end
78
-
79
- define_translator_for(:retry, :method => :to_c_retry)
80
- def to_c_retry(tree, result_var = nil)
81
- code = "
82
- {
83
- typeof(pframe) target_frame_;
84
- target_frame_ = (void*)plocals->call_frame;
85
-
86
- if (target_frame_ == 0) {
87
- #{_raise("rb_eLocalJumpError","illegal retry")};
88
- }
89
-
90
- target_frame_->targetted = 1;
91
- longjmp(pframe->jmp,FASTRUBY_TAG_RETRY);
92
- }
93
- "
94
- if result_var
95
- code
96
- else
97
- inline_block code
98
- end
99
- end
100
-
101
- define_translator_for(:redo, :method => :to_c_redo)
102
- def to_c_redo(tree, result_var = nil)
103
- if @on_block
104
- code = "
105
- goto fastruby_local_redo;
106
- "
107
-
108
- if result_var
109
- code
110
- else
111
- inline_block code
112
- end
113
- else
114
- _raise("rb_eLocalJumpError","illegal redo");
115
- end
116
- end
117
-
118
- define_translator_for(:next, :method => :to_c_next)
119
- def to_c_next(tree, result_var = nil)
120
- tmp_varname = "_acc_" + rand(10000000).to_s
121
- if @on_block
122
- code =proc {"
123
- {
124
- last_expression = Qnil;
125
-
126
- #{
127
- if tree[1]
128
- to_c(tree[1],"last_expression")
129
- end
130
- }
131
- pframe->thread_data->accumulator = last_expression;
132
- goto fastruby_local_next;
133
- }
134
- "}
135
-
136
- if result_var
137
- code.call
138
- else
139
- inline_block &code
140
- end
141
- else
142
- _raise("rb_eLocalJumpError","illegal next");
143
- end
144
- end
145
-
146
- define_method_handler(:to_c, :priority => 100) { |*x|
147
- tree, result_var = x
148
-
149
-
150
- call_tree = tree[1]
151
- catch_tag_id = call_tree[3][1][1]
152
- included_catch_jmp = false
153
-
154
- @catch_jmp = @catch_jmp || Set.new
155
-
156
- begin
157
- inner_code = catch_block(catch_tag_id) do
158
- to_c(tree[3],result_var)
159
- end
160
-
161
- included_catch_jmp = true if @catch_jmp.include?(catch_tag_id)
162
- ensure
163
- @catch_jmp.delete(catch_tag_id)
164
- end
165
-
166
- if included_catch_jmp
167
- new_frame = anonymous_function{ |name| "
168
- static VALUE #{name}(VALUE param) {
169
- volatile VALUE last_expression = Qnil;
170
- #{@frame_struct} frame;
171
-
172
- typeof(frame)* volatile pframe;
173
- typeof(frame)* volatile parent_frame;
174
- #{@locals_struct}* volatile plocals;
175
-
176
- parent_frame = (void*)param;
177
-
178
- frame.parent_frame = (void*)param;
179
- frame.plocals = parent_frame->plocals;
180
- frame.rescue = parent_frame->rescue;
181
- frame.targetted = 0;
182
- frame.thread_data = parent_frame->thread_data;
183
- frame.return_value = Qnil;
184
- frame.thread_data->accumulator = Qnil;
185
- if (frame.thread_data == 0) frame.thread_data = rb_current_thread_data();
186
-
187
- plocals = frame.plocals;
188
- pframe = &frame;
189
-
190
- volatile int aux = setjmp(frame.jmp);
191
- if (aux != 0) {
192
- // restore previous frame
193
- typeof(pframe) original_frame = pframe;
194
- pframe = parent_frame;
195
-
196
- if (aux == (int)#{intern_num catch_tag_id.to_s + "_end"}) {
197
- return frame.thread_data->accumulator;
198
- } else if (aux == (int)#{intern_num catch_tag_id.to_s + "_start"}) {
199
- } else {
200
- longjmp(pframe->jmp,aux);
201
- }
202
-
203
- return last_expression;
204
- }
205
-
206
- #{catch_tag_id.to_s}_start:
207
- #{inner_code};
208
- #{catch_tag_id.to_s}_end:
209
- return last_expression;
210
- #{@catch_blocks.map { |cb|
211
- "#{cb.to_s}_end:
212
-
213
- plocals->return_value = last_expression;
214
- plocals->targetted = 1;
215
- longjmp(pframe->jmp, #{intern_num( cb.to_s + "_end")});
216
-
217
- #{cb.to_s}_start:
218
-
219
- plocals->return_value = last_expression;
220
- plocals->targetted = 1;
221
- longjmp(pframe->jmp, #{intern_num( cb.to_s + "_start")});
222
-
223
- "
224
-
225
- }.join("\n")
226
- }
227
-
228
- }
229
- "
230
- } + "((VALUE)pframe)"
231
-
232
- if result_var
233
- "#{result_var} = #{new_frame};"
234
- else
235
- new_frame
236
- end
237
- else
238
- "
239
- #{catch_tag_id.to_s}_start:
240
- #{inner_code};
241
- #{catch_tag_id.to_s}_end:
242
-
243
- "
244
- end
245
-
246
- }.condition{|*x|
247
- tree, result_var = x
248
-
249
- tree.node_type == :iter && tree[1][2] == :_catch
250
- }
251
-
252
- define_method_handler(:to_c, :priority => 100) { |*x|
253
- tree, result_var = x
254
-
255
- code = ""
256
-
257
- catch_tag_id = tree[3][1][1]
258
-
259
- if @catch_jmp_on_throw
260
- @catch_jmp << catch_tag_id
261
- end
262
-
263
- code << to_c(tree[3][2] || fs(:nil), "last_expression")
264
- code << "pframe->thread_data->accumulator = last_expression;"
265
- code << "goto #{catch_tag_id.to_s}_end;"
266
-
267
- if result_var
268
- code
269
- else
270
- inline_block code
271
- end
272
- }.condition{|*x|
273
- tree, result_var = x
274
-
275
- tree.node_type == :call && tree[2] == :_throw
276
- }
277
-
278
- define_method_handler(:to_c, :priority => 100) { |*x|
279
- tree, result_var = x
280
-
281
- code = ""
282
-
283
- catch_tag_id = tree[3][1][1]
284
- code << "goto #{catch_tag_id.to_s}_start;"
285
-
286
- if result_var
287
- code
288
- else
289
- inline_block code
290
- end
291
- }.condition{|*x|
292
- tree, result_var = x
293
-
294
- tree.node_type == :call && tree[2] == :_loop
295
- }
296
-
297
- end
298
- end