From: Jean Privat Date: Tue, 10 Nov 2015 14:45:58 +0000 (-0500) Subject: typing: move vararg_length on each argument, instead of the whole signature X-Git-Tag: v0.8~91^2~6 X-Git-Url: http://nitlanguage.org typing: move vararg_length on each argument, instead of the whole signature This will permit to have more that one vararg per call. Signed-off-by: Jean Privat --- diff --git a/src/compiler/abstract_compiler.nit b/src/compiler/abstract_compiler.nit index de68957..f177ef6 100644 --- a/src/compiler/abstract_compiler.nit +++ b/src/compiler/abstract_compiler.nit @@ -1222,8 +1222,8 @@ abstract class AbstractCompilerVisitor res.add(null_instance) continue end - if param.is_vararg and map.vararg_decl > 0 then - var vararg = exprs.sub(j, map.vararg_decl) + if param.is_vararg and args[i].vararg_decl > 0 then + var vararg = exprs.sub(j, args[i].vararg_decl) var elttype = param.mtype var arg = self.vararg_instance(mpropdef, recv, vararg, elttype) res.add(arg) diff --git a/src/interpreter/naive_interpreter.nit b/src/interpreter/naive_interpreter.nit index dc911fd..299445d 100644 --- a/src/interpreter/naive_interpreter.nit +++ b/src/interpreter/naive_interpreter.nit @@ -471,8 +471,8 @@ class NaiveInterpreter res.add(null_instance) continue end - if param.is_vararg and map.vararg_decl > 0 then - var vararg = exprs.sub(j, map.vararg_decl) + if param.is_vararg and args[i].vararg_decl > 0 then + var vararg = exprs.sub(j, args[i].vararg_decl) var elttype = param.mtype.anchor_to(self.mainmodule, recv.mtype.as(MClassType)) var arg = self.array_instance(vararg, elttype) res.add(arg) diff --git a/src/semantize/typing.nit b/src/semantize/typing.nit index b4599d0..9d2472b 100644 --- a/src/semantize/typing.nit +++ b/src/semantize/typing.nit @@ -529,7 +529,7 @@ private class TypeVisitor self.visit_expr_subtype(first, paramtype) end else - map.vararg_decl = vararg_decl + 1 + first.vararg_decl = vararg_decl + 1 for i in [vararg_rank..vararg_rank+vararg_decl] do self.visit_expr_subtype(args[i], paramtype) end @@ -614,10 +614,6 @@ end class SignatureMap # Associate a parameter to an argument var map = new ArrayMap[Int, Int] - - # The length of the vararg sequence - # 0 if no vararg or if reverse vararg (cf `AVarargExpr`) - var vararg_decl: Int = 0 end # A specific method call site with its associated informations. @@ -853,6 +849,15 @@ redef class AExpr # The result of the evaluation of `self` must be # stored inside the designated array (there is an implicit `push`) var comprehension: nullable AArrayExpr = null + + # It indicates the number of arguments collected as a vararg. + # + # When 0, the argument is used as is, without transformation. + # When 1, the argument is transformed into an singleton array. + # Above 1, the arguments and the next ones are transformed into a common array. + # + # This attribute is meaning less on expressions not used as attributes. + var vararg_decl: Int = 0 end redef class ABlockExpr