nitc :: NaiveInterpreter :: varargize
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 instances to use in the call.
Return null
if one of the evaluation of the arguments return null.
# 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 instances to use in the call.
# Return `null` if one of the evaluation of the arguments return null.
fun varargize(mpropdef: MMethodDef, map: nullable SignatureMap, recv: Instance, args: SequenceRead[AExpr]): nullable Array[Instance]
do
var msignature = mpropdef.msignature.as(not null)
var res = new Array[Instance]
res.add(recv)
if msignature.arity == 0 then return res
if map == null then
assert args.length == msignature.arity else debug("Expected {msignature.arity} args, got {args.length}")
var rest_args = aexprs_to_instances(args.iterator)
if rest_args == null then return null
res.append(rest_args)
return res
end
# Eval in order of arguments, not parameters
var exprs = aexprs_to_instances(args.iterator)
if exprs == null then return null
# 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.anchor_to(self.mainmodule, recv.mtype.as(MClassType))
var arg = self.array_instance(vararg, elttype)
res.add(arg)
continue
end
res.add exprs[j]
end
return res
end
src/interpreter/naive_interpreter.nit:487,2--530,4