ytl 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/ytl/accmem.rb CHANGED
@@ -243,9 +243,9 @@ module YTLJit
243
243
  end
244
244
 
245
245
  def collect_candidate_type_regident(context, slf)
246
- if Runtime::Arena.is_a?(slf.ruby_type) then
247
- slfcls = @arguments[2].get_constant_value
248
- tt = RubyType::BaseType.from_ruby_class(slfcls[0])
246
+ slfcls = @arguments[2].get_constant_value
247
+ tt = RubyType::BaseType.from_ruby_class(slfcls[0])
248
+ if tt.ruby_type == Runtime::Arena then
249
249
  add_type(context.to_signature, tt)
250
250
 
251
251
  if @initmethod.is_a?(SendInitializeNode) then
data/lib/ytl.rb CHANGED
@@ -9,7 +9,7 @@ include YTLJit
9
9
  module YTL
10
10
  include YTLJit
11
11
 
12
- VERSION = "0.0.3"
12
+ VERSION = "0.0.4"
13
13
 
14
14
  ISEQ_OPTS = {
15
15
  :peephole_optimization => true,
@@ -19,60 +19,68 @@ module YTL
19
19
 
20
20
  def self.parse_opt(argv)
21
21
  ytlopt = {}
22
- prelude = File.join(File.dirname(__FILE__), "..", "runtime", "prelude.rb")
23
- ytlopt[:execute_before_compile] = [prelude]
22
+ ytlopt[:execute_before_compile] = []
24
23
  opt = OptionParser.new
25
24
 
26
25
  opt.on('--disasm', 'Disasemble generated code') do |f|
27
26
  ytlopt[:disasm] = f
28
27
  end
29
-
28
+
30
29
  opt.on('--dump-yarv', 'Dump YARV byte code') do |f|
31
30
  ytlopt[:dump_yarv] = f
32
31
  end
33
-
32
+
34
33
  opt.on('--disp-signature', 'Display signature of method') do |f|
35
34
  ytlopt[:disp_signature] = f
36
35
  end
37
-
36
+
38
37
  opt.on('--dump-context', 'Dump context(registor/stack) for debug') do |f|
39
38
  ytlopt[:dump_context] = f
40
39
  end
41
-
40
+
42
41
  opt.on('-o FILE', '--write-code =FILE',
43
- 'Write generating naitive code and node objects') do |f|
42
+ 'Write generating naitive code and node objects') do |f|
44
43
  ytlopt[:write_code] = f
45
44
  end
46
-
45
+
47
46
  opt.on('--write-node-before-type-inference =FILE',
48
47
  'Write node of before type inference') do |f|
49
48
  ytlopt[:write_node_before_ti] = f
50
49
  end
51
-
50
+
52
51
  opt.on('--write-node-after-type-inference =FILE',
53
52
  'Write node of after type inference') do |f|
54
53
  ytlopt[:write_node_after_ti] = f
55
54
  end
56
-
55
+
57
56
  opt.on('-r FILE', '--execute-before-compile =FILE',
58
57
  'Execute ruby program (execute by CRuby)') do |f|
59
58
  ytlopt[:execute_before_compile].push f
60
59
  end
61
-
60
+
62
61
  opt.on('-c', '--compile-only',
63
62
  'Stop when compile finished (not execute compiled code)') do |f|
64
63
  ytlopt[:compile_only] = f
65
64
  end
66
-
65
+
67
66
  opt.on('--compile-array-as-unboxed',
68
67
  'Compile Array as unboxed if nesseary(not excape, not use special methods)') do |f|
69
68
  ytlopt[:compile_array_as_uboxed] = f
70
69
  end
71
-
70
+
72
71
  opt.parse!(argv)
73
72
  ytlopt
74
73
  end
75
74
 
75
+ def self.prelude_iseq
76
+ prelude = File.join(File.dirname(__FILE__), "..", "runtime", "prelude.rb")
77
+ rf = File.read(prelude)
78
+ prog = eval(rf)
79
+ is = RubyVM::InstructionSequence.compile(prog, ARGV[0],
80
+ "", 0, ISEQ_OPTS).to_a
81
+ VMLib::InstSeqTree.new(nil, is)
82
+ end
83
+
76
84
  def self.dump_node(tnode, fn)
77
85
  if defined? yield then
78
86
  yield
@@ -83,72 +91,73 @@ module YTL
83
91
  fp.print "class #{klass.name}; end\n"
84
92
  end
85
93
  end
86
-
94
+
87
95
  fp.print "Marshal.load(<<'EOS')\n"
88
96
  fp.print Marshal.dump(tnode)
89
97
  fp.print "\n"
90
98
  fp.print "EOS\n"
91
99
  end
92
100
  end
93
-
101
+
94
102
  def self.reduced_main(prog, options)
95
103
  tr_context = VM::YARVContext.new
96
-
104
+
97
105
  import_ruby_object(tr_context)
98
-
106
+
99
107
  tnode = nil
100
108
  is = RubyVM::InstructionSequence.compile(prog, ARGV[0],
101
109
  "", 0, ISEQ_OPTS).to_a
102
110
  iseq = VMLib::InstSeqTree.new(nil, is)
111
+ iseqs = [prelude_iseq, iseq]
103
112
 
104
- tr = VM::YARVTranslatorCRubyObject.new([iseq])
113
+ tr = VM::YARVTranslatorCRubyObject.new(iseqs)
105
114
  tnode = tr.translate(tr_context)
106
-
115
+
107
116
  ci_context = VM::CollectInfoContext.new(tnode)
108
117
  ci_context.options = options
109
118
  tnode.collect_info(ci_context)
110
-
119
+
111
120
  dmylit = VM::Node::LiteralNode.new(tnode, nil)
112
121
  arg = [dmylit, dmylit, dmylit]
113
122
  sig = []
114
123
  arg.each do |ele|
115
124
  sig.push RubyType::BaseType.from_ruby_class(NilClass)
116
125
  end
117
-
126
+
118
127
  ti_context = VM::TypeInferenceContext.new(tnode)
119
128
  ti_context.options = options
120
129
  begin
121
130
  tnode.collect_candidate_type(ti_context, arg, sig)
122
131
  end until ti_context.convergent
123
132
  ti_context = tnode.collect_candidate_type(ti_context, arg, sig)
124
-
133
+
125
134
  c_context = VM::CompileContext.new(tnode)
126
135
  c_context.current_method_signature.push sig
127
136
  c_context.options = options
128
137
  c_context = tnode.compile(c_context)
129
138
  tnode.make_frame_struct_tab
130
-
139
+
131
140
  tcs = tnode.code_space
132
141
  tcs.call(tcs.base_address)
133
142
  end
134
-
143
+
135
144
  def self.main(options)
136
145
  tr_context = VM::YARVContext.new
137
146
  progs = []
138
-
147
+
139
148
  import_ruby_object(tr_context)
140
149
  options[:execute_before_compile].each do |fn|
141
150
  rf = File.read(fn)
142
151
  prog = eval(rf)
143
152
  progs.push prog
144
153
  is = RubyVM::InstructionSequence.compile(prog, ARGV[0],
145
- "", 0, ISEQ_OPTS).to_a
154
+ "", 0, ISEQ_OPTS).to_a
146
155
  iseq = VMLib::InstSeqTree.new(nil, is)
147
156
  tr = VM::YARVTranslatorCRubyObject.new([iseq])
148
157
  tr_context.current_file_name = fn
149
158
  tr.translate(tr_context)
150
159
  end
151
-
160
+
152
161
  tnode = nil
153
162
  case File.extname(ARGV[0])
154
163
  when ".ytl"
@@ -160,7 +169,7 @@ module YTL
160
169
  tnode.code_space.call(tnode.code_space.base_address)
161
170
  return
162
171
  end
163
-
172
+
164
173
  when ".rb"
165
174
  prog = File.read(ARGV[0])
166
175
  is = RubyVM::InstructionSequence.compile(prog, ARGV[0],
@@ -169,34 +178,35 @@ module YTL
169
178
  if options[:dump_yarv] then
170
179
  pp iseq
171
180
  end
172
-
173
- tr = VM::YARVTranslatorCRubyObject.new([iseq])
181
+ iseqs = [prelude_iseq, iseq]
182
+
183
+ tr = VM::YARVTranslatorCRubyObject.new(iseqs)
174
184
  tr_context.current_file_name = ARGV[0]
175
185
  tnode = tr.translate(tr_context)
176
186
  end
177
-
187
+
178
188
  ci_context = VM::CollectInfoContext.new(tnode)
179
189
  ci_context.options = options
180
190
  tnode.collect_info(ci_context)
181
-
191
+
182
192
  if fn = options[:write_node_before_ti] then
183
193
  dump_node(tnode, fn)
184
194
  end
185
-
195
+
186
196
  dmylit = VM::Node::LiteralNode.new(tnode, nil)
187
197
  arg = [dmylit, dmylit, dmylit]
188
198
  sig = []
189
199
  arg.each do |ele|
190
200
  sig.push RubyType::BaseType.from_ruby_class(NilClass)
191
201
  end
192
-
202
+
193
203
  ti_context = VM::TypeInferenceContext.new(tnode)
194
204
  ti_context.options = options
195
205
  begin
196
206
  tnode.collect_candidate_type(ti_context, arg, sig)
197
207
  end until ti_context.convergent
198
208
  ti_context = tnode.collect_candidate_type(ti_context, arg, sig)
199
-
209
+
200
210
  if fn = options[:write_node_after_ti] then
201
211
  dump_node(tnode, fn)
202
212
  end
@@ -206,20 +216,20 @@ module YTL
206
216
  c_context.options = options
207
217
  c_context = tnode.compile(c_context)
208
218
  tnode.make_frame_struct_tab
209
-
219
+
210
220
  if fn = options[:write_code] then
211
221
  dump_node(tnode, fn) {
212
222
  tnode.code_store_hook
213
223
  }
214
224
  end
215
-
225
+
216
226
  if options[:disasm] then
217
227
  tnode.code_space_tab.each do |cs|
218
228
  cs.fill_disasm_cache
219
229
  end
220
230
  tnode.code_space.disassemble
221
231
  end
222
-
232
+
223
233
  tcs = tnode.code_space
224
234
  STDOUT.flush
225
235
  if !options[:compile_only] then
data/runtime/prelude.rb CHANGED
@@ -24,10 +24,34 @@ class Array
24
24
  yield self[i]
25
25
  i = i + 1
26
26
  end
27
-
27
+
28
28
  self
29
29
  end
30
30
 
31
+ def collect
32
+ res = []
33
+ i = 0
34
+ e = self.size
35
+ while i < e
36
+ res[i] = yield self[i]
37
+ i = i + 1
38
+ end
39
+
40
+ res
41
+ end
42
+
43
+ def map
44
+ res = []
45
+ i = 0
46
+ e = self.size
47
+ while i < e
48
+ res[i] = yield self[i]
49
+ i = i + 1
50
+ end
51
+
52
+ res
53
+ end
54
+
31
55
  def at(idx)
32
56
  self[idx]
33
57
  end
@@ -49,7 +73,26 @@ class Range
49
73
  end
50
74
  end
51
75
 
52
- e
76
+ self
77
+ end
78
+
79
+ def to_a
80
+ i = self.first
81
+ e = self.last
82
+ res = []
83
+ if self.exclude_end? then
84
+ while i < e
85
+ res.push i
86
+ i = i + 1
87
+ end
88
+ else
89
+ while i <= e
90
+ res.push i
91
+ i = i + 1
92
+ end
93
+ end
94
+
95
+ res
53
96
  end
54
97
  end
55
98
 
data/test/floattest.rb CHANGED
@@ -2,3 +2,10 @@ p "2.0".to_f
2
2
  p (7).to_f
3
3
  p Math.sin(3.14159265)
4
4
  p Math.sqrt(2.0)
5
+ p (0.0).to_i
6
+ p 1.to_i
7
+ p 1.5.to_i
8
+ p 1.0.to_i
9
+ p 3.14.to_i
10
+ p -3.00000001.to_i
11
+ p 3.00000001.to_i
data/test/hashtest.rb ADDED
@@ -0,0 +1,15 @@
1
+ a = Hash.new
2
+ a[:a] = 1
3
+ a[:b] = 2
4
+
5
+ p a[:a]
6
+ p a[:b]
7
+ p a[:c]
8
+
9
+ b = {:a => 1, :b => 3, 1 => :c}
10
+ p b
11
+ p b[:a]
12
+ p b[:b]
13
+ p b[3]
14
+
15
+
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Hideki Miura
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-05-06 00:00:00 +09:00
17
+ date: 2011-08-14 00:00:00 +09:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -46,7 +46,6 @@ files:
46
46
  - lib/ytl/importobj.rb
47
47
  - lib/ytl/macro.rb
48
48
  - runtime/prelude.rb
49
- - runtime/test.rb
50
49
  - runtime/type.rb
51
50
  - test/basictest.rb
52
51
  - test/breaktest.rb
@@ -56,6 +55,7 @@ files:
56
55
  - test/execytl.rb
57
56
  - test/exttest.rb
58
57
  - test/floattest.rb
58
+ - test/hashtest.rb
59
59
  - test/ivtest.rb
60
60
  - test/looptest.rb
61
61
  - test/macrotest.rb
@@ -103,6 +103,7 @@ test_files:
103
103
  - test/execytl.rb
104
104
  - test/exttest.rb
105
105
  - test/floattest.rb
106
+ - test/hashtest.rb
106
107
  - test/ivtest.rb
107
108
  - test/looptest.rb
108
109
  - test/macrotest.rb
data/runtime/test.rb DELETED
@@ -1 +0,0 @@
1
-