<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -16,7 +16,7 @@ def fib(n)
   end
 end
 
-YARV2LLVM::compile( &lt;&lt;EOS
+YARV2LLVM::compile(&lt;&lt;EOS, {})
 =begin
 def fact(n)
   n
@@ -33,7 +33,7 @@ def llvmfib(n)
 end
 
 EOS
-)
+
 Benchmark.bm do |x|
   x.report(&quot;Ruby   &quot;){  p fib(35)}
   x.report(&quot;llvm   &quot;){  p llvmfib(35)}</diff>
      <filename>benchmark.rb</filename>
    </modified>
    <modified>
      <diff>@@ -23,8 +23,8 @@ for y in 0..count_size
   for x in 0..count_size
     zr = 0.0
     zi = 0.0
-    cr = (2.0*x/size)-1.5
-    ci = (2.0*y/size)-1.0
+    cr = (2.0*x.to_f/size.to_f)-1.5
+    ci = (2.0*y.to_f/size.to_f)-1.0
     escape = false
 
     zrzr = zr*zr</diff>
      <filename>bm_so_mandelbrot.rb</filename>
    </modified>
    <modified>
      <diff>@@ -14,6 +14,7 @@ class LLVMBuilder
     @externed_function = {}
     @func = nil
     @global_ptr = nil
+    @builder_to_func = {}
     ExecutionEngine.get(@module)
   end
   
@@ -34,13 +35,13 @@ class LLVMBuilder
 
   def make_stub(receiver, name, rett, argt, orgfunc)
     pppp &quot;Make stub #{name}&quot;
-    sname = &quot;__stub_&quot; + name
+    sname = &quot;__stub_&quot; + to_label(name)
     nargs = argt.size
     if receiver == nil then
       argt.unshift RubyType.value
     end
     stype = Type.function(VALUE, [VALUE] * argt.size)
-    @stubfunc = @module.get_or_insert_function(to_label(sname), stype)
+    @stubfunc = @module.get_or_insert_function(sname, stype)
     eb = @stubfunc.create_block
     b = eb.builder
     argv = []
@@ -83,12 +84,20 @@ class LLVMBuilder
     MethodDefinition::RubyMethod[name.to_sym][receiver][:func] = @func
 
     eb = @func.create_block
-    eb.builder
+    b =eb.builder
+    @builder_to_func[b] = @func
+    b
   end
 
+  def select_func(b)
+    @func = @builder_to_func[b]
+  end
+  
   def define_function_raw(name, type)
     @func = @module.get_or_insert_function(name, type)
-    @func.create_block.builder
+    b = @func.create_block.builder
+    @builder_to_func[b] = @func
+    b
   end
 
   def get_or_insert_function(name, type)
@@ -135,8 +144,10 @@ class LLVMBuilder
       @module = LLVM::Module.read_bitcode(fp.read)
     }
     MethodDefinition::RubyMethodStub.each do |nm, val|
-      nn = to_label(val[:sname])
-      val[:stub] = @module.get_or_insert_function(nn, val[:type])
+      if nm then
+        nn = val[:sname]
+        val[:stub] = @module.get_or_insert_function(nn, val[:type])
+      end
     end
   end
 </diff>
      <filename>lib/llvmbuilder.rb</filename>
    </modified>
    <modified>
      <diff>@@ -8,6 +8,8 @@ module MethodDefinition
   # Use ruby internal and ignor in yarv2llvm.
   SystemMethod = {
     :&quot;core#define_method&quot; =&gt; 
+      {:args =&gt; 1},
+    :&quot;core#define_singleton_method&quot; =&gt; 
       {:args =&gt; 1}
   }
   </diff>
      <filename>lib/methoddef.rb</filename>
    </modified>
    <modified>
      <diff>@@ -422,9 +422,11 @@ class ComplexType
     else
       @klass = :nil
     end
+    @constant = nil
   end
 
   attr_accessor :klass
+  attr_accessor :constant
 
   def dup_type
     self.class.new</diff>
      <filename>lib/type.rb</filename>
    </modified>
    <modified>
      <diff>@@ -121,6 +121,7 @@ class YarvTranslator&lt;YarvVisitor
     # When this value call by call method, generate llvm code correspond 
     # to function name.
     @generated_code = {}
+    @generated_define_func = {}
 
     # Hash name of local block to name of local block jump to the 
     # local block of the key
@@ -189,10 +190,24 @@ class YarvTranslator&lt;YarvVisitor
       gen_ivar_ptr(@builder)
     end
 
+    @generated_define_func.each do |klass, value|
+      value.each do |name, gen|
+        if name then
+          gen.call(nil)
+        end
+      end
+    end
+
     initfunc = gen_init_ruby(@builder)
-    @generated_code.each do |fname, gen|
-      gen.call(nil)
+
+    @generated_code.each do |klass, value|
+      value.each do |name, gen|
+        if name then
+          gen.call
+        end
+      end
     end
+
     deffunc = gen_define_ruby(@builder)
 
     if OPTION[:optimize] then
@@ -284,8 +299,11 @@ class YarvTranslator&lt;YarvVisitor
           argt[n - 1].add_same_value local[-n][:type]
           local[-n][:type].add_same_type argt[n - 1]
         end
-        argt[numarg - 1].add_same_value local[-numarg][:type]
-        local[-numarg][:type].add_same_type argt[numarg - 1]
+
+        if info[0] or code.header['type'] != :method then
+          argt[numarg - 1].add_same_value local[-numarg][:type]
+          local[-numarg][:type].add_same_type argt[numarg - 1]
+        end
         
         minfo[:defined] = true
       end
@@ -384,27 +402,34 @@ class YarvTranslator&lt;YarvVisitor
       argtype.push local[1][:type]
     end
 
+    if @expstack.last then
+      retexp = @expstack.pop
+    else
+      retexp = [RubyType.value, lambda {|b, context|
+                  context.rc = 4.llvm
+                  context
+                }]
+    end
+
+    rescode = @rescode
     if info[1] then
-      if @expstack.last then
-        retexp = @expstack.pop
-      else
-        retexp = [RubyType.value, lambda {|b, context|
-            context.rc = 4.llvm
-            context
-          }]
-      end
-      rescode = @rescode
       rett2 = MethodDefinition::RubyMethod[info[1]][info[0]][:rettype]
       rett2.add_same_value retexp[0]
       retexp[0].add_same_type rett2
       RubyType.resolve
+    end
       
-      have_yield = @have_yield
-      array_alloca_size = @array_alloca_size
-      loop_cnt_alloca_size = @loop_cnt_alloca_size
-      instance_vars_local = @instance_vars_local
-
-      @generated_code[info[1]] = lambda {|inlineargs|
+    have_yield = @have_yield
+    array_alloca_size = @array_alloca_size
+    loop_cnt_alloca_size = @loop_cnt_alloca_size
+    instance_vars_local = @instance_vars_local
+
+    b = nil
+    inlineargs = nil
+    @generated_define_func[info[0]] ||= {}
+    @generated_define_func[info[0]][info[1]] = lambda {|iargs|
+      inlineargs = iargs
+      if info[1] then
         if OPTION[:func_signature] then
           # write function prototype
           print &quot;#{info[1]} :(&quot;
@@ -457,33 +482,47 @@ class YarvTranslator&lt;YarvVisitor
            info[0] == :YARV2LLVM then
           is_mkstub = false
         end
+      else
+        retexp[0] = RubyType.value
+        argtype = []
+        is_mkstub = false
+      end
 
-        if inlineargs then
-          b = inlineargs[0]
-        else
-          b = @builder.define_function(info[0], info[1].to_s, 
-                                       retexp[0], argtype, is_mkstub)
-        end
-        context = Context.new(local, @builder)
-        context.array_alloca_size = array_alloca_size
-        context.loop_cnt_alloca_size = loop_cnt_alloca_size
-        context.instance_vars_local = instance_vars_local
-        context.block_value[nil] = [RubyType.value, 4.llvm]
-        context.inline_args = inlineargs[1] if inlineargs
+      if inlineargs then
+        b = inlineargs[0]
+      else
+        b = @builder.define_function(info[0], info[1].to_s, 
+                                     retexp[0], argtype, is_mkstub)
+      end
+    }
+
+    @generated_code[info[0]] ||= {}
+    @generated_code[info[0]][info[1]] = lambda {
+      context = Context.new(local, @builder)
+      context.array_alloca_size = array_alloca_size
+      context.loop_cnt_alloca_size = loop_cnt_alloca_size
+      context.instance_vars_local = instance_vars_local
+      context.block_value[nil] = [RubyType.value, 4.llvm]
+      context.builder.select_func(b)
+
+      if inlineargs then
+        context.inline_args = inlineargs[1]
         context = rescode.call(b, context)
         rc = retexp[1].call(b, context).rc
-        unless inlineargs
-          if rc then
-            b.return(rc)
-          else
-            b.return(4.llvm)  # nil
-          end
+      else
+        context.inline_args = nil
+        context = rescode.call(b, context)
+        rc = retexp[1].call(b, context).rc
+        if rc then
+          b.return(rc)
+        else
+          b.return(4.llvm)  # nil
         end
+      end
 
-        pppp &quot;ret type #{retexp[0].type}&quot;
-        pppp &quot;end&quot;
-      }
-    end
+      pppp &quot;ret type #{retexp[0].type}&quot;
+      pppp &quot;end&quot;
+    }
 
 #    @expstack = []
     @rescode = lambda {|b, context| context}
@@ -492,6 +531,9 @@ class YarvTranslator&lt;YarvVisitor
   def visit_local_block_start(code, ins, local, ln, info)
     oldrescode = @rescode
     live =  @is_live
+    if live == nil and info[1] == nil then
+      live = true
+    end
 
     @is_live = nil
     if live and @expstack.size &gt; 0 then
@@ -546,8 +588,8 @@ class YarvTranslator&lt;YarvVisitor
           end
           
           context.rc = rc
-          context
         end
+        context
       }
 
       @expstack.pop
@@ -751,7 +793,7 @@ class YarvTranslator&lt;YarvVisitor
 
   def visit_setconstant(code, ins, local, ln, info)
     val = @expstack.pop
-    eval(&quot;#{ins[1].to_s} = #{val[0].name}&quot;, @binding)
+    eval(&quot;#{ins[1].to_s} = #{val[0].type.constant}&quot;, @binding)
   end
 
   def visit_getglobal(code, ins, local, ln, info)
@@ -839,7 +881,9 @@ class YarvTranslator&lt;YarvVisitor
 
   def visit_putobject(code, ins, local, ln, info)
     p1 = ins[1]
-    @expstack.push [RubyType.typeof(p1, info[3], p1), 
+    type = RubyType.typeof(p1, info[3], p1)
+    type.type.constant = p1
+    @expstack.push [type, 
       lambda {|b, context| 
         pppp p1
         context.rc = p1.llvm 
@@ -1055,7 +1099,7 @@ class YarvTranslator&lt;YarvVisitor
     evt = ins[1]
     TRACE_INFO[curtrace_no] = [evt, info.clone]
     @trace_no += 1
-    if info[1] == :trace_func and info[0] == :YARV2LLVM then
+    if (info[1] == :trace_func and info[0] == :YARV2LLVM) or info[1] == nil then
       return
     end
 
@@ -1092,7 +1136,14 @@ class YarvTranslator&lt;YarvVisitor
     }
   end
 
-  # defineclass
+  def visit_defineclass(code, ins, local, ln, info)
+    case ins[3]
+    when 0
+      eval(&quot;class #{ins[1]};end&quot;, @binding)
+    when 2
+      eval(&quot;module #{ins[1]};end&quot;, @binding)
+    end
+  end
   
   include SendUtil
   def visit_send(code, ins, local, ln, info)
@@ -1901,6 +1952,7 @@ class YarvTranslator&lt;YarvVisitor
   def gen_init_ruby(builder)
     ftype = Type.function(VALUE, [])
     b = builder.define_function_raw('init_ruby', ftype)
+    initfunc = builder.current_function
     member = []
     @global_malloc_area_tab.each do |vname, val|
       member.push val[0]
@@ -1914,8 +1966,20 @@ class YarvTranslator&lt;YarvVisitor
     init = Value.get_struct_constant(type, *initarg)
     gl = builder.define_global_variable(type, init)
 
+    @generated_define_func.each do |klass, defperklass|
+      if klass then
+        klassval = Object.const_get(klass, true)
+      else
+        klassval = 4
+      end
+      defperklass[nil].call([b, [klassval.llvm]])
+    end
+    @generated_code.each do |klass, defperklass|
+      defperklass[nil].call
+    end
+
     b.return(4.llvm)
-    builder.current_function
+    initfunc
   end
 
   def gen_define_ruby(builder)
@@ -1942,6 +2006,7 @@ class YarvTranslator&lt;YarvVisitor
       end
     end
 #=end
+
     b.return(4.llvm)
     builder.current_function
   end</diff>
      <filename>lib/vmtraverse.rb</filename>
    </modified>
    <modified>
      <diff>@@ -158,7 +158,7 @@ def offset_momentum(bodies)
 end
 
 def main
-n = 20_000_000 # ARGV[0]
+n = 200_000 # ARGV[0]
 
 offset_momentum(BODIES)
 
@@ -178,7 +178,5 @@ end
 
 p energy(BODIES)
 end
-
 EOS
-
 main</diff>
      <filename>sample/bm_so_nbody.rb</filename>
    </modified>
    <modified>
      <diff>@@ -151,6 +151,7 @@ EOS
    assert(compute_e[0], 2)
  end
 
+
  def test_send_with_block
    # This test don't move when optimize =&gt; true
    # This resason is optimizer tries to ilining calling function pointer
@@ -408,9 +409,9 @@ end
 EOS
    assert_equal(tprocesstimes, nil)
 end
-
-# I can't pass this test yet.
 =begin
+# I can't pass this test yet.
+
   def test_complex_type
     YARV2LLVM::compile(&lt;&lt;-EOS, {:optimize =&gt; false})
         def t_complex_str(arr)</diff>
      <filename>test/test_compile.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>8168b3e136b01f643363bed42d757d937d15ae86</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/889f977b4c073ccc2af052c49750c16fde8e4e1b</url>
  <id>889f977b4c073ccc2af052c49750c16fde8e4e1b</id>
  <committed-date>2008-12-29T06:05:26-08:00</committed-date>
  <authored-date>2008-12-29T06:05:26-08:00</authored-date>
  <message>Compile out of method and can command line compile but has many bugs</message>
  <tree>9f0ab86a55aa331b7a114c7f09b704f6ac1e55dc</tree>
  <committer>
    <name>U-KOZUE\kozue</name>
    <email>m-72@tf6.so-net.ne.jp</email>
  </committer>
</commit>
