nitc :: SeparateRuntimeFunction :: _build_c_name
The name on the compiled methodnitc :: SeparateRuntimeFunction :: _c_funptrtype
The C type for the function pointer.nitc :: SeparateRuntimeFunction :: _c_ret
The C return type (something orvoid
)
nitc :: SeparateRuntimeFunction :: _c_sig
The C signature (only the parmeter part)nitc :: SeparateRuntimeFunction :: _called_recv
The call-side static receivernitc :: SeparateRuntimeFunction :: _called_signature
The call-side static signaturenitc :: SeparateRuntimeFunction :: build_c_name=
The name on the compiled methodnitc :: SeparateRuntimeFunction :: c_funptrtype
The C type for the function pointer.nitc :: SeparateRuntimeFunction :: c_funptrtype=
The C type for the function pointer.nitc :: SeparateRuntimeFunction :: c_ret=
The C return type (something orvoid
)
nitc :: SeparateRuntimeFunction :: c_sig=
The C signature (only the parmeter part)nitc :: SeparateRuntimeFunction :: called_recv=
The call-side static receivernitc :: SeparateRuntimeFunction :: called_signature
The call-side static signaturenitc :: SeparateRuntimeFunction :: called_signature=
The call-side static signaturenitc :: SeparateRuntimeFunction :: compile_trampolines
Compile the trampolines used to implement late-binding.nitc $ SeparateRuntimeFunction :: SELF
Type of this instance, automatically specialized in every classnitc $ SeparateRuntimeFunction :: body_to_c
Generate the code for the body without return statement at the end andnitc $ SeparateRuntimeFunction :: build_c_name
The name on the compiled methodnitc $ SeparateRuntimeFunction :: build_frame
Builds the static frame for current runtime methodnitc $ SeparateRuntimeFunction :: declare_signature
How the concrete compiler will declare the method, e.g inside a global header file,nitc $ SeparateRuntimeFunction :: end_compile_to_c
Hook called at the end ofcompile_to_c
function. This function
nitc $ SeparateRuntimeFunction :: msignature
The current msignature to use when compiling :signature_to_c
and body_to_c
.
nitc $ SeparateRuntimeFunction :: recv_mtype
The current receiver type to compile :signature_to_c
and body_to_c
.
nitc :: SeparateRuntimeFunction :: _build_c_name
The name on the compiled methodnitc :: SeparateRuntimeFunction :: _c_funptrtype
The C type for the function pointer.nitc :: SeparateRuntimeFunction :: _c_ret
The C return type (something orvoid
)
nitc :: SeparateRuntimeFunction :: _c_sig
The C signature (only the parmeter part)nitc :: SeparateRuntimeFunction :: _called_recv
The call-side static receivernitc :: SeparateRuntimeFunction :: _called_signature
The call-side static signaturenitc :: AbstractRuntimeFunction :: _mmethoddef
The associated Nit methodnitc :: AbstractRuntimeFunction :: body_to_c
Generate the code for the body without return statement at the end andnitc :: AbstractRuntimeFunction :: build_c_name
Non cached version ofc_name
nitc :: SeparateRuntimeFunction :: build_c_name=
The name on the compiled methodnitc :: AbstractRuntimeFunction :: build_frame
Builds the static frame for current runtime methodnitc :: SeparateRuntimeFunction :: c_funptrtype
The C type for the function pointer.nitc :: SeparateRuntimeFunction :: c_funptrtype=
The C type for the function pointer.nitc :: AbstractRuntimeFunction :: c_name
The mangled c name of the runtime_functionnitc :: AbstractRuntimeFunction :: c_ref
nitc :: SeparateRuntimeFunction :: c_ret=
The C return type (something orvoid
)
nitc :: SeparateRuntimeFunction :: c_sig=
The C signature (only the parmeter part)nitc :: AbstractRuntimeFunction :: call
Implements a call of the runtime_functionnitc :: SeparateRuntimeFunction :: called_recv=
The call-side static receivernitc :: SeparateRuntimeFunction :: called_signature
The call-side static signaturenitc :: SeparateRuntimeFunction :: called_signature=
The call-side static signaturecore :: Object :: class_factory
Implementation used byget_class
to create the specific class.
nitc :: AbstractRuntimeFunction :: compile_to_c
Generate the codenitc :: SeparateRuntimeFunction :: compile_trampolines
Compile the trampolines used to implement late-binding.nitc :: AbstractRuntimeFunction :: declare_signature
How the concrete compiler will declare the method, e.g inside a global header file,core :: Object :: defaultinit
nitc :: AbstractRuntimeFunction :: end_compile_to_c
Hook called at the end ofcompile_to_c
function. This function
nitc :: AbstractRuntimeFunction :: fill_parameters
Fills the argument array inside v.frame.arguments, callingresolve_ith_parameter
nitc :: AbstractRuntimeFunction :: has_return
Returnstrue
if the associated mmethoddef
's return type isn't null,
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
nitc :: AbstractRuntimeFunction :: mmethoddef=
The associated Nit methodnitc :: AbstractRuntimeFunction :: msignature
The current msignature to use when compiling :signature_to_c
and body_to_c
.
core :: Object :: native_class_name
The class name of the object in CString format.core :: Object :: output_class_name
Display class name on stdout (debug only).nitc :: AbstractRuntimeFunction :: recv_mtype
The current receiver type to compile :signature_to_c
and body_to_c
.
nitc :: AbstractRuntimeFunction :: resolve_ith_parameter
Step 4 : CreatesRuntimeVariable
for each method argument.
nitc :: AbstractRuntimeFunction :: resolve_receiver
Prepare theself
runtime variable to be used by the rest of
nitc :: AbstractRuntimeFunction :: resolve_return_mtype
Step 3 : Returns the return type used by the runtime function.nitc :: AbstractRuntimeFunction :: signature_to_c
Generate the code for the signature with an open curly bracenitc :: AbstractRuntimeFunction
A C function associated to a Nit method
# The C function associated to a methoddef separately compiled
class SeparateRuntimeFunction
super AbstractRuntimeFunction
# The call-side static receiver
var called_recv: MType
# The call-side static signature
var called_signature: MSignature
# The name on the compiled method
redef var build_c_name: String
redef fun to_s do return self.mmethoddef.to_s
redef fun msignature
do
return called_signature
end
redef fun recv_mtype
do
return called_recv
end
redef fun return_mtype
do
return called_signature.return_mtype
end
# The C return type (something or `void`)
var c_ret: String is lazy do
var ret = called_signature.return_mtype
if ret != null then
return ret.ctype
else
return "void"
end
end
# The C signature (only the parmeter part)
var c_sig: String is lazy do
var sig = new FlatBuffer
sig.append("({called_recv.ctype} self")
for i in [0..called_signature.arity[ do
var mp = called_signature.mparameters[i]
var mtype = mp.mtype
if mp.is_vararg then
mtype = mmethoddef.mclassdef.mmodule.array_type(mtype)
end
sig.append(", {mtype.ctype} p{i}")
end
sig.append(")")
return sig.to_s
end
# The C type for the function pointer.
var c_funptrtype: String is lazy do return "{c_ret}(*){c_sig}"
redef fun declare_signature(v, sig)
do
v.compiler.provide_declaration(c_name, "{sig};")
end
redef fun body_to_c(v)
do
var rta = v.compiler.as(SeparateCompiler).runtime_type_analysis
if rta != null and not rta.live_mmodules.has(mmethoddef.mclassdef.mmodule) then
v.add_abort("FATAL: Dead method executed.")
else
super
end
end
redef fun end_compile_to_c(v)
do
var compiler = v.compiler
compiler.names[self.c_name] = "{mmethoddef.full_name} ({mmethoddef.location.file.filename}:{mmethoddef.location.line_start})"
end
redef fun build_frame(v, arguments)
do
var recv = mmethoddef.mclassdef.bound_mtype
return new StaticFrame(v, mmethoddef, recv, arguments)
end
# Compile the trampolines used to implement late-binding.
#
# See `opt_trampoline_call`.
fun compile_trampolines(compiler: SeparateCompiler)
do
var recv = self.mmethoddef.mclassdef.bound_mtype
var selfvar = new RuntimeVariable("self", called_recv, recv)
var ret = called_signature.return_mtype
var arguments = ["self"]
for i in [0..called_signature.arity[ do arguments.add "p{i}"
if mmethoddef.is_intro and not recv.is_c_primitive then
var m = mmethoddef.mproperty
var n2 = "CALL_" + m.const_color
compiler.provide_declaration(n2, "{c_ret} {n2}{c_sig};")
var v2 = compiler.new_visitor
v2.add "{c_ret} {n2}{c_sig} \{"
v2.require_declaration(m.const_color)
var call = "(({c_funptrtype})({v2.class_info(selfvar)}->vft[{m.const_color}]))({arguments.join(", ")});"
if ret != null then
v2.add "return {call}"
else
v2.add call
end
v2.add "\}"
end
if mmethoddef.has_supercall and not recv.is_c_primitive then
var m = mmethoddef
var n2 = "CALL_" + m.const_color
compiler.provide_declaration(n2, "{c_ret} {n2}{c_sig};")
var v2 = compiler.new_visitor
v2.add "{c_ret} {n2}{c_sig} \{"
v2.require_declaration(m.const_color)
var call = "(({c_funptrtype})({v2.class_info(selfvar)}->vft[{m.const_color}]))({arguments.join(", ")});"
if ret != null then
v2.add "return {call}"
else
v2.add call
end
v2.add "\}"
end
end
end
src/compiler/separate_compiler.nit:2463,1--2594,3