rta: add_monomorphic_send mark the mproperty as live
[nit.git] / src / separate_compiler.nit
index 01ac4fa..4b1c5cc 100644 (file)
@@ -18,7 +18,6 @@ module separate_compiler
 import abstract_compiler
 import layout_builders
 import rapid_type_analysis
-import compiler_ffi
 
 # Add separate compiler specific options
 redef class ToolContext
@@ -934,10 +933,10 @@ class SeparateCompiler
                self.header.add_decl("struct nitni_instance \{struct instance *value;\};")
        end
        
-       redef fun finalize_ffi_for_module(nmodule)
+       redef fun finalize_ffi_for_module(mmodule)
        do
                var old_module = self.mainmodule
-               self.mainmodule = nmodule.mmodule.as(not null)
+               self.mainmodule = mmodule
                super
                self.mainmodule = old_module
        end
@@ -984,7 +983,7 @@ class SeparateCompilerVisitor
                        self.require_declaration("BOX_{valtype.c_name}")
                        self.add("{res} = BOX_{valtype.c_name}({value}); /* autobox from {value.mtype} to {mtype} */")
                        return res
-               else if value.mtype.cname_blind == "void*" and mtype.cname_blind == "void*" then
+               else if value.mtype.ctype == "void*" and mtype.ctype == "void*" then
                        return value
                else
                        # Bad things will appen!
@@ -1012,13 +1011,21 @@ class SeparateCompilerVisitor
        do
                var rta = compiler.runtime_type_analysis
                var recv = args.first.mtype
-               if compiler.modelbuilder.toolcontext.opt_direct_call_monomorph.value and rta != null and recv isa MClassType then
+               if compiler.modelbuilder.toolcontext.opt_direct_call_monomorph.value and rta != null then
                        var tgs = rta.live_targets(callsite)
                        if tgs.length == 1 then
                                # DIRECT CALL
                                var mmethod = callsite.mproperty
                                self.varargize(mmethod.intro, mmethod.intro.msignature.as(not null), args)
-                               return call(tgs.first, recv, args)
+                               var res0 = before_send(mmethod, args)
+                               var res = call(tgs.first, tgs.first.mclassdef.bound_mtype, args)
+                               if res0 != null then
+                                       assert res != null
+                                       self.assign(res0, res)
+                                       res = res0
+                               end
+                               add("\}") # close the before_send
+                               return res
                        end
                end
                return super
@@ -1125,8 +1132,8 @@ class SeparateCompilerVisitor
                        res = self.new_var(ret)
                end
 
-               var s = new Buffer
-               var ss = new Buffer
+               var s = new FlatBuffer
+               var ss = new FlatBuffer
 
                s.append("val*")
                ss.append("{recv}")
@@ -1759,8 +1766,8 @@ class SeparateRuntimeFunction
 
                var msignature = mmethoddef.msignature.resolve_for(mmethoddef.mclassdef.bound_mtype, mmethoddef.mclassdef.bound_mtype, mmethoddef.mclassdef.mmodule, true)
 
-               var sig = new Buffer
-               var comment = new Buffer
+               var sig = new FlatBuffer
+               var comment = new FlatBuffer
                var ret = msignature.return_mtype
                if ret != null then
                        sig.append("{ret.ctype} ")
@@ -1832,8 +1839,8 @@ class VirtualRuntimeFunction
                var frame = new Frame(v, mmethoddef, recv, arguments)
                v.frame = frame
 
-               var sig = new Buffer
-               var comment = new Buffer
+               var sig = new FlatBuffer
+               var comment = new FlatBuffer
 
                # Because the function is virtual, the signature must match the one of the original class
                var intromclassdef = self.mmethoddef.mproperty.intro.mclassdef