Class: YTLJit::VM::Node::MethodSelectNode

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

Overview

Method name

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 inherited from BaseNode

#add_element_node, #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, val) ⇒ MethodSelectNode

Returns a new instance of MethodSelectNode.



1875
1876
1877
1878
1879
1880
1881
1882
# File 'lib/ytljit/vm.rb', line 1875

def initialize(parent, val)
  super(parent)
  @name = val
  @calling_convention = :unkown
  @reciever = nil
  @send_node = nil
  @ruby_reciever = nil
end

Instance Attribute Details

#calling_convention(context) ⇒ Object (readonly)

Returns the value of attribute calling_convention.



1894
1895
1896
# File 'lib/ytljit/vm.rb', line 1894

def calling_convention
  @calling_convention
end

#nameObject (readonly)

Returns the value of attribute name.



1893
1894
1895
# File 'lib/ytljit/vm.rb', line 1893

def name
  @name
end

#recieverObject

Returns the value of attribute reciever.



1895
1896
1897
# File 'lib/ytljit/vm.rb', line 1895

def reciever
  @reciever
end

Instance Method Details

#collect_candidate_type(context) ⇒ Object



1897
1898
1899
# File 'lib/ytljit/vm.rb', line 1897

def collect_candidate_type(context)
  context
end

#compile(context) ⇒ Object



1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
# File 'lib/ytljit/vm.rb', line 1966

def compile(context)
  context = super(context)
  if @send_node.is_fcall or @send_node.is_vcall then
    slfop = @parent.frame_info.offset_arg(2, BPR)
    asm = context.assembler
    asm.with_retry do
      asm.mov(TMPR3, slfop)
    end
    context.ret_reg2 = TMPR3
    mtop = @reciever.search_method_with_super(@name)[0]
    if mtop then
      sig = @parent.signature(context)
      cs = mtop.find_cs_by_signature(sig)
      context.ret_reg = cs.var_base_address
    else
      if @reciever.klass_object then
        addr = lambda {
          @reciever.klass_object.method_address_of(@name)
        }
        if addr.call then
          context.ret_reg = OpVarMemAddress.new(addr)
          context.code_space.refer_operands.push context.ret_reg 
          context.ret_node = self
        else
          raise "Unkown method - #{@name}"
          context.ret_reg = OpImmidiateAddress.new(0)
          context.ret_node = self
        end
      else
        raise "foo"
      end
    end
  else
    context = @reciever.compile(context)
    context.ret_node.decide_type_once(context.to_signature)
    rtype = context.ret_node.type
    if @calling_convention != :ytl then
      context = rtype.gen_boxing(context)
    end
    recval = context.ret_reg
    knode = ClassTopNode.get_class_top_node(rtype.ruby_type)
    mtop = nil

    if rtype.is_a?(RubyType::DefaultType0) then
      # Can't type inference. Dynamic method search
      mnval = @name.address
      objclass = OpMemAddress.new(address_of("rb_obj_class"))
      addr = address_of("ytl_method_address_of_raw")
      meaddrof = OpMemAddress.new(addr)

      context.start_using_reg(TMPR2)
      context.start_using_reg(FUNC_ARG[0])
      context.start_using_reg(FUNC_ARG[1])
      
      asm = context.assembler
      asm.with_retry do
        asm.push(recval)
        asm.mov(FUNC_ARG[0], recval)
        asm.call_with_arg(objclass, 1)
        asm.mov(FUNC_ARG[0], RETR)
        asm.mov(FUNC_ARG[1], mnval)
        asm.call_with_arg(meaddrof, 2)
        asm.mov(TMPR2, RETR)
        asm.pop(TMPR3)
      end
      context.ret_reg2 = TMPR3
      
      context.end_using_reg(FUNC_ARG[1])
      context.end_using_reg(FUNC_ARG[0])
      
      context.ret_node = self
      context.set_reg_content(RETR, self)
      context.set_reg_content(TMPR2, self)
      context.set_reg_content(TMPR3, @reciever)
      context.ret_reg = TMPR2

    elsif knode and mtop = knode.search_method_with_super(@name)[0] then
      asm = context.assembler
      if !rtype.boxed and rtype.ruby_type == Float then
        if recval != XMM0 then
          asm.with_retry do
            asm.mov(XMM0, recval)
          end
        end
        context.ret_reg2 = XMM0
      else
        asm.with_retry do
          asm.mov(TMPR3, recval)
        end
        context.ret_reg2 = TMPR3
      end

      sig = @parent.signature(context)
      cs = mtop.find_cs_by_signature(sig)
      context.ret_reg = cs.var_base_address

    else
      # regident type 

      asm = context.assembler
      if !rtype.boxed and rtype.ruby_type == Float then
        if recval != XMM0 then
          asm.with_retry do
            asm.mov(XMM0, recval)
          end
        end
        context.ret_reg2 = XMM0
      else
        asm.with_retry do
          asm.mov(TMPR3, recval)
        end
        context.ret_reg2 = TMPR3
      end

      addr = lambda {
        rrec = @ruby_reciever
        if rrec.is_a?(ClassClassWrapper) then
          rrec = rrec.value
        end
        if rrec.class == Module then
          name = @name
          rrec.send(:method_address_of, name)
        else
          rrec.method_address_of(@name)
        end
      }
      if addr.call then
        context.ret_reg = OpVarMemAddress.new(addr)
        context.code_space.refer_operands.push context.ret_reg 
        context.ret_node = self
      else
        raise "Unkown method - #{@name}"
        context.ret_reg = OpImmidiateAddress.new(0)
        context.ret_node = self
      end
    end
  end
  context
end

#method_top_node(ctop, slf) ⇒ Object



1901
1902
1903
1904
1905
1906
1907
# File 'lib/ytljit/vm.rb', line 1901

def method_top_node(ctop, slf)
  if slf then
    ctop.search_method_with_super(@name, slf.ruby_type)[0]
  else
    ctop.search_method_with_super(@name)[0]
  end
end

#set_reciever(sendnode) ⇒ Object



1884
1885
1886
1887
1888
1889
1890
1891
# File 'lib/ytljit/vm.rb', line 1884

def set_reciever(sendnode)
  @send_node = sendnode
  if sendnode.is_fcall or sendnode.is_vcall then
    @reciever = @parent.class_top
  else
    @reciever = sendnode.arguments[2]
  end
end