nitc :: NaiveInterpreter :: call
mpropdef
for a args
(where args[0]
is the receiver).Return a value if mpropdef
is a function, or null if it is a procedure.
The call is direct/static. There is no message-sending/late-binding.
# Execute `mpropdef` for a `args` (where `args[0]` is the receiver).
# Return a value if `mpropdef` is a function, or null if it is a procedure.
# The call is direct/static. There is no message-sending/late-binding.
fun call(mpropdef: MMethodDef, args: Array[Instance]): nullable Instance
do
if self.modelbuilder.toolcontext.opt_discover_call_trace.value and not self.discover_call_trace.has(mpropdef) then
self.discover_call_trace.add mpropdef
self.debug("Discovered {mpropdef}")
end
assert args.length == mpropdef.msignature.arity + 1 else debug("Invalid arity for {mpropdef}. {args.length} arguments given.")
# Look for the AST node that implements the property
var val = mpropdef.constant_value
var node = modelbuilder.mpropdef2node(mpropdef)
if mpropdef.is_abstract then
if node != null then
self.frames.unshift new_frame(node, mpropdef, args)
end
fatal("Abstract method `{mpropdef.mproperty.name}` called on `{args.first.mtype}`")
abort
end
if node isa APropdef then
self.parameter_check(node, mpropdef, args)
return node.call(self, mpropdef, args)
else if node isa AClassdef then
self.parameter_check(node, mpropdef, args)
return node.call(self, mpropdef, args)
else if node != null then
fatal("Fatal Error: method {mpropdef} associated to unexpected AST node {node.location}")
abort
else if val != null then
return value_instance(val)
else
fatal("Fatal Error: method {mpropdef} not found in the AST")
abort
end
end
src/interpreter/naive_interpreter.nit:532,2--570,4