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



298
299
300
301
302
303
304
305
306
307
# File 'lib/ytljit/vm_trans.rb', line 298

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



188
189
190
191
192
193
194
# File 'lib/ytljit/vm_trans.rb', line 188

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



399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# File 'lib/ytljit/vm_trans.rb', line 399

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



175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/ytljit/vm_trans.rb', line 175

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



550
551
552
553
554
555
556
557
558
559
560
561
562
563
# File 'lib/ytljit/vm_trans.rb', line 550

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



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/ytljit/vm_trans.rb', line 273

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
  top.send_nodes_with_block = context.send_nodes_with_block
  if top.class == MethodTopNode then
    SendNode.get_macro_tab[top.name] ||= {}
    if context.macro_method then
      maccontext = ToRubyContext.new
      code = top.to_ruby(maccontext).ret_code.last
      #            print code
      proc = eval("lambda" + code)
      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
      SendNode.get_macro_tab[top.name][:last] = top
    end
  end
end

#visit_block_start(code, ins, context) ⇒ Object



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
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/ytljit/vm_trans.rb', line 221

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)
  # Get code space each optional argument label
  cnode.opt_label.each do |lab|
    cnode.opt_label_node.push get_vmnode_from_label(context, lab)
  end

  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



971
972
973
974
975
976
977
978
979
980
981
982
983
# File 'lib/ytljit/vm_trans.rb', line 971

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] = context.expstack.last

  curnode.body = node
  context.current_node = node
end

#visit_branchunless(code, ins, context) ⇒ Object



985
986
987
988
989
990
991
992
993
994
995
996
997
# File 'lib/ytljit/vm_trans.rb', line 985

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] = context.expstack.last

  curnode.body = node
  context.current_node = node
end

#visit_concatstrings(code, ins, context) ⇒ Object



522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
# File 'lib/ytljit/vm_trans.rb', line 522

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



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
725
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
# File 'lib/ytljit/vm_trans.rb', line 692

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, 3
        klassobj = Class.new(supklass)
        
      when 2, 5
        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



639
640
641
642
643
644
# File 'lib/ytljit/vm_trans.rb', line 639

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

#visit_duparray(code, ins, context) ⇒ Object



582
583
584
585
586
# File 'lib/ytljit/vm_trans.rb', line 582

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



646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
# File 'lib/ytljit/vm_trans.rb', line 646

def visit_dupn(code, ins, context)
  res = []
  n = ins[1]
  n.times do
    orgnode = context.expstack.pop
    nnode = MultiplexNode.new(orgnode.parent, 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



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

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



325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'lib/ytljit/vm_trans.rb', line 325

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



445
446
447
448
449
450
451
# File 'lib/ytljit/vm_trans.rb', line 445

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

#visit_getlocal(code, ins, context) ⇒ Object



312
313
314
315
# File 'lib/ytljit/vm_trans.rb', line 312

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



852
853
854
855
856
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
# File 'lib/ytljit/vm_trans.rb', line 852

def visit_invokeblock(code, ins, context)
  curnode = context.current_node
  func = YieldNode.new(curnode)
  func.debug_info = context.debug_info
  func.depth = depth_of_block(code)
  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



849
850
# File 'lib/ytljit/vm_trans.rb', line 849

def visit_invokesuper(code, ins, context)
end

#visit_jump(code, ins, context) ⇒ Object



955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
# File 'lib/ytljit/vm_trans.rb', line 955

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



898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
# File 'lib/ytljit/vm_trans.rb', line 898

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
    vnode = context.expstack.pop
    curnode = context.current_node 
    nnode = SetResultNode.new(curnode, vnode)
    curnode.body = nnode
    curnode =nnode
    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



565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
# File 'lib/ytljit/vm_trans.rb', line 565

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



593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
# File 'lib/ytljit/vm_trans.rb', line 593

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



616
617
618
619
620
# File 'lib/ytljit/vm_trans.rb', line 616

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



309
310
# File 'lib/ytljit/vm_trans.rb', line 309

def visit_nop(code, ins, context)
end

#visit_pop(code, ins, context) ⇒ Object



622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
# File 'lib/ytljit/vm_trans.rb', line 622

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



486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
# File 'lib/ytljit/vm_trans.rb', line 486

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



463
464
465
466
467
# File 'lib/ytljit/vm_trans.rb', line 463

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



476
477
478
479
480
# File 'lib/ytljit/vm_trans.rb', line 476

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



469
470
471
472
473
474
# File 'lib/ytljit/vm_trans.rb', line 469

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



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

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

#visit_putstring(code, ins, context) ⇒ Object



516
517
518
519
520
# File 'lib/ytljit/vm_trans.rb', line 516

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



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
808
809
810
811
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
# File 'lib/ytljit/vm_trans.rb', line 762

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 or true) then
    slf = SelfRefNode.new(curnode)
    slf.debug_info = context.debug_info
  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
    if blk_iseq then
      context.send_nodes_with_block.push sn
    end
  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]}", "", 1, 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



434
435
436
437
438
439
440
441
442
443
# File 'lib/ytljit/vm_trans.rb', line 434

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



344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
# File 'lib/ytljit/vm_trans.rb', line 344

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]

  prev_var = nil
  context.expstack.each_with_index do |ele, i|
    if ele.is_a?(LocalVarRefNode) and 
        ele.offset == offset and ele.depth == dep then
      prev_var ||= MultiplexNode.new(curnode, ele)
      context.expstack[i] = prev_var
    elsif ele.is_a?(SendNode) then
      ele.traverse_node do |arg, args, j|
        if arg.is_a?(LocalVarRefNode) and 
            arg.offset == offset and arg.depth == dep then
          prev_var ||= MultiplexNode.new(ele, arg)
          args[j] = prev_var
        end
      end
    end
  end

  if prev_var then
    mnode = MultiplexHolderNode.new(curnode, prev_var)
    curnode.body = mnode
    curnode = mnode
  end

  node = LocalAssignNode.new(curnode, offset, dep, val)
  node.debug_info = context.debug_info
  if context.expstack[-1] == val then
    varref = LocalVarRefNode.new(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



453
454
455
456
457
458
459
460
461
# File 'lib/ytljit/vm_trans.rb', line 453

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



317
318
319
320
# File 'lib/ytljit/vm_trans.rb', line 317

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



678
679
680
681
682
683
684
# File 'lib/ytljit/vm_trans.rb', line 678

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

#visit_swap(code, ins, context) ⇒ Object



663
664
665
666
667
668
# File 'lib/ytljit/vm_trans.rb', line 663

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



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/ytljit/vm_trans.rb', line 196

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



946
947
948
949
950
951
952
953
# File 'lib/ytljit/vm_trans.rb', line 946

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



672
673
674
675
676
# File 'lib/ytljit/vm_trans.rb', line 672

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

#visit_tostring(code, ins, context) ⇒ Object



538
539
540
541
542
543
544
545
546
# File 'lib/ytljit/vm_trans.rb', line 538

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



689
690
# File 'lib/ytljit/vm_trans.rb', line 689

def visit_trace(code, ins, context)
end