Module: YTLJit::VM::YARVTranslatorSimpleMixin

Includes:
Node
Included in:
YARVTranslatorCRubyObject, YARVTranslatorSimple
Defined in:
lib/ytljit/vm_trans.rb

Instance Method Summary collapse

Methods included from Node

#compile_compare_nonnum

Instance Method Details

#depth_of_block(code) ⇒ Object



286
287
288
289
290
291
292
293
294
295
# File 'lib/ytljit/vm_trans.rb', line 286

def depth_of_block(code)
  dep = 0
  ccode = code
  while ccode.header['type'] == :block
    ccode = ccode.parent
    dep += 1
  end
  
  dep
end

#gen_arg_node(context, sendnode, func, args) ⇒ Object



183
184
185
186
187
188
189
# File 'lib/ytljit/vm_trans.rb', line 183

def gen_arg_node(context, sendnode, func, args)
  curnode = context.current_node
  nnode = sendnode.new(curnode, func, args, 0, 0)
  nnode.debug_info = context.debug_info
  func.parent = nnode
  nnode
end

#get_self_object(context) ⇒ Object

getclassvariable setclassvariable



363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
# File 'lib/ytljit/vm_trans.rb', line 363

def get_self_object(context)
  klass = context.expstack.pop
  case klass
  when ConstantRefNode
    klass = klass.value_node

  when LiteralNode
    klass = klass.value
    if klass == nil then
      klass = context.current_class_node
    end

  when SpecialObjectNode
    if klass.kind == 3 then
      klass = context.current_class_node
    else
      raise "Unkown special object kind = #{klass.kind}"
    end

  else
    raise "Umkonwn node #{klass.class}"
  end

  klass
end

#get_vmnode_from_label(context, label) ⇒ Object



170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/ytljit/vm_trans.rb', line 170

def get_vmnode_from_label(context, label)
  curnode = context.current_node
  nllab = context.local_label_tab[label]
  if nllab == nil then
    nllab = LocalLabel.new(curnode, label)
    nllab.value_node = PhiNode.new(nllab)
    nllab.debug_info = context.debug_info
    context.local_label_tab[label] = nllab
  end
  
  nllab
end

#newinst_to_sendnode(argnum, klass, code, ins, context) ⇒ Object

toregexp



514
515
516
517
518
519
520
521
522
523
524
525
526
527
# File 'lib/ytljit/vm_trans.rb', line 514

def newinst_to_sendnode(argnum, klass, code, ins, context)
  arg = []
  argnum.times {
    arg.push context.expstack.pop
  }
  curnode = context.current_node
  arg.push ConstantRefNode.new(curnode, nil, klass.name.to_sym)

  arg.reverse.each do |c|
    context.expstack.push c
  end

  visit_send(code, [:send, :new, argnum, nil, 0, nil], context)
end

#visit_block_end(code, ins, context) ⇒ Object



262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/ytljit/vm_trans.rb', line 262

def visit_block_end(code, ins, context)
  curnode = context.current_node
  top = context.top_nodes.last
  klassnode = context.current_class_node
  top.exception_table = context.exception_table
  if top.class == MethodTopNode then
    if context.macro_method then
      code = top.to_ruby(ToRubyContext.new).ret_code.last
      #            print code
      proc = eval("lambda" + code)
      if SendNode.get_macro_tab[top.name] == nil then
        SendNode.get_macro_tab[top.name] = {}
      end
      SendNode.get_macro_tab[top.name][:last] = proc
    else
      if !SendNode.get_user_defined_method_tab[top.name] then
        SendNode.get_user_defined_method_tab[top.name] = []
      end
      klassobj = klassnode.klass_object
      SendNode.get_user_defined_method_tab[top.name].push klassobj
    end
  end
end

#visit_block_start(code, ins, context) ⇒ Object



216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/ytljit/vm_trans.rb', line 216

def visit_block_start(code, ins, context)
  mtopnode = context.current_node
  if !mtopnode.is_a?(TopNode) then
    oldtop = context.the_top
    mtopnode = TopTopNode.new(nil, Object)
    mtopnode.debug_info = context.debug_info
    context.the_top = mtopnode
    oldtop.parent = mtopnode
    mtopnode.init_node = oldtop
  end

  context.macro_method = nil

  locals = code.header['locals']
  arg_size   = code.header['misc'][:arg_size]
  args   = code.header['args']
  (arg_size - locals.size).times do 
    locals.push nil
  end
  cnode = mtopnode.construct_frame_info(locals, arg_size, args)
  exptab = code.header['exception_table']
  context.exception_table = {}
  if exptab.size != 0 then
    exptab.each do |tag, body, st, ed, cont, sp|
      context.exception_table[tag] ||= []
      nbody = nil
      if body then
        ncontext = YARVContext.new(context)
        nbody = ExceptionTopNode.new(mtopnode)
        nbody.debug_info = context.debug_info
        ncontext.current_node = nbody
        ncontext.top_nodes.push nbody
        ncontext.current_file_name = context.current_file_name
        ncontext.current_class_node = context.current_class_node
        ncontext.current_method_node = context.current_method_node
        tr = self.class.new([VMLib::InstSeqTree.new(code, body)])
        tr.translate(ncontext)
      end
      context.exception_table[tag].push [st, ed, cont, nbody]
    end
  end

  context.not_reached_pos = false
  context.current_node = cnode
end

#visit_branchif(code, ins, context) ⇒ Object



927
928
929
930
931
932
933
934
935
936
937
938
939
# File 'lib/ytljit/vm_trans.rb', line 927

def visit_branchif(code, ins, context)
  curnode = context.current_node
  nllab = get_vmnode_from_label(context, ins[1])
 
  cond = context.expstack.pop
 
  node = BranchIfNode.new(curnode, cond, nllab)
  node.debug_info = context.debug_info
  nllab.come_from[node] = nil

  curnode.body = node
  context.current_node = node
end

#visit_branchunless(code, ins, context) ⇒ Object



941
942
943
944
945
946
947
948
949
950
951
952
953
# File 'lib/ytljit/vm_trans.rb', line 941

def visit_branchunless(code, ins, context)
  curnode = context.current_node
  nllab = get_vmnode_from_label(context, ins[1])

  cond = context.expstack.pop
  
  node = BranchUnlessNode.new(curnode, cond, nllab)
  node.debug_info = context.debug_info
  nllab.come_from[node] = nil

  curnode.body = node
  context.current_node = node
end

#visit_concatstrings(code, ins, context) ⇒ Object



486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
# File 'lib/ytljit/vm_trans.rb', line 486

def visit_concatstrings(code, ins, context)
  curnode = context.current_node
  numarg = ins[1]
  nnode = context.expstack[-numarg]
  (numarg - 1).times do |i|
    func = FixArgCApiNode.new(curnode, "rb_str_append", [:VALUE, :VALUE])
    args = [nnode, context.expstack[i - numarg + 1]]
    nnode = gen_arg_node(context, RetStringSendNode, func, args)
  end

  numarg.times do
    context.expstack.pop
  end
  context.expstack.push nnode
end

#visit_defineclass(code, ins, context) ⇒ Object



656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
# File 'lib/ytljit/vm_trans.rb', line 656

def visit_defineclass(code, ins, context)
  name = ins[1]
  supklsnode = context.expstack.pop
  defat = context.expstack.pop
  clsobj = context.current_class_node.klass_object
  klassobj = nil
  begin
    klassobj = clsobj.const_get(name, true)
  rescue NameError
  end

  if klassobj == nil then
    klassnode = context.current_class_node.constant_tab[name]
    if klassnode then
      klassobj = klassnodne.klass_object
      
    else
      supklass = nil
      case supklsnode
      when LiteralNode
        supklass = supklsnode.value
        if supklass == nil then
          supklass = Object
        end

      when ConstantRefNode
        supnode = supklsnode.value_node
        if supnode.is_a?(ClassTopNode) then
          supklass = supnode.klass_object
        else
          raise "Not class #{supnode.class}"
        end

      else
        raise "Not support #{supklsnode.class}"
      end

      case ins[3]
      when 0
        klassobj = Class.new(supklass)
        
      when 2
        klassobj = Module.new
      end
    end
    clsobj.const_set(name, klassobj)
  end
  RubyType::define_wraped_class(klassobj, RubyType::RubyTypeBoxed)
  cnode = ClassTopNode.new(context.current_class_node, klassobj, name)
  cnode.debug_info = context.debug_info
  context.current_class_node.constant_tab[name] = cnode
  
  body = VMLib::InstSeqTree.new(code, ins[2])
  ncontext = YARVContext.new(context)
  ncontext.current_file_name = context.current_file_name
  ncontext.current_node = cnode
  ncontext.current_class_node = cnode
  ncontext.top_nodes.push cnode

  tr = self.class.new([body])
  tr.translate(ncontext)

  curnode = context.current_node
  cvnode = ClassValueNode.new(curnode, cnode)
  cvnode.debug_info = context.debug_info
  context.expstack.push cvnode

  context
end

#visit_dup(code, ins, context) ⇒ Object



603
604
605
606
607
608
# File 'lib/ytljit/vm_trans.rb', line 603

def visit_dup(code, ins, context)
  orgnode = context.expstack.pop
  nnode = MultiplexNode.new(orgnode)
  context.expstack.push nnode
  context.expstack.push nnode
end

#visit_duparray(code, ins, context) ⇒ Object



546
547
548
549
550
# File 'lib/ytljit/vm_trans.rb', line 546

def visit_duparray(code, ins, context)
  nnode = LiteralNode.new(nil, ins[1])
  nnode.debug_info = context.debug_info
  context.expstack.push nnode
end

#visit_dupn(code, ins, context) ⇒ Object



610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
# File 'lib/ytljit/vm_trans.rb', line 610

def visit_dupn(code, ins, context)
  res = []
  n = ins[1]
  n.times do
    orgnode = context.expstack.pop
    nnode = MultiplexNode.new(orgnode)
    res.push nnode
  end
  res = res.reverse
  res.each do |ele|
    context.expstack.push ele
  end
  res.each do |ele|
    context.expstack.push ele
  end
end

#visit_getconstant(code, ins, context) ⇒ Object



389
390
391
392
393
394
395
396
# File 'lib/ytljit/vm_trans.rb', line 389

def visit_getconstant(code, ins, context)
  klass = get_self_object(context)
  name = ins[1]
  curnode = context.current_node
  node = ConstantRefNode.new(curnode, klass, name)
  node.debug_info = context.debug_info
  context.expstack.push node
end

#visit_getdynamic(code, ins, context) ⇒ Object

getspecial setspecial



313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/ytljit/vm_trans.rb', line 313

def visit_getdynamic(code, ins, context)
  # + 3 mean prtv_env/pointer to block function/self
  dep = ins[2]
  curcode = code
  dep.times do
    curcode = curcode.parent
  end
  offset = curcode.header['misc'][:local_size] + 3 - ins[1]
  node = nil
  if curcode.header['type'] == :ensure and offset == 3 then
    node = LiteralNode.new(context.current_node, nil)
    node.debug_info = context.debug_info
  else
    node = LocalVarRefNode.new(context.current_node, offset, dep)
    node.debug_info = context.debug_info
  end
  context.expstack.push node
end

#visit_getglobal(code, ins, context) ⇒ Object



409
410
411
412
413
414
415
# File 'lib/ytljit/vm_trans.rb', line 409

def visit_getglobal(code, ins, context)
  name = ins[1]
  curnode = context.current_node
  node = GlobalVarRefNode.new(curnode, name)
  curnode.body = node
  context.expstack.push node
end

#visit_getlocal(code, ins, context) ⇒ Object



300
301
302
303
# File 'lib/ytljit/vm_trans.rb', line 300

def visit_getlocal(code, ins, context)
  dep = depth_of_block(code)
  visit_getdynamic(code, [:getlocal, ins[1], dep], context)
end

#visit_invokeblock(code, ins, context) ⇒ Object



812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
# File 'lib/ytljit/vm_trans.rb', line 812

def visit_invokeblock(code, ins, context)
  curnode = context.current_node
  func = YieldNode.new(curnode)
  func.debug_info = context.debug_info
  numarg = ins[1]
  op_flag = ins[2]
  seqno = ins[3]

  # regular arguments
  args = []
  numarg.times do |i|
    argele = context.expstack.pop
    args.push argele
  end

  frameinfo = func.frame_info
  roff = frameinfo.real_offset(0)  # offset of prevenv
  framelayout = frameinfo.frame_layout

  # self
  argnode = LiteralNode.new(curnode, nil)
  argnode.debug_info = context.debug_info
  args.push argnode

  # block
  argnode = LiteralNode.new(curnode, nil)
  argnode.debug_info = context.debug_info
  args.push argnode
  
  # perv env
  argnode = LiteralNode.new(curnode, nil)
  argnode.debug_info = context.debug_info
  args.push argnode

  args = args.reverse

  nnode = SendNode.new(curnode, func, args, op_flag, seqno)
  nnode.current_exception_table = context.current_exception_table
  nnode.debug_info = context.debug_info
  func.parent = nnode
  context.expstack.push nnode

  context
end

#visit_invokesuper(code, ins, context) ⇒ Object



809
810
# File 'lib/ytljit/vm_trans.rb', line 809

def visit_invokesuper(code, ins, context)
end

#visit_jump(code, ins, context) ⇒ Object



911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
# File 'lib/ytljit/vm_trans.rb', line 911

def visit_jump(code, ins, context)
  curnode = context.current_node
  nllab = get_vmnode_from_label(context, ins[1])

  jpnode = JumpNode.new(curnode, nllab) 
  jpnode.debug_info = context.debug_info
  jpnode.body = nllab

  val = context.expstack.pop
  nllab.come_from[jpnode] = val

  curnode.body = jpnode
  context.current_node = jpnode
  context.not_reached_pos = true
end

#visit_leave(code, ins, context) ⇒ Object



857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
# File 'lib/ytljit/vm_trans.rb', line 857

def visit_leave(code, ins, context)
  curnode = nil
  vnode = nil

  if context.top_nodes.last.name == :initialize then
    # This is necessary. So it decides type of new method
    visit_pop(code, ins, context)
    curnode = context.current_node 
    vnode = SelfRefNode.new(curnode)
  else
    curnode = context.current_node 
    vnode = context.expstack.pop
  end

  if vnode then
    vnode.debug_info = context.debug_info
  else
    vnode = LiteralNode.new(curnode, nil)
  end
  srnode = SetResultNode.new(curnode, vnode)
  srnode.debug_info = context.debug_info
  curnode.body = srnode

  context.current_node = srnode

  case code.header['type']
  when :method
    nnode = MethodEndNode.new(srnode)
  when :block
    nnode = BlockEndNode.new(srnode)
  when :class
    nnode = ClassEndNode.new(srnode)
  when :top
    nnode = ClassEndNode.new(srnode)
  else
    raise "unkown type #{code.header['type']}"
  end
  nnode.debug_info = context.debug_info

  context.top_nodes.last.end_nodes.push nnode
  srnode.body = nnode
  context.current_node = nnode
  context.not_reached_pos = true
end

#visit_newarray(code, ins, context) ⇒ Object



529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
# File 'lib/ytljit/vm_trans.rb', line 529

def visit_newarray(code, ins, context)
  curnode = context.current_node
  func = FixArgCApiNode.new(curnode, "rb_ary_new3", 
                            [:int, :VALUE, :"..."])
  argnum = ins[1]
  argnumnode = LiteralNode.new(nil, argnum)
  args = []
  argnum.times do
    argele = context.expstack.pop
    args.push argele
  end
  args.push argnumnode
  args = args.reverse
  nnode = gen_arg_node(context, RetArraySendNode, func, args)
  context.expstack.push nnode
end

#visit_newhash(code, ins, context) ⇒ Object

expandarray concatarray splatarray checkincludearray



557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
# File 'lib/ytljit/vm_trans.rb', line 557

def visit_newhash(code, ins, context)
  curnode= context.current_node
  argnum = ins[1]
  args = []
  while argnum > 0
    argnum = argnum - 2
    args.push context.expstack.pop
    args.push context.expstack.pop
  end
  topnode = ClassTopNode.get_class_top_node(Object)
  hcnode = ConstantRefNode.new(curnode, topnode, :Hash)
  context.expstack.push hcnode
  visit_send(code, [:send, :new, 0, nil, 0, nil], context)

  args.reverse.each_slice(2) do |key, value|
    visit_dup(code, [:dup] , context)
    context.expstack.push key
    context.expstack.push value
    visit_send(code, [:send, :[]=, 2, nil, 0, nil], context)
    visit_pop(code, [:pop] , context)
  end
end

#visit_newrange(code, ins, context) ⇒ Object



580
581
582
583
584
# File 'lib/ytljit/vm_trans.rb', line 580

def visit_newrange(code, ins, context)
  exclflag = LiteralNode.new(nil, ins[1] != 0)
  context.expstack.push exclflag
  newinst_to_sendnode(3, Range, code, ins, context)
end

#visit_nop(code, ins, context) ⇒ Object



297
298
# File 'lib/ytljit/vm_trans.rb', line 297

def visit_nop(code, ins, context)
end

#visit_pop(code, ins, context) ⇒ Object



586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
# File 'lib/ytljit/vm_trans.rb', line 586

def visit_pop(code, ins, context)
  node = context.expstack.pop
  if node == nil then
    # Maybe push instruction deleted by optimize
    node = LiteralNode.new(nil, nil)
  end

  curnode = context.current_node
  node.parent = curnode
  curnode.body = node
  if node.is_a?(HaveChildlenMixin) then
    context.current_node = node
  end

  context
end

#visit_putiseq(code, ins, context) ⇒ Object



450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
# File 'lib/ytljit/vm_trans.rb', line 450

def visit_putiseq(code, ins, context)
  body = VMLib::InstSeqTree.new(code, ins[1])
  curnode = context.current_node
  ncontext = YARVContext.new(context)

  case body.header['type']
  when :block
    mtopnode = BlockTopNode.new(curnode)
  when :method
    mtopnode = MethodTopNode.new(curnode, body.header['name'].to_sym)
  when :class
    mtopnode = ClassTopNode.new(curnode, Object, body.header['name'].to_sym)
  when :top
    raise "Maybe bug not appear top block."
  end
  mtopnode.debug_info = context.debug_info
  ncontext.current_node = mtopnode
  ncontext.top_nodes.push mtopnode

  ncontext.current_file_name = context.current_file_name
  ncontext.current_class_node = context.current_class_node
  mname = context.expstack.last
  ncontext.current_method_node = mname

  tr = self.class.new([body])
  tr.translate(ncontext)
  context.macro_method = ncontext.macro_method
  context.expstack.push mtopnode
end

#visit_putnil(code, ins, context) ⇒ Object



427
428
429
430
431
# File 'lib/ytljit/vm_trans.rb', line 427

def visit_putnil(code, ins, context)
  nnode = LiteralNode.new(nil, nil)
  nnode.debug_info = context.debug_info
  context.expstack.push nnode
end

#visit_putobject(code, ins, context) ⇒ Object



440
441
442
443
444
# File 'lib/ytljit/vm_trans.rb', line 440

def visit_putobject(code, ins, context)
  nnode = LiteralNode.new(nil, ins[1])
  nnode.debug_info = context.debug_info
  context.expstack.push nnode
end

#visit_putself(code, ins, context) ⇒ Object



433
434
435
436
437
438
# File 'lib/ytljit/vm_trans.rb', line 433

def visit_putself(code, ins, context)
  curnode = context.current_node
  nnode = SelfRefNode.new(curnode)
  nnode.debug_info = context.debug_info
  context.expstack.push nnode
end

#visit_putspecialobject(code, ins, context) ⇒ Object



446
447
448
# File 'lib/ytljit/vm_trans.rb', line 446

def visit_putspecialobject(code, ins, context)
  context.expstack.push SpecialObjectNode.new(nil, ins[1])
end

#visit_putstring(code, ins, context) ⇒ Object



480
481
482
483
484
# File 'lib/ytljit/vm_trans.rb', line 480

def visit_putstring(code, ins, context)
  nnode = LiteralNode.new(nil, ins[1])
  nnode.debug_info = context.debug_info
  context.expstack.push nnode
end

#visit_send(code, ins, context) ⇒ Object



726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
# File 'lib/ytljit/vm_trans.rb', line 726

def visit_send(code, ins, context)
  curnode = context.current_node
  numarg = ins[2]
  blk_iseq = ins[3]
  op_flag = ins[4]
  seqno = ins[5]

  # regular arguments
  arg = []
  numarg.times do |i|
    argele = context.expstack.pop
    arg.push argele
  end
  
  # self
  slf = context.expstack.pop
  if (op_flag & (0b11 << 3)) != 0 and # fcall, vcall
      slf.is_a?(LiteralNode) and 
      slf.value == nil and 
      context.current_class_node.name != :top then
    slf = SelfRefNode.new(curnode)
  end
  arg.push slf

  # block
  if blk_iseq then
    body = VMLib::InstSeqTree.new(code, blk_iseq)
    ncontext = YARVContext.new(context)
    ncontext.current_file_name = context.current_file_name
    ncontext.current_class_node = context.current_class_node
    ncontext.current_method_node = context.current_method_node
    btn = ncontext.current_node = BlockTopNode.new(curnode)
    ncontext.top_nodes.push btn

    tr = self.class.new([body])
    tr.translate(ncontext)
    btn.debug_info = context.debug_info
    context.macro_method = ncontext.macro_method

    arg.push btn # block
  else
    argnode = LiteralNode.new(curnode, nil)
    argnode.debug_info = context.debug_info
    arg.push argnode      # block(dymmy)
  end

  # perv env
  argnode = LiteralNode.new(curnode, nil)
  argnode.debug_info = context.debug_info
  arg.push argnode

  arg = arg.reverse

  func = MethodSelectNode.new(curnode, ins[1])
  sn = SendNode.macro_expand(context, func, arg, op_flag, seqno)
  if sn == nil then
    sn = SendNode.make_send_node(curnode, func, arg, op_flag, seqno)
    sn.current_exception_table = context.current_exception_table
    if sn.is_a?(SendEvalNode) then
      if context.macro_method == nil then
        context.macro_method = true
      end
    end
    
    sn.debug_info = context.debug_info
    func.set_reciever(sn)
    context.expstack.push sn
  else
    # macro(including eval method). execute in compile time and
    # compile eval strings.
    val, evalstr = sn
    evalstr = evalstr.join("\n")
    is = RubyVM::InstructionSequence.compile(
            evalstr, "macro #{ins[1]}", "", 0, YTL::ISEQ_OPTS).to_a
    ncode = VMLib::InstSeqTree.new(code, is)
    ncode.body.pop        # Chop leave instruction
    translate_main(ncode, context)
    #          context.expstack.push val
  end

  context
end

#visit_setconstant(code, ins, context) ⇒ Object



398
399
400
401
402
403
404
405
406
407
# File 'lib/ytljit/vm_trans.rb', line 398

def visit_setconstant(code, ins, context)
  klass = get_self_object(context)
  value = context.expstack.pop
  name = ins[1]
  curnode = context.current_node
  node = ConstantAssignNode.new(curnode, klass, name, value)
  node.debug_info = context.debug_info
  curnode.body = node
  context.current_node = node
end

#visit_setdynamic(code, ins, context) ⇒ Object



332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'lib/ytljit/vm_trans.rb', line 332

def visit_setdynamic(code, ins, context)
  dep = ins[2]
  curcode = code
  dep.times do
    curcode = curcode.parent
  end
  val = context.expstack.pop
  curnode = context.current_node
  offset = curcode.header['misc'][:local_size] + 3 - ins[1]
  node = LocalAssignNode.new(curnode, offset, dep, val)
  node.debug_info = context.debug_info
  if context.expstack[-1] == val then
    varref = LocalVarRefNode.new(context.current_node, offset, dep)
    varref.debug_info = context.debug_info
    context.expstack[-1] = varref
  end
  curnode.body = node
  context.current_node = node
end

#visit_setglobal(code, ins, context) ⇒ Object



417
418
419
420
421
422
423
424
425
# File 'lib/ytljit/vm_trans.rb', line 417

def visit_setglobal(code, ins, context)
  value = context.expstack.pop
  name = ins[1]
  curnode = context.current_node
  node = GlobalVarAssignNode.new(curnode, name, value)
  node.debug_info = context.debug_info
  curnode.body = node
  context.current_node = node
end

#visit_setlocal(code, ins, context) ⇒ Object



305
306
307
308
# File 'lib/ytljit/vm_trans.rb', line 305

def visit_setlocal(code, ins, context)
  dep = depth_of_block(code)
  visit_setdynamic(code, [:setlocal, ins[1], dep], context)
end

#visit_setn(code, ins, context) ⇒ Object



642
643
644
645
646
647
648
# File 'lib/ytljit/vm_trans.rb', line 642

def visit_setn(code, ins, context)
  n = ins[1] + 1
  orgnode = context.expstack.last
  nnode = MultiplexNode.new(orgnode)
  context.expstack[-n] = nnode
  context.expstack[-1] = nnode
end

#visit_swap(code, ins, context) ⇒ Object



627
628
629
630
631
632
# File 'lib/ytljit/vm_trans.rb', line 627

def visit_swap(code, ins, context)
  val0 = context.expstack.pop
  val1 = context.expstack.pop
  context.expstack.push val0
  context.expstack.push val1
end

#visit_symbol(code, ins, context) ⇒ Object



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/ytljit/vm_trans.rb', line 191

def visit_symbol(code, ins, context)
  context.current_local_label = ins
  context.local_label_list.push ins

  curnode = context.current_node
  nllab = get_vmnode_from_label(context, ins)
  
  if !(curnode.is_a?(JumpNode) or 
       curnode.is_a?(MethodEndNode) or
       curnode.is_a?(ThrowNode)) then
    jmpnode = JumpNode.new(curnode, nllab)
    jmpnode.debug_info = context.debug_info
    nllab.parent = jmpnode

    val = context.expstack.pop
    nllab.come_from[jmpnode] = val

    curnode.body = jmpnode
    jmpnode.body = nllab
    context.expstack.push nllab.value_node
  end

  context.current_node = nllab
end

#visit_throw(code, ins, context) ⇒ Object



902
903
904
905
906
907
908
909
# File 'lib/ytljit/vm_trans.rb', line 902

def visit_throw(code, ins, context)
  curnode = context.current_node
  exceptobj = context.expstack.pop

  thnode = ThrowNode.new(curnode, ins[1], exceptobj)
  curnode.body = thnode
  context.current_node = thnode
end

#visit_topn(code, ins, context) ⇒ Object

reput



636
637
638
639
640
# File 'lib/ytljit/vm_trans.rb', line 636

def visit_topn(code, ins, context)
  raise
  n = ins[1] + 1
  context.expstack.push context.expstack[-n]
end

#visit_tostring(code, ins, context) ⇒ Object



502
503
504
505
506
507
508
509
510
# File 'lib/ytljit/vm_trans.rb', line 502

def visit_tostring(code, ins, context)
  curnode = context.current_node
  func = FixArgCApiNode.new(curnode, "rb_obj_as_string", [:VALUE])
  args = []
  argele = context.expstack.pop
  args.push argele
  nnode = gen_arg_node(context, RetStringSendNode, func, args)
  context.expstack.push nnode
end

#visit_trace(code, ins, context) ⇒ Object

adjuststack defined



653
654
# File 'lib/ytljit/vm_trans.rb', line 653

def visit_trace(code, ins, context)
end