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

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

Overview

Literal

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 collapse

Attributes inherited from BaseNode

#code_space, #element_node_list, #id, #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 inherited from BaseNode

#add_element_node, #collect_info, #decide_type, #decide_type_core, #decide_type_once, #gen_type_inference_proc, #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, val) ⇒ LiteralNode

Returns a new instance of LiteralNode.



1690
1691
1692
1693
1694
# File 'lib/ytljit/vm.rb', line 1690

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.



1696
1697
1698
# File 'lib/ytljit/vm.rb', line 1696

def value
  @value
end

Instance Method Details

#collect_candidate_type(context) ⇒ Object



1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
# File 'lib/ytljit/vm.rb', line 1698

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

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

#compile(context) ⇒ Object



1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
# File 'lib/ytljit/vm.rb', line 1716

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

  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)
  end

  context
end

#get_constant_valueObject



1759
1760
1761
# File 'lib/ytljit/vm.rb', line 1759

def get_constant_value
  [@value]
end