nitc :: AbstractCompilerVisitor :: call
# Generate a static call on a method definition
fun call(m: MMethodDef, recvtype: MClassType, args: Array[RuntimeVariable]): nullable RuntimeVariable is abstract
src/compiler/abstract_compiler.nit:1508,2--1509,114
redef fun call(mmethoddef, recvtype, arguments)
do
assert arguments.length == mmethoddef.msignature.arity + 1 else debug("Invalid arity for {mmethoddef}. {arguments.length} arguments given.")
var res: nullable RuntimeVariable
var ret = mmethoddef.msignature.return_mtype
if ret == null then
res = null
else
ret = ret.resolve_for(mmethoddef.mclassdef.bound_mtype, mmethoddef.mclassdef.bound_mtype, mmethoddef.mclassdef.mmodule, true)
res = self.new_var(ret)
end
if (mmethoddef.is_intern and not compiler.modelbuilder.toolcontext.opt_no_inline_intern.value) or
(compiler.modelbuilder.toolcontext.opt_inline_some_methods.value and mmethoddef.can_inline(self)) then
compiler.modelbuilder.nb_invok_by_inline += 1
if compiler.modelbuilder.toolcontext.opt_invocation_metrics.value then add("count_invoke_by_inline++;")
var frame = new StaticFrame(self, mmethoddef, recvtype, arguments)
frame.returnlabel = self.get_name("RET_LABEL")
frame.returnvar = res
var old_frame = self.frame
self.frame = frame
self.add("\{ /* Inline {mmethoddef} ({arguments.join(",")}) on {arguments.first.inspect} */")
mmethoddef.compile_inside_to_c(self, arguments)
self.add("{frame.returnlabel.as(not null)}:(void)0;")
self.add("\}")
self.frame = old_frame
return res
end
compiler.modelbuilder.nb_invok_by_direct += 1
if compiler.modelbuilder.toolcontext.opt_invocation_metrics.value then add("count_invoke_by_direct++;")
# Autobox arguments
self.adapt_signature(mmethoddef, arguments)
self.require_declaration(mmethoddef.c_name)
if res == null then
self.add("{mmethoddef.c_name}({arguments.join(", ")}); /* Direct call {mmethoddef} on {arguments.first.inspect}*/")
return null
else
self.add("{res} = {mmethoddef.c_name}({arguments.join(", ")});")
end
return res
end
src/compiler/separate_compiler.nit:1612,2--1656,4
redef fun call(m, recvtype, args)
do
var recv_type = get_recvtype(m, recvtype, args)
var recv = self.autoadapt(self.autobox(args.first, recvtype), recvtype)
if m.is_extern then recv = unbox_extern(recv, recv_type)
args = args.to_a
args.first = recv
assert args.length == m.msignature.arity + 1 else debug("Invalid arity for {m}. {args.length} arguments given.")
var rm = new CustomizedRuntimeFunction(m, recvtype)
return rm.call(self, args)
end
src/compiler/global_compiler.nit:623,2--636,4