Class: YTLJit::VM::Node::LiteralNode

Inherits:
BaseNode show all
Includes:
NodeUtil, TypeListWithoutSignature
Defined in:
lib/ytljit/vm.rb

Overview

Literal

Constant Summary

Constants inherited from BaseNode

BaseNode::ESCAPE_LEVEL

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 collapse

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 included from TypeListWithoutSignature

#add_type, #set_type_list, #type_list, #type_list_initvar

Methods included from NodeUtil

#search_class_top, #search_end, #search_frame_info, #search_top

Methods inherited from BaseNode

#add_element_node, #add_element_node_backward, #add_element_node_backward_aux, #collect_info, #decide_type, #decide_type_core, #decide_type_once, #gen_type_inference_proc, #inference_type, #marge_element_node, #marge_type, #same_type, #search_valid_signature, #set_escape_node, #set_escape_node_backward, #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, val) ⇒ LiteralNode

Returns a new instance of LiteralNode.



2697
2698
2699
2700
2701
# File 'lib/ytljit/vm.rb', line 2697

def initialize(parent, val)
  super(parent)
  @value = val
  @type = RubyType::BaseType.from_object(val)
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



2703
2704
2705
# File 'lib/ytljit/vm.rb', line 2703

def value
  @value
end

Instance Method Details

#code_space_from_signatureObject

Dummy for pass as block (nil)



2706
2707
2708
# File 'lib/ytljit/vm.rb', line 2706

def code_space_from_signature
  {}
end

#collect_candidate_type(context) ⇒ Object



2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
# File 'lib/ytljit/vm.rb', line 2710

def collect_candidate_type(context)
  sig = context.to_signature
  if @type == nil then
    @type = RubyType::BaseType.from_object(@value) 
  end

  case @value
  when Array
    add_type(sig, @type)
    @value.each do |ele|
      etype = RubyType::BaseType.from_object(ele)
      @element_node_list[0][2].add_type(sig, etype)
    end

  when Hash
    add_type(sig, @type)
    @value.each do |key, value|
      vtype = RubyType::BaseType.from_object(value)
      @element_node_list[0][2].add_type(sig, vtype)
    end

  when Range
    @type = @type.to_box
    add_type(sig, @type)
    if @type.args == nil then
      @type.args = []
      ele = @value.first
      fstnode = LiteralNode.new(self, ele)
      context = fstnode.collect_candidate_type(context)
      @type.args.push fstnode
      ele = @value.last
      sndnode = LiteralNode.new(self, ele)
      @type.args.push sndnode
      context = sndnode.collect_candidate_type(context)
      ele = @value.exclude_end?
      exclnode = LiteralNode.new(self, ele)
      @type.args.push exclnode
      context = exclnode.collect_candidate_type(context)
      add_element_node(@type, sig, fstnode, [0], context)
      add_element_node(@type, sig, sndnode, [1], context)
    end
  else
    add_type(sig, @type)
  end

  context
end

#compile(context) ⇒ Object



2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
# File 'lib/ytljit/vm.rb', line 2762

def compile(context)
  context = super(context)

  decide_type_once(context.to_signature)
  case @value
  when Fixnum
    val = @value
    if @type.boxed then
      val = val.boxing
    end
    context.ret_node = self
    context.ret_reg = OpImmidiateMachineWord.new(val)

  when Float
    val = @value
    if @type.boxed then
      val = val.boxing
      context.ret_reg = OpImmidiateMachineWord.new(val)
    else
      offm4 = OpIndirect.new(SPR, -AsmType::DOUBLE.size)
      asm = context.assembler
      asm.with_retry do
        asm.mov64(offm4, val.unboxing)
        asm.movsd(XMM0, offm4)
      end
      context.ret_reg = XMM0
    end
    context.ret_node = self
    context.set_reg_content(context.ret_reg, self)

  else
    if @var_value == nil then
      add = lambda { @value.address }
      @var_value = OpVarImmidiateAddress.new(add)
    end

    context.ret_node = self
    context.ret_reg = @var_value
    context = @type.gen_copy(context)
    context.set_reg_content(context.ret_reg, self)
  end

  context
end

#compile_get_constant(context) ⇒ Object



2758
2759
2760
# File 'lib/ytljit/vm.rb', line 2758

def compile_get_constant(context)
  compile(context)
end

#get_constant_valueObject



2807
2808
2809
# File 'lib/ytljit/vm.rb', line 2807

def get_constant_value
  [@value]
end

#type=(val) ⇒ Object



2811
2812
2813
# File 'lib/ytljit/vm.rb', line 2811

def type=(val)
  val
end