auto_super_init: use CallSite
authorJean Privat <jean@pryen.org>
Wed, 5 Mar 2014 20:50:08 +0000 (15:50 -0500)
committerJean Privat <jean@pryen.org>
Wed, 5 Mar 2014 20:50:08 +0000 (15:50 -0500)
this will simplify calls on (future) new-style init since the logic
will be in the CallSite part.

Signed-off-by: Jean Privat <jean@pryen.org>

src/abstract_compiler.nit
src/auto_super_init.nit
src/naive_interpreter.nit
src/rapid_type_analysis.nit

index c8454e5..1d78c97 100644 (file)
@@ -1512,10 +1512,10 @@ redef class AConcreteMethPropdef
                        var args = [arguments.first]
                        for auto_super_init in auto_super_inits do
                                args.clear
-                               for i in [0..auto_super_init.intro.msignature.arity+1[ do
+                               for i in [0..auto_super_init.msignature.arity+1[ do
                                        args.add(arguments[i])
                                end
-                               v.send(auto_super_init, args)
+                               v.compile_callsite(auto_super_init, args)
                        end
                end
                v.stmt(self.n_block)
index 1fecf9f..f304d04 100644 (file)
@@ -49,7 +49,7 @@ end
 
 redef class AConcreteMethPropdef
        # In case of constructor, the list of implicit auto super init constructors invoked (if needed)
-       var auto_super_inits: nullable Array[MMethod] = null
+       var auto_super_inits: nullable Array[CallSite] = null
 
        fun do_auto_super_init(modelbuilder: ModelBuilder)
        do
@@ -57,6 +57,7 @@ redef class AConcreteMethPropdef
                var mpropdef = self.mpropdef.as(not null)
                var mmodule = mpropdef.mclassdef.mmodule
                var anchor = mclassdef.bound_mtype
+               var recvtype = mclassdef.mclass.mclass_type
 
                # Collect only for constructors
                if not mpropdef.mproperty.is_init then return
@@ -83,7 +84,7 @@ redef class AConcreteMethPropdef
 
                # Still here? So it means that we must determine what super inits need to be automatically invoked
 
-               var auto_super_inits = new Array[MMethod]
+               var auto_super_inits = new Array[CallSite]
                for msupertype in mclassdef.supertypes do
                        # FIXME: the order is quite arbitrary
                        if not msupertype.mclass.kind.need_init then continue
@@ -97,14 +98,23 @@ redef class AConcreteMethPropdef
                                return
                        end
                        assert candidate isa MMethod
-                       auto_super_inits.add(candidate)
+
+                       var candidatedefs = candidate.lookup_definitions(mmodule, anchor)
+                       var candidatedef = candidatedefs.first
+                       # TODO, we drop the others propdefs in the callsite, that is not great :(
+
+                       var msignature = candidatedef.msignature
+                       msignature = msignature.resolve_for(recvtype, anchor, mmodule, true)
+
+                       var callsite = new CallSite(self, recvtype, true, candidate, candidatedef, msignature, false)
+                       auto_super_inits.add(callsite)
                end
                if auto_super_inits.is_empty then
                        modelbuilder.error(self, "Error: No constructors to call implicitely in {mpropdef}. Call one explicitely.")
                        return
                end
                for auto_super_init in auto_super_inits do
-                       var auto_super_init_def = auto_super_init.intro
+                       var auto_super_init_def = auto_super_init.mpropdef
                        var msig = mpropdef.msignature.as(not null)
                        var supermsig = auto_super_init.msignature
                        if supermsig.arity > msig.arity then
index 016cdc8..4b1030a 100644 (file)
@@ -623,10 +623,10 @@ redef class AConcreteMethPropdef
                        var args = [arguments.first]
                        for auto_super_init in auto_super_inits do
                                args.clear
-                               for i in [0..auto_super_init.intro.msignature.arity+1[ do
+                               for i in [0..auto_super_init.msignature.arity+1[ do
                                        args.add(arguments[i])
                                end
-                               v.send(auto_super_init, args)
+                               v.callsite(auto_super_init, args)
                        end
                end
 
index d2121e5..eecee11 100644 (file)
@@ -158,7 +158,7 @@ class RapidTypeAnalysis
                                var auto_super_inits = npropdef.auto_super_inits
                                if auto_super_inits != null then
                                        for auto_super_init in auto_super_inits do
-                                               v.add_monomorphic_send(v.receiver, auto_super_init)
+                                               v.add_callsite(auto_super_init)
                                        end
                                end
                        else if npropdef isa AInternMethPropdef or