<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -227,7 +227,8 @@ module LLVMUtil
     # argsize is 0(not send index) or 1(send index)
     argsize = code.blockes[ins[3][1]].header['misc'][:arg_size]
 
-    minfo = MethodDefinition::RubyMethod[blab][info[0]]
+    recklass = info[0]
+    minfo = MethodDefinition::RubyMethod[blab][recklass]
     if minfo == nil then
       minfo = MethodDefinition::RubyMethod[blab][nil]
     end
@@ -248,7 +249,8 @@ module LLVMUtil
         :yield_argtype =&gt; nil,
         :yield_rettype =&gt; nil,
       }
-      MethodDefinition::RubyMethod[blab][info[0]] = minfo
+      recklass = info[0]
+      MethodDefinition::RubyMethod[blab][recklass] = minfo
     else
       atype = minfo[:argtype][0]
       rtype = minfo[:rettype]
@@ -398,27 +400,46 @@ module SendUtil
   include LLVM
   include RubyHelpers
 
+  def extend_klass_list(type)
+    res = {}
+    klslist = [type.klass] + type.conflicted_types.keys
+    klslist.each do |kls|
+      Object.nested_const_get(kls).y2l_ancestors.each do |kls2|
+        res[kls2.to_s.to_sym] = true
+      end
+    end
+
+    res
+  end
+
   MaxSmallPolymotphicNum = 4
   def gen_method_select(rectype, lexklass, mname, is_pass2)
     mtab = MethodDefinition::RubyMethod[mname].reject {|klass, info| 
       !info.is_a?(Hash)
     }
     recklass = nil
+
+    # delete entry of method table for non-releated type
     if rectype then
       conftype = rectype.conflicted_types
-      if conftype.size &lt;= 1 then
+      conftype_ex = extend_klass_list(rectype)
+      if conftype.size == 0 then
         recklass = rectype.klass
       else
         mtab.delete_if {|klass, info| 
-          klass and conftype[klass] == nil
+          klass and conftype_ex[klass] == nil
         }
+        if mtab.size == 1 then
+          recklass = mtab.keys[0]
+        end
       end
     end
 
+    # just fit
     minfo = mtab[recklass]
     if minfo and ((!is_pass2) or minfo[:func]) then
       # recklass == nil -&gt;  functional method
-      return [minfo, minfo[:func]]
+      return [minfo, minfo[:func], recklass]
     end
 
     # inheritance search
@@ -434,15 +455,16 @@ module SendUtil
       obj.y2l_ancestors.each do |sup|
         minfo = mtab[sup.name.to_sym]
         if minfo and ((!is_pass2) or minfo[:func]) then
-          return [minfo, minfo[:func]]
+          return [minfo, minfo[:func], sup.name.to_sym]
         end
       end
       minfo = mtab[nil]
       if minfo and ((!is_pass2) or minfo[:func]) then
-        return [minfo, minfo[:func]]
+        return [minfo, minfo[:func], nil]
       end
     end
 
+    # reciver type is unkown. search from method table.
     candidatenum = mtab.size
     candidate = []
     if candidatenum &gt; 1 then
@@ -454,17 +476,20 @@ module SendUtil
         end
       }
     end
+
 #=begin    
     funcinfo = get_inline_function(recklass, lexklass, mname)
     if funcinfo then
-     return [nil, nil]
+     return [nil, nil, nil]
     end
 #=end
 
     if candidatenum == 0 then
-      return [nil, nil]
+      # No entry
+      return [nil, nil, nil]
 
     elsif candidatenum == 1 then
+      # number of elelment is 1. Use it.
       minfo = nil
       if recklass then
         minfo = mtab[recklass]
@@ -472,23 +497,26 @@ module SendUtil
         minfo = mtab.values[0]
       end
       if minfo then
-        return [minfo, minfo[:func]]
+        return [minfo, minfo[:func], recklass ? recklass : mtab.keys[0]]
       else
-        return [nil, nil]
+        return [nil, nil, nil]
       end
 
     elsif candidatenum &lt; MaxSmallPolymotphicNum then
+      # Polymorpic method call. Conflict method is few.
       # TODO : Use inline hash function generation
-      p rectype.conflicted_types.keys
+      p mtab.keys
       p candidatenum
       p rectype.inspect2
       p rectype.name
+      p rectype.line_no
       p lexklass
       p mname
       p is_pass2
       raise(&quot;Not implimented polymorphic methed call yet '#{mname}' #{lexklass}&quot;)
 
     else
+      # Polymorpic method call. Conflict method is many.
       # TODO : Use cukko-hasing and inline hash function generation
       raise('Not implimented polymorphic methed call yet')
     end
@@ -700,7 +728,7 @@ module SendUtil
           context}]
     end
     if minfo and minfo[:self] then
-      v[0].add_same_type minfo[:self]
+#      v[0].add_same_type minfo[:self]
 #      minfo[:self].add_same_type v[0]
     end
 
@@ -710,16 +738,27 @@ module SendUtil
       @type_inferece_after_traverse = lambda {
         old_tiat.call
         rectype = receiver ? receiver[0] : nil
-        minfo, func = gen_method_select(rectype, info[0], mname, false)
+        minfo, func, rec = gen_method_select(rectype, info[0], mname, false)
 
         if minfo and minfo[:self] then
+          rettype = minfo[:rettype]
+          if cact = minfo[:copy_rettype] then
+            if cact == true then
+              orgrettype = rettype
+              rettype = RubyType.new(nil)
+              orgrettype.add_same_type(rettype)
+            else
+              rectype = receiver ? receiver[0] : local_vars[2][:type]
+              rettype = cact.call(rectype, args.map{|e| e[0]})
+            end
+          end
           args.each_with_index do |pe, n|
             pe[0].add_same_type(minfo[:argtype][nargs - n - 1])
             minfo[:argtype][nargs - n - 1].add_same_value(pe[0])
             pe[0].add_extent_base minfo[:argtype][nargs - n - 1]
           end
-          v[0].add_same_type minfo[:self]
-#          minfo[:self].add_same_type v[0]
+          #          v[0].add_same_type minfo[:self]
+          #          minfo[:self].add_same_type v[0]
         end
       }  
     end
@@ -746,7 +785,7 @@ module SendUtil
 
       minfoy = MethodDefinition::RubyMethod[mname][recklass]
 
-      if minfoy and (yargt = minfoy[:yield_argtype]) then
+      if minfoy.is_a?(Hash) and (yargt = minfoy[:yield_argtype]) then
         minfob = MethodDefinition::RubyMethod[blab][recklass]
         if minfob == nil then
           rtype = RubyType.new(nil)
@@ -817,7 +856,8 @@ module SendUtil
             end
           end
           # receiver of block is parent class
-          minfo = MethodDefinition::RubyMethod[blab][info[0]]
+          recklass = info[0]
+          minfo = MethodDefinition::RubyMethod[blab][recklass]
 
           gen_get_block_ptr(info[0], minfo, b, context)
         }]
@@ -829,8 +869,9 @@ module SendUtil
   def do_function(receiver, info, ins, local_vars, args, mname, curlevel)
     recklass = receiver ? receiver[0].klass : nil
     rectype = receiver ? receiver[0] : nil
-    minfo, func = gen_method_select(rectype, info[0], mname, false)
-    if minfo then
+    isfunc = ((ins[4] &amp; 8) != 0) # true: function type, false: method type
+    minfo, func, kls = gen_method_select(rectype, info[0], mname, false)
+    if minfo and (isfunc or kls) then
       rettype = minfo[:rettype]
       if cact = minfo[:copy_rettype] then
         if cact == true then
@@ -871,7 +912,7 @@ module SendUtil
           recklass = receiver ? receiver[0].klass : nil
           minfo, func = gen_method_select(rectype, info[0], mname, true)
 
-          if !with_selfp((ins[4] &amp; 8) != 0, receiver, info[0], mname) then
+          if !with_selfp(isfunc, receiver, info[0], mname) then
             para.pop
           end
 </diff>
      <filename>lib/llvmutil.rb</filename>
    </modified>
    <modified>
      <diff>@@ -749,7 +749,8 @@ module MethodDefinition
              b.store(0.llvm, blkarea)
  
              blab = get_block_label(info[1], blk)
-             minfo = MethodDefinition::RubyMethod[blab][info[0]] 
+             recklass = info[0]
+             minfo = MethodDefinition::RubyMethod[blab][recklass] 
              context = gen_get_block_ptr(info[0], minfo, b, context)
              blkptr = context.rc
 </diff>
      <filename>lib/methoddef.rb</filename>
    </modified>
    <modified>
      <diff>@@ -433,11 +433,12 @@ class YarvTranslator&lt;YarvVisitor
 
     minfo = nil
     if info[1] then
-      minfo = MethodDefinition::RubyMethod[info[1]][info[0]]
+      recklass = info[0]
+      minfo = MethodDefinition::RubyMethod[info[1]][recklass]
       if minfo == nil then
         minfo = MethodDefinition::RubyMethod[info[1]][nil]
         if minfo then
-          MethodDefinition::RubyMethod[info[1]][info[0]] = minfo
+          MethodDefinition::RubyMethod[info[1]][recklass] = minfo
         end
       end
     end
@@ -696,14 +697,15 @@ class YarvTranslator&lt;YarvVisitor
     loop_cnt_alloca_size = @loop_cnt_alloca_size
     instance_vars_local = @instance_vars_local
 
-    if MethodDefinition::RubyMethod[info[1]][info[0]].is_a?(Hash) then
-      MethodDefinition::RubyMethod[info[1]][info[0]][:have_throw] = have_throw
-      MethodDefinition::RubyMethod[info[1]][info[0]][:have_yield] = have_yield
+    recklass = info[0]
+    if MethodDefinition::RubyMethod[info[1]][recklass].is_a?(Hash) then
+      MethodDefinition::RubyMethod[info[1]][recklass][:have_throw] = have_throw
+      MethodDefinition::RubyMethod[info[1]][recklass][:have_yield] = have_yield
     end
 
     rett2 = nil
     if info[1] then
-      rett2 = MethodDefinition::RubyMethod[info[1]][info[0]][:rettype]
+      rett2 = MethodDefinition::RubyMethod[info[1]][recklass][:rettype]
     end
 
     if rett2 == nil # or rett2.type == nil then
@@ -724,6 +726,8 @@ class YarvTranslator&lt;YarvVisitor
       @type_inferece_after_traverse.call
       RubyType.resolve
       @type_inferece_after_traverse = lambda {}
+      RubyType.resolve
+      @type_inferece_after_traverse = lambda {}
 
       if info[1] then
         pppp &quot;define #{info[1]}&quot;
@@ -774,7 +778,8 @@ class YarvTranslator&lt;YarvVisitor
       end
 
       if inlineargs == nil and @inline_code_tab[code] == nil then
-        b = @builder.define_function(info[0], info[1].to_s, 
+        recklass = info[0]
+        b = @builder.define_function(recklass, info[1].to_s, 
                                      rett2, argtype, is_mkstub)
       end
 
@@ -1847,9 +1852,10 @@ class YarvTranslator&lt;YarvVisitor
   end
 
   def visit_defineclass(code, ins, local_vars, ln, info)
+    recklass = info[0]
     action = lambda {|code, info|
-      if MethodDefinition::RubyMethod[info[1]][info[0]] == nil then
-        MethodDefinition::RubyMethod[info[1]][info[0]] = true
+      if MethodDefinition::RubyMethod[info[1]][recklass] == nil then
+        MethodDefinition::RubyMethod[info[1]][recklass] = true
       end
     }
     sup = @expstack.pop
@@ -1881,9 +1887,7 @@ class YarvTranslator&lt;YarvVisitor
     end
     
     receiver = nil
-    if !isfunc then
-      receiver = @expstack.pop
-    else
+    if isfunc then
       @expstack.pop
       if info[0] then
         receiver = [local_vars[2][:type], 
@@ -1891,6 +1895,8 @@ class YarvTranslator&lt;YarvVisitor
                       context.rc = b.load(local_vars[2][:area])
                       context}]
       end
+    else
+      receiver = @expstack.pop
     end
 
     RubyType.resolve
@@ -1951,19 +1957,30 @@ class YarvTranslator&lt;YarvVisitor
     @type_inferece_after_traverse = lambda {
       old_tiat.call
       rectype = receiver ? receiver[0] : nil
-      minfo, func = gen_method_select(rectype, curklass, mname, false)
+      minfo, func, kls = gen_method_select(rectype, curklass, mname, false)
 
-      if minfo then
+      if minfo and (isfunc or kls) then
         nargt = minfo[:argtype]
         nargt.each_with_index do |ele, n|
           para[n][0].add_same_type ele
           ele.add_same_type para[n][0]
         end
-        rett.add_same_type minfo[:rettype]
-        minfo[:rettype].add_same_type rett
+        rettype = minfo[:rettype]
+        if cact = minfo[:copy_rettype] then
+          if cact == true then
+            orgrettype = rettype
+            rettype = RubyType.new(nil)
+            orgrettype.add_same_type(rettype)
+          else
+            rectype = receiver ? receiver[0] : local_vars[2][:type]
+            rettype = cact.call(rectype, args.map{|e| e[0]})
+          end
+        end
+        rett.add_same_type rettype
+        rettype.add_same_type rett
       end
     }
-    
+
     @expstack.push [rett,
       lambda {|b, context|
 
@@ -2049,7 +2066,8 @@ class YarvTranslator&lt;YarvVisitor
     
     rett = RubyType.new(nil, info[3], &quot;Return type of yield&quot;)
 
-    minfo = MethodDefinition::RubyMethod[info[1]][info[0]]
+    recklass = info[0]
+    minfo = MethodDefinition::RubyMethod[info[1]][recklass]
     minfo[:yield_argtype] = arg.map {|e| e[0]}
     minfo[:yield_rettype] = rett
 
@@ -2107,7 +2125,8 @@ class YarvTranslator&lt;YarvVisitor
     end
 
     if info[1] then
-      rett2 = MethodDefinition::RubyMethod[info[1]][info[0]][:rettype]
+      recklass = info[0]
+      rett2 = MethodDefinition::RubyMethod[info[1]][recklass][:rettype]
       retexp[0].add_same_type rett2
       # RubyType.resolve
     end
@@ -3466,8 +3485,9 @@ class YarvTranslator&lt;YarvVisitor
   end
 
   def set_have_yield(info, val)
-    if MethodDefinition::RubyMethod[info[1]][info[0]].is_a?(Hash) then
-      MethodDefinition::RubyMethod[info[1]][info[0]][:have_yield] = val
+    recklass = info[0]
+    if MethodDefinition::RubyMethod[info[1]][recklass].is_a?(Hash) then
+      MethodDefinition::RubyMethod[info[1]][recklass][:have_yield] = val
     end
     @have_yield = val
   end</diff>
      <filename>lib/vmtraverse.rb</filename>
    </modified>
    <modified>
      <diff>@@ -111,21 +111,23 @@ module YARV2LLVM
 
 
   st = RubyType.array
-  rt = RubyType.array
-  rt.add_same_type(st)
-  st.add_same_type(rt)
-  MethodDefinition::RubyMethod[:sort][:Array] = {
+  MethodDefinition::RubyMethod[:sort][:AbstructContainer] = {
     :self =&gt; st,
     :argtype =&gt; [],
-    :rettype =&gt; rt,
-    :copy_rettype =&gt; true,
+    :rettype =&gt; nil,
+    :copy_rettype =&gt; lambda { |rect, argt|
+      rt = RubyType.array
+      rt.add_same_type(rect)
+      rect.add_same_type(rt)
+      rt
+    }
   }
 
   st = RubyType.array
   rt = RubyType.array
   rt.add_same_type(st)
   st.add_same_type(rt)
-  MethodDefinition::RubyMethod[:sort!][:Array] = {
+  MethodDefinition::RubyMethod[:sort!][:AbstructContainer] = {
     :self =&gt; st,
     :argtype =&gt; [],
     :rettype =&gt; rt,
@@ -137,7 +139,7 @@ module YARV2LLVM
   rt = RubyType.array
   rt.add_same_type(st)
   st.add_same_type(rt)
-  MethodDefinition::RubyMethod[:uniq!][:Array] = {
+  MethodDefinition::RubyMethod[:uniq!][:AbstructContainer] = {
     :self =&gt; st,
     :argtype =&gt; [],
     :rettype =&gt; rt,</diff>
      <filename>runtime/prelude.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>a3c7a6be91dadbd71fc13c6bf2b6b02875adad02</id>
    </parent>
  </parents>
  <author>
    <name>U-KOZUE\kozue</name>
    <email>m-72@tf6.so-net.ne.jp</email>
  </author>
  <url>http://github.com/miura1729/yarv2llvm/commit/23e335091f4f4d2f8fac3cbd166c8abc71234485</url>
  <id>23e335091f4f4d2f8fac3cbd166c8abc71234485</id>
  <committed-date>2009-10-24T02:59:37-07:00</committed-date>
  <authored-date>2009-10-24T02:59:37-07:00</authored-date>
  <message>Some changes</message>
  <tree>b50e20bc82cebaca58d2ad6cbce68b6e3e5486c1</tree>
  <committer>
    <name>U-KOZUE\kozue</name>
    <email>m-72@tf6.so-net.ne.jp</email>
  </committer>
</commit>
