compiler: implements method_finish (partially)
[nit.git] / src / compiler / abstract_compiler.nit
index fa64951..a6f6afa 100644 (file)
@@ -1053,16 +1053,21 @@ abstract class AbstractCompilerVisitor
                if not initializers.is_empty then
                        var recv = arguments.first
 
-                       assert initializers.length == arguments.length - 1 else debug("expected {initializers.length}, got {arguments.length - 1}")
                        var i = 1
                        for p in initializers do
                                if p isa MMethod then
-                                       self.send(p, [recv, arguments[i]])
+                                       var args = [recv]
+                                       for x in p.intro.msignature.mparameters do
+                                               args.add arguments[i]
+                                               i += 1
+                                       end
+                                       self.send(p, args)
                                else if p isa MAttribute then
                                        self.write_attribute(p, recv, arguments[i])
+                                       i += 1
                                else abort
-                               i += 1
                        end
+                       assert i == arguments.length
 
                        return self.send(callsite.mproperty, [recv])
                end
@@ -2319,33 +2324,12 @@ redef class AClassdef
        private fun compile_to_c(v: AbstractCompilerVisitor, mpropdef: MMethodDef, arguments: Array[RuntimeVariable])
        do
                if mpropdef == self.mfree_init then
-                       if mpropdef.mproperty.is_root_init then
-                               assert self.super_inits == null
-                               assert arguments.length == 1
-                               if not mpropdef.is_intro then
-                                       v.supercall(mpropdef, arguments.first.mtype.as(MClassType), arguments)
-                               end
-                               return
-                       end
-
-                       var super_inits = self.super_inits
-                       if super_inits != null then
-                               var args_of_super = arguments
-                               if arguments.length > 1 then args_of_super = [arguments.first]
-                               for su in super_inits do
-                                       v.send(su, args_of_super)
-                               end
-                       end
-
-                       var recv = arguments.first
-                       var i = 1
-                       # Collect undefined attributes
-                       for npropdef in self.n_propdefs do
-                               if npropdef isa AAttrPropdef and npropdef.n_expr == null and not npropdef.noinit then
-                                       v.write_attribute(npropdef.mpropdef.mproperty, recv, arguments[i])
-                                       i += 1
-                               end
+                       assert mpropdef.mproperty.is_root_init
+                       assert arguments.length == 1
+                       if not mpropdef.is_intro then
+                               v.supercall(mpropdef, arguments.first.mtype.as(MClassType), arguments)
                        end
+                       return
                else
                        abort
                end
@@ -2617,6 +2601,12 @@ redef class AForExpr
                v.compile_callsite(next_meth, [it])
                v.add("\}")
                v.add("BREAK_{v.escapemark_name(escapemark)}: (void)0;")
+
+               var method_finish = self.method_finish
+               if method_finish != null then
+                       # TODO: Find a way to call this also in long escape (e.g. return)
+                       v.compile_callsite(method_finish, [it])
+               end
        end
 end