args
as expressions in the call of mpropdef
on recv
.This method is used to manage varargs in signatures and returns the real array of runtime variables to use in the call.
# Evaluate `args` as expressions in the call of `mpropdef` on `recv`.
# This method is used to manage varargs in signatures and returns the real array
# of runtime variables to use in the call.
fun varargize(mpropdef: MMethodDef, map: nullable SignatureMap, recv: RuntimeVariable, args: SequenceRead[AExpr]): Array[RuntimeVariable]
do
var msignature = mpropdef.msignature.as(not null)
var res = new Array[RuntimeVariable]
res.add(recv)
if msignature.arity == 0 then return res
if map == null then
assert args.length == msignature.arity
for ne in args do
res.add self.expr(ne, null)
end
return res
end
# Eval in order of arguments, not parameters
var exprs = new Array[RuntimeVariable].with_capacity(args.length)
for ne in args do
exprs.add self.expr(ne, null)
end
# Fill `res` with the result of the evaluation according to the mapping
for i in [0..msignature.arity[ do
var param = msignature.mparameters[i]
var j = map.map.get_or_null(i)
if j == null then
# default value
res.add(null_instance)
continue
end
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)
continue
end
res.add exprs[j]
end
return res
end
src/compiler/abstract_compiler.nit:1387,2--1431,4