For more detail see abstract_compiler::ThunkFunction
documentation.
nitc $ CustomizedThunkFunction :: SELF
Type of this instance, automatically specialized in every classnitc $ CustomizedThunkFunction :: c_name
The mangled c name of the runtime_functionnitc $ CustomizedThunkFunction :: resolve_receiver
Prepare theself
runtime variable to be used by the rest of
nitc $ CustomizedThunkFunction :: target_recv
The type expected by the callee. Used to resolvemmethoddef
's formal
nitc :: AbstractRuntimeFunction :: _mmethoddef
The associated Nit methodnitc :: ThunkFunction :: _polymorph_call_flag
Determines if the callsite should be polymorphic or static.nitc :: 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 :: AbstractRuntimeFunction :: build_frame
Builds the static frame for current runtime methodnitc :: AbstractRuntimeFunction :: c_name
The mangled c name of the runtime_functionnitc :: AbstractRuntimeFunction :: c_ref
nitc :: AbstractRuntimeFunction :: call
Implements a call of the runtime_functioncore :: Object :: class_factory
Implementation used byget_class
to create the specific class.
nitc :: AbstractRuntimeFunction :: compile_to_c
Generate the codenitc :: AbstractRuntimeFunction :: declare_signature
How the concrete compiler will declare the method, e.g inside a global header file,nitc :: ThunkFunction :: defaultinit
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 :: ThunkFunction :: polymorph_call_flag
Determines if the callsite should be polymorphic or static.nitc :: ThunkFunction :: polymorph_call_flag=
Determines if the callsite should be polymorphic or static.nitc :: CustomizedRuntimeFunction :: recv=
The considered recievernitc :: 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 :: ThunkFunction :: target_recv
The type expected by the callee. Used to resolvemmethoddef
's formal
nitc :: AbstractRuntimeFunction
A C function associated to a Nit methodnitc :: CustomizedRuntimeFunction
A runtime function customized on a specific monomorph receiver type
# Thunk implementation for global compiler.
# For more detail see `abstract_compiler::ThunkFunction` documentation.
class CustomizedThunkFunction
super ThunkFunction
super CustomizedRuntimeFunction
redef fun c_name
do
return "THUNK_" + super
end
redef fun hash
do
return super + c_name.hash
end
redef fun resolve_receiver(v)
do
var res = super(v)
if res.is_exact then res.is_exact = not polymorph_call_flag
return res
end
redef fun target_recv
do
# If the targeted method was introduced by a primitive type,
# then target_recv must be set to it. Otherwise, there will
# be a missing cast. Here's an example:
#
# ~~~~nitish
# class Int
# fun mult_by(x:Int):Int do return x * self
# end
#
# var f = &10.mult_by
# ~~~~
# Here the thunk `f` must box the receiver `10` into an object.
# This is due to the memory representation of a call ref which
# has a pointer to an opaque type `val*`:
#
# ```C
# struct Mult_by_callref_struct {
# classid;
# // The receiver `10` would be here
# val* recv;
# // the targeted receiver is a `long`
# long (*pointer_to_mult_by)(long, long);
# }
# ```
#
# Thus, every primitive type must be boxed into an `Object` when
# instantiating a callref.
#
# However, if the underlying method was introduced by a primitive
# type then a cast must be invoked to convert our boxed receiver
# to its original primitive type.
var intro_recv = mmethoddef.mproperty.intro_mclassdef.bound_mtype
if intro_recv.is_c_primitive then
return intro_recv
end
return recv_mtype
end
end
src/compiler/global_compiler.nit:1163,1--1225,3