ytljit 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -190,6 +190,25 @@ module YTLJit
190
190
  # setclassvariable
191
191
 
192
192
  def visit_getconstant(code, ins, context)
193
+ klass = context.expstack.pop
194
+ case klass
195
+ when ConstantRefNode
196
+ klass = klass.value_node
197
+
198
+
199
+ when LiteralNode
200
+ klass = klass.value
201
+ if klass == nil then
202
+ klass = context.current_class_node
203
+ end
204
+
205
+ else
206
+ raise "Umkonwn node #{klass.class}"
207
+ end
208
+ name = ins[1]
209
+ curnode = context.current_node
210
+ node = ConstantRefNode.new(curnode, klass, name)
211
+ context.expstack.push node
193
212
  end
194
213
 
195
214
  def visit_setconstant(code, ins, context)
@@ -305,27 +324,51 @@ module YTLJit
305
324
  def visit_defineclass(code, ins, context)
306
325
  name = ins[1]
307
326
  supklsnode = context.expstack.pop
308
- klassobj = Object.const_get(name, true)
327
+ defat = context.expstack.pop
328
+ clsobj = context.current_class_node.klass_object
329
+ klassobj = nil
330
+ begin
331
+ klassobj = clsobj.const_get(name, true)
332
+ rescue NameError
333
+ end
309
334
 
310
335
  if klassobj == nil then
311
- klassnode = context.nested_class_tab[name]
336
+ klassnode = context.current_class_node.constant_tab[name]
312
337
  if klassnode then
313
- klassobj = klassnodne.klasss_object
338
+ klassobj = klassnodne.klass_object
314
339
 
315
340
  else
341
+ supklass = nil
342
+ case supklsnode
343
+ when LiteralNode
344
+ supklass = supklsnode.value
345
+ if supklass == nil then
346
+ supklass = Object
347
+ end
348
+
349
+ when ConstantRefNode
350
+ supnode = supklsnode.value_node
351
+ if supnode.is_a?(ClassTopNode) then
352
+ supklass = supnode.klass_object
353
+ else
354
+ raise "Not class #{supnode.class}"
355
+ end
356
+
357
+ else
358
+ raise "Not support #{supklsnode.class}"
359
+ end
360
+
316
361
  case ins[3]
317
362
  when 0
318
- supklass = nil
319
- if supklsnode then
320
- supklass = supklasnode.klasss_object
321
- end
322
363
  klassobj = Class.new(supklass)
323
364
 
324
365
  when 2
325
- klassobj = Module.new(supklass)
366
+ klassobj = Module.new
326
367
  end
327
368
  end
369
+ clsobj.const_set(name, klassobj)
328
370
  end
371
+ RubyType::define_wraped_class(klassobj, RubyType::RubyTypeBoxed)
329
372
  cnode = ClassTopNode.new(context.current_class_node, klassobj, name)
330
373
 
331
374
  body = VMLib::InstSeqTree.new(code, ins[2])
@@ -333,12 +376,16 @@ module YTLJit
333
376
  ncontext.current_file_name = context.current_file_name
334
377
  ncontext.current_node = cnode
335
378
  ncontext.current_class_node = cnode
336
- ncontext.top_nodes.push mtopnode
379
+ ncontext.top_nodes.push cnode
337
380
 
338
381
  tr = self.class.new([body])
339
382
  tr.translate(ncontext)
340
383
 
341
- context.current_class_node.nested_class_tab[name] = cnode
384
+ context.current_class_node.constant_tab[name] = cnode
385
+ curnode = context.current_node
386
+ cvnode = ClassValueNode.new(curnode, cnode)
387
+ context.expstack.push cvnode
388
+
342
389
  context
343
390
  end
344
391
 
@@ -85,7 +85,7 @@ module YTLJit
85
85
  @types_tree = KlassTree.new
86
86
  end
87
87
 
88
- def to_key(context, offset = -1)
88
+ def to_signature(context, offset = -1)
89
89
  context.current_method_signature[offset]
90
90
  end
91
91
 
@@ -143,18 +143,24 @@ module YTLJit
143
143
  module RubyType
144
144
  def self.define_wraped_class(klass, base = RubyTypeBoxed)
145
145
  cn = nil
146
-
147
- if klass then
146
+ if klass.name then
148
147
  cn = klass.name.to_sym
149
- basett, boxtt, unboxtt = BaseType.type_tab
150
- if boxtt[cn] == nil then
151
- BaseType.related_ruby_class(klass, base)
148
+ else
149
+ cns = klass.inspect
150
+ if /([a-zA-Z:]+)/ =~ cns then
151
+ cn = $1.to_sym
152
+ else
153
+ raise "Unexcepcted class format #{cns}"
152
154
  end
153
-
154
- boxobj = boxtt[cn]
155
- unboxobj = unboxtt[cn]
156
- [boxobj, unboxobj]
157
155
  end
156
+ basett, boxtt, unboxtt = BaseType.type_tab
157
+ if boxtt[cn] == nil then
158
+ BaseType.related_ruby_class(klass, base)
159
+ end
160
+
161
+ boxobj = boxtt[cn]
162
+ unboxobj = unboxtt[cn]
163
+ [boxobj, unboxobj]
158
164
  end
159
165
 
160
166
  class BaseType
@@ -287,13 +293,16 @@ module YTLJit
287
293
  include VM::TypeCodeGen::DefaultTypeCodeGen
288
294
  end
289
295
 
290
- YTLJit::RubyType::define_wraped_class(NilClass, RubyTypeBoxed)
291
- YTLJit::RubyType::define_wraped_class(Fixnum, RubyTypeUnboxed)
292
- YTLJit::RubyType::define_wraped_class(Float, RubyTypeUnboxed)
293
- YTLJit::RubyType::define_wraped_class(TrueClass, RubyTypeBoxed)
294
- YTLJit::RubyType::define_wraped_class(FalseClass, RubyTypeBoxed)
295
- YTLJit::RubyType::define_wraped_class(String, RubyTypeBoxed)
296
- YTLJit::RubyType::define_wraped_class(Array, RubyTypeBoxed)
297
- YTLJit::RubyType::define_wraped_class(Hash, RubyTypeBoxed)
296
+ define_wraped_class(NilClass, RubyTypeBoxed)
297
+ define_wraped_class(Fixnum, RubyTypeUnboxed)
298
+ define_wraped_class(Float, RubyTypeUnboxed)
299
+ define_wraped_class(TrueClass, RubyTypeBoxed)
300
+ define_wraped_class(FalseClass, RubyTypeBoxed)
301
+ define_wraped_class(Symbol, RubyTypeBoxed)
302
+ define_wraped_class(String, RubyTypeBoxed)
303
+ define_wraped_class(Array, RubyTypeBoxed)
304
+ define_wraped_class(Hash, RubyTypeBoxed)
305
+ define_wraped_class(Module, RubyTypeBoxed)
306
+ define_wraped_class(Class, RubyTypeBoxed)
298
307
  end
299
308
  end
@@ -82,7 +82,6 @@ module YTLJit
82
82
  include AbsArch
83
83
 
84
84
  def gen_boxing(context)
85
- p "boxingaaa"
86
85
  context
87
86
  end
88
87
 
@@ -111,7 +110,6 @@ module YTLJit
111
110
  end
112
111
 
113
112
  def gen_unboxing(context)
114
- p "unboxing"
115
113
  context
116
114
  end
117
115
  end
data/test/vmtest.rb CHANGED
@@ -17,7 +17,10 @@ is = RubyVM::InstructionSequence.compile(
17
17
  # "def foo(x); if x then x = 2.0 else x = 1 end; x; end; p foo(1)", "", "", 0,
18
18
  # "def foo(x); yield(x) + 2; end; p foo(1) {|a| a + 1}", "", "", 0,
19
19
  # "def id(x); x; end; p id(1); p id(1.0)", "", "", 0,
20
- "def id(x); x; end; p id(1); p id(1.0); def id2(x) x end; id2(1)", "", "", 0,
20
+ # "def id(x); x; end; p id(1); p id(1.0); def id2(x) x end; id2(1)", "", "", 0,
21
+ "def mul(x); x * x; end; p mul(20);p mul(30.0)", "", "", 0,
22
+ # "def div(x, y); x / y; end; p div(20, 10);p div(30.0, -12.0)", "", "", 0,
23
+ # "def div(x, y); x / y; end; p div(-20, 10);p div(30.0, -12.0)", "", "", 0,
21
24
  # "1.1","", "", 0,
22
25
  { :peephole_optimization => true,
23
26
  :inline_const_cache => false,
@@ -42,6 +45,7 @@ tnode.collect_candidate_type(context, [], [])
42
45
 
43
46
  tnode = Marshal.load(Marshal.dump(tnode))
44
47
  context = VM::CompileContext.new(tnode)
48
+ context.options = {:disp_signature => true}
45
49
  tnode.compile(context)
46
50
  # context.code_space.disassemble
47
51
  p tnode.code_space
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
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: 2010-10-20 00:00:00 +09:00
17
+ date: 2010-11-04 00:00:00 +09:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency