src: introduce new constructors
[nit.git] / src / separate_compiler.nit
index 7dd57b0..4dfbeb0 100644 (file)
@@ -107,6 +107,7 @@ redef class ModelBuilder
                compiler.new_file("{mainmodule.name}.main")
                compiler.compile_nitni_global_ref_functions
                compiler.compile_main_function
+               compiler.compile_finalizer_function
 
                # compile methods
                for m in mainmodule.in_importation.greaters do
@@ -765,6 +766,7 @@ class SeparateCompiler
                        v.require_declaration("class_{c_name}")
                        v.add("{res}->class = &class_{c_name};")
                        self.generate_init_attr(v, res, mtype)
+                       v.set_finalizer res
                        v.add("return {res};")
                end
                v.add("\}")
@@ -956,11 +958,12 @@ 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 then
+               var mmethod = callsite.mproperty
+               # TODO: Inlining of new-style constructors
+               if compiler.modelbuilder.toolcontext.opt_direct_call_monomorph.value and rta != null and not mmethod.is_root_init 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)
                                var res0 = before_send(mmethod, args)
                                var res = call(tgs.first, tgs.first.mclassdef.bound_mtype, args)
@@ -1644,7 +1647,7 @@ class SeparateCompilerVisitor
                        return
                else if pname == "copy_to" then
                        var recv1 = "((struct instance_{nclass.c_instance_name}*){arguments[1]})->values"
-                       self.add("memcpy({recv1}, {recv}, {arguments[2]}*sizeof({elttype.ctype}));")
+                       self.add("memmove({recv1}, {recv}, {arguments[2]}*sizeof({elttype.ctype}));")
                        return
                end
        end