Class: YTLJit::VM::Node::SendNewNode

Inherits:
SendNode show all
Defined in:
lib/ytljit/vm_sendnode.rb

Constant Summary

Constants included from AbsArch

AbsArch::AL, AbsArch::BL, AbsArch::CL, AbsArch::DL, AbsArch::FUNC_ARG, AbsArch::FUNC_ARG_YTL, AbsArch::FUNC_FLOAT_ARG, AbsArch::FUNC_FLOAT_ARG_YTL, AbsArch::INDIRECT_BPR, AbsArch::INDIRECT_RETR, AbsArch::INDIRECT_SPR, AbsArch::INDIRECT_TMPR, AbsArch::INDIRECT_TMPR2, AbsArch::INDIRECT_TMPR3

Constants included from SSE

SSE::XMM0, SSE::XMM1, SSE::XMM2, SSE::XMM3, SSE::XMM4, SSE::XMM5, SSE::XMM6, SSE::XMM7

Instance Attribute Summary

Attributes inherited from SendNode

#arguments, #class_top, #frame_info, #func, #modified_instance_var, #modified_local_var, #next_node, #opt_flag, #result_cache, #seq_no

Attributes included from HaveChildlenMixin

#body

Attributes inherited from BaseNode

#code_space, #debug_info, #element_node_list, #id, #is_escape, #parent, #ti_observee, #ti_observer, #type

Instance Method Summary collapse

Methods inherited from SendNode

add_special_send_node, #check_signature_changed, #collect_candidate_type, #collect_info, #fill_result_cache, #get_constant_value, get_macro_tab, #get_send_method_node, make_send_node, node, #search_signature

Methods included from SendUtil

#compile_c_fixarg, #compile_c_fixarg_raw, #compile_c_vararg, #compile_ytl, #gen_eval_self, #signature

Methods included from NodeUtil

#search_class_top, #search_end, #search_frame_info, #search_top

Methods included from SendNodeCodeGen

#gen_make_argv

Methods included from CommonCodeGen

#dump_context, #gen_alloca, #gen_call

Methods included from OptFlagOp

#is_args_blockarg, #is_args_splat, #is_fcall, #is_opt_send, #is_super, #is_tailcall, #is_tailrecursion, #is_vcall

Methods inherited from BaseNode

#add_element_node, #collect_candidate_type, #collect_info, #decide_type, #decide_type_core, #decide_type_once, #gen_type_inference_proc, #get_constant_value, #inference_type, #merge_type, #same_type, #ti_add_observer, #ti_changed, #ti_del_link, #ti_reset, #ti_update

Methods included from TypeListWithSignature

#add_type, #set_type_list, #type_list, #type_list_initvar

Methods included from Inspect

#inspect_by_graph

Constructor Details

#initialize(parent, func, arguments, op_flag, seqno) ⇒ SendNewNode

Returns a new instance of SendNewNode.



496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
# File 'lib/ytljit/vm_sendnode.rb', line 496

def initialize(parent, func, arguments, op_flag, seqno)
  super
  allocfunc = MethodSelectNode.new(self, :allocate)
  alloc = SendNode.make_send_node(self, allocfunc, 
                                  arguments[0, 3], 0, seqno)
  allocfunc.set_reciever(alloc)
  initfunc = MethodSelectNode.new(self, :initialize)
  initarg = arguments.dup
  initarg[2] = alloc
  init = SendNode.make_send_node(self, initfunc, 
                                 initarg, op_flag, seqno)
  initfunc.set_reciever(init)
  alloc.parent = init
  @initmethod = init
  @allocmethod = alloc
end

Instance Method Details

#collect_candidate_type_regident(context, slf) ⇒ Object



528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
# File 'lib/ytljit/vm_sendnode.rb', line 528

def collect_candidate_type_regident(context, slf)
  slfnode = @arguments[2]

  if slf.ruby_type.is_a?(Class) then
    case slfnode
    when ConstantRefNode
      context = @initmethod.collect_candidate_type(context)
      clstop = slfnode.value_node
      tt = nil
      sig = context.to_signature
      case clstop
      when ClassTopNode
        tt = RubyType::BaseType.from_ruby_class(clstop.klass_object)
        add_type(sig, tt)
        
      when LiteralNode
        tt = RubyType::BaseType.from_ruby_class(clstop.value)
        add_type(sig, tt)

      else
        raise "Unkown node type in constant #{slfnode.value_node.class}"
      end

      # set element type
      if tt.ruby_type == Range then
        tt.args = @arguments[3..-1]
        add_element_node(sig, @arguments[3], [0], context)
      end

      if tt.ruby_type == Array then
        @arguments[3..-1].each_with_index do |anode, idx|
          add_element_node(sig, anode, [idx - 3], context)
        end
      end
    else
      raise "Unkonwn node type #{@arguments[2].class} "
    end
  end
  context
end

#compile(context) ⇒ Object



569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
# File 'lib/ytljit/vm_sendnode.rb', line 569

def compile(context)
  @arguments[2].decide_type_once(context.to_signature)
  rtype = @arguments[2].type
  rrtype = rtype.ruby_type
  if rrtype.is_a?(Class) then
    if !@is_escape and rrtype.to_s == '#<Class:Range>' then
      context = gen_alloca(context, 3)
      asm = context.assembler
      breg = context.ret_reg

      off = 0
      [3, 4, 5].each do |no|
        context = @arguments[no].compile(context)
        dst = OpIndirect.new(breg, off)
        asm.with_retry do
          if context.ret_reg.is_a?(OpRegistor) then
            asm.mov(dst, context.ret_reg)
          else
            asm.mov(TMPR, context.ret_reg)
            asm.mov(dst, TMPR)
          end
        end
        off = off + AsmType::MACHINE_WORD.size
      end
      
      context.ret_reg = breg
      context.ret_node = self
      context

    elsif @initmethod.func.calling_convention(context) then
      context = @initmethod.compile(context)

    else
      # initialize method not defined
      context = @allocmethod.compile(context)
    end
    @body.compile(context)
  else
    super
  end
end

#debug_info=(val) ⇒ Object



513
514
515
516
517
# File 'lib/ytljit/vm_sendnode.rb', line 513

def debug_info=(val)
  @initmethod.debug_info = val
  @allocmethod.debug_info = val
  @debug_info = val
end

#traverse_childlen {|@func| ... } ⇒ Object

Yields:



519
520
521
522
523
524
525
526
# File 'lib/ytljit/vm_sendnode.rb', line 519

def traverse_childlen
  @arguments.each do |arg|
    yield arg
  end
  yield @func
  yield @initmethod
  yield @body
end