nitc $ SeparateErasureCompilerVisitor :: SELF
Type of this instance, automatically specialized in every classnitc $ SeparateErasureCompilerVisitor :: box_extern
Box extern classes to be used in the generated codenitc $ SeparateErasureCompilerVisitor :: class_name_string
Return a "const char*" variable associated to the classname of the dynamic type of an objectnitc $ SeparateErasureCompilerVisitor :: init_instance
Generate a alloc-instance + init-attributesnitc $ SeparateErasureCompilerVisitor :: native_array_instance
nitc $ SeparateErasureCompilerVisitor :: routine_ref_instance
Instantiate a new routine pointernitc $ SeparateErasureCompilerVisitor :: type_test
Generate a polymorphic subtype testnitc $ SeparateErasureCompilerVisitor :: unbox_extern
Unbox extern classes to be used in extern code (legacy NI and FFI)nitc :: AbstractCompilerVisitor :: _compiler
The associated compilernitc :: AbstractCompilerVisitor :: _current_node
The current visited AST nodenitc :: AbstractCompilerVisitor :: _frame
The currentStaticFrame
nitc :: AbstractCompilerVisitor :: _last
nitc :: AbstractCompilerVisitor :: adapt_signature
Adapt the arguments of a method according to targettedMMethodDef
nitc :: AbstractCompilerVisitor :: add
Add a line in the main part of the generated Cnitc :: AbstractCompilerVisitor :: add_cast
Add a dynamic castnitc :: AbstractCompilerVisitor :: add_escape_label
Insert a C label for associated with an escapemarknitc :: AbstractCompilerVisitor :: add_extern
Look for a needed .h and .c file for a given modulenitc :: AbstractCompilerVisitor :: add_raw_abort
Generate abort without a message.nitc :: AbstractCompilerVisitor :: add_raw_throw
Generate a long jump if there is a catch block.nitc :: AbstractCompilerVisitor :: array_instance
Generate an array valuenitc :: AbstractCompilerVisitor :: assign
Correctly assign a left and a right valuenitc :: AbstractCompilerVisitor :: autoadapt
Unsafely cast a value to a new typenitc :: AbstractCompilerVisitor :: autobox
Box or unbox a value to another type iff a C type conversion is needednitc :: SeparateCompilerVisitor :: before_send
Handle common special cases before doing the effective method invocationnitc :: AbstractCompilerVisitor :: bool_instance
Generate an integer valuenitc :: AbstractCompilerVisitor :: bool_type
Alias for self.compiler.mainmodule.bool_typenitc :: AbstractCompilerVisitor :: box_extern
Box extern classes to be used in the generated codenitc :: AbstractCompilerVisitor :: byte_instance
Generate a byte valuenitc :: AbstractCompilerVisitor :: c_string_instance
Generates a CString instance fully escaped in C-style \xHH fashionnitc :: AbstractCompilerVisitor :: call
Generate a static call on a method definitionnitc :: AbstractCompilerVisitor :: char_instance
Generate a char valuenitc :: AbstractCompilerVisitor :: check_recv_notnull
Add a check and an abort for a null receiver if neededcore :: Object :: class_factory
Implementation used byget_class
to create the specific class.
nitc :: SeparateCompilerVisitor :: class_info
Returns a C expression of the runtime class structure of the value.nitc :: AbstractCompilerVisitor :: class_name_string
Return a "const char*" variable associated to the classname of the dynamic type of an objectnitc :: AbstractCompilerVisitor :: compiler=
The associated compilernitc :: AbstractCompilerVisitor :: current_node
The current visited AST nodenitc :: AbstractCompilerVisitor :: current_node=
The current visited AST nodenitc :: AbstractCompilerVisitor :: debug
Safely show a debug message on the current node and repeat the message in the C code as a commentnitc :: AbstractCompilerVisitor :: declare_once
Add a declaration in the local-headercore :: Object :: defaultinit
nitc :: SeparateCompilerVisitor :: direct_call
Fully and directly call a mpropdefnitc :: AbstractCompilerVisitor :: equal_test
Generate a Nit "is" for two runtime_variablesnitc :: AbstractCompilerVisitor :: escapemark_name
Return an unique and stable identifier associated with an escapemarknitc :: AbstractCompilerVisitor :: expr
Compile an expression an return its resultnitc :: AbstractCompilerVisitor :: expr_bool
Alias forself.expr(nexpr, self.bool_type)
nitc :: SeparateCompilerVisitor :: extract_tag
Returns a C expression containing the tag of the value as a long.nitc :: AbstractCompilerVisitor :: float_instance
Generate a float valuenitc :: AbstractCompilerVisitor :: frame=
The currentStaticFrame
nitc :: AbstractCompilerVisitor :: get_property
Force to get the primitive property namedname
in the instance recv
or abort
nitc :: SeparateCompilerVisitor :: hardening_cast_type
Check that mtype it a pointer to a live cast typenitc :: SeparateCompilerVisitor :: hardening_live_open_type
Check that mtype is a live open typenitc :: AbstractCompilerVisitor :: init_instance
Generate a alloc-instance + init-attributesnitc :: AbstractCompilerVisitor :: init_instance_or_extern
Allocate and init attributes of an instance of a standard or extern classnitc :: AbstractCompilerVisitor :: int16_instance
Generate an int16 valuenitc :: AbstractCompilerVisitor :: int32_instance
Generate an int32 valuenitc :: AbstractCompilerVisitor :: int8_instance
Generate an int8 valuenitc :: AbstractCompilerVisitor :: int_instance
Generate an integer valuecore :: 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 :: AbstractCompilerVisitor :: is_same_type_test
Generate the code required to dynamically check if 2 objects share the same runtime typenitc :: AbstractCompilerVisitor :: isset_attribute
Generate a polymorphic attribute is_set testnitc :: AbstractCompilerVisitor :: last
nitc :: AbstractCompilerVisitor :: last=
nitc :: AbstractCompilerVisitor :: maybe_null
Can value be null? (according to current knowledge)nitc :: AbstractCompilerVisitor :: monomorphic_send
Generate a monomorphic send for the methodm
, the type t
and the arguments args
nitc :: AbstractCompilerVisitor :: monomorphic_super_send
Generate a monomorphic super send from the methodm
, the type t
and the arguments args
nitc :: AbstractCompilerVisitor :: native_array_get
Return an element of a native array.nitc :: AbstractCompilerVisitor :: native_array_set
Store an element in a native array.core :: Object :: native_class_name
The class name of the object in CString format.nitc :: AbstractCompilerVisitor :: new_expr
Return a new local runtime_variable initialized with the C expressioncexpr
.
nitc :: AbstractCompilerVisitor :: new_named_var
Return a new uninitialized named runtime_variablenitc :: AbstractCompilerVisitor :: new_var
Return a new uninitialized local runtime_variablenitc :: AbstractCompilerVisitor :: new_var_extern
The difference withnew_var
is the C static type of the local variable
nitc :: AbstractCompilerVisitor :: null_instance
Generate thenull
value
nitc :: AbstractCompilerVisitor :: object_type
Alias for self.compiler.mainmodule.object_typecore :: Object :: output_class_name
Display class name on stdout (debug only).nitc :: AbstractCompilerVisitor :: read_attribute
Generate a polymorphic attribute readnitc :: AbstractCompilerVisitor :: require_declaration
Request the presence of a global declarationnitc :: AbstractCompilerVisitor :: ret
Generate a return with the values
nitc :: AbstractCompilerVisitor :: ret_to_c
Return aRuntimeVarible
to C user code
nitc :: AbstractCompilerVisitor :: routine_ref_call
Call the underlying referenced functionnitc :: AbstractCompilerVisitor :: routine_ref_instance
Instantiate a new routine pointernitc :: AbstractCompilerVisitor :: send
Generate a polymorphic send for the methodm
and the arguments args
nitc :: AbstractCompilerVisitor :: set_finalizer
Set a GC finalizer onrecv
, only if recv
isa Finalizable
nitc :: AbstractCompilerVisitor :: stmt
Compile a statement (if any)nitc :: AbstractCompilerVisitor :: string_instance
Generate a string valuenitc :: AbstractCompilerVisitor :: supercall
Generate a super call from a method definitionnitc :: SeparateCompilerVisitor :: type_info
Returns a C expression of the runtime type structure of the value.nitc :: AbstractCompilerVisitor :: type_test
Generate a polymorphic subtype testnitc :: AbstractCompilerVisitor :: uint16_instance
Generate a uint16 valuenitc :: AbstractCompilerVisitor :: uint32_instance
Generate a uint32 valuenitc :: AbstractCompilerVisitor :: unbox_extern
Unbox extern classes to be used in extern code (legacy NI and FFI)nitc :: AbstractCompilerVisitor :: unbox_signature_extern
Unbox all the arguments of a method when implementedextern
or intern
nitc :: AbstractCompilerVisitor :: var_from_c
Create aRuntimeVariable
for this C variable originating from C user code
nitc :: AbstractCompilerVisitor :: vararg_instance
Get an instance of a array for a varargnitc :: AbstractCompilerVisitor :: varargize
Evaluateargs
as expressions in the call of mpropdef
on recv
.
nitc :: AbstractCompilerVisitor :: variable
Return the local runtime_variable associated to a Nit local variablenitc :: AbstractCompilerVisitor :: write_attribute
Generate a polymorphic attribute writenitc :: AbstractCompilerVisitor
A visitor on the AST of property definition that generate the C code.nitc :: SeparateCompilerVisitor
A visitor on the AST of property definition that generate the C code of a separate compilation process.
class SeparateErasureCompilerVisitor
super SeparateCompilerVisitor
redef fun compile_callsite(callsite, arguments)
do
var res = super
if callsite.erasure_cast and not self.compiler.as(SeparateErasureCompiler).modelbuilder.toolcontext.opt_no_check_erasure_cast.value then
assert res != null
var mtype = callsite.msignature.return_mtype
assert mtype != null
self.add("/* Erasure cast for return {res} isa {mtype} */")
var cond = self.type_test(res, mtype, "erasure")
self.add("if (!{cond}) \{")
#var x = self.class_name_string(res)
#var y = self.class_name_string(arguments.first)
#self.add("PRINT_ERROR(\"Erasure cast: expected {mtype} (self is %s), got %s for {res}\\n\", {y}, {x});")
self.add_abort("Cast failed")
self.add("\}")
end
return res
end
redef fun init_instance(mtype)
do
self.require_declaration("NEW_{mtype.mclass.c_name}")
return self.new_expr("NEW_{mtype.mclass.c_name}()", mtype)
end
redef fun type_test(value, mtype, tag)
do
self.add("/* type test for {value.inspect} isa {mtype} */")
var res = self.new_var(bool_type)
var cltype = self.get_name("cltype")
self.add_decl("int {cltype};")
var idtype = self.get_name("idtype")
self.add_decl("int {idtype};")
var maybe_null = self.maybe_null(value)
var accept_null = "0"
if mtype isa MNullableType then
mtype = mtype.mtype
accept_null = "1"
end
if mtype isa MParameterType then
# Here we get the bound of the the formal type (eh, erasure...)
mtype = mtype.resolve_for(self.frame.mpropdef.mclassdef.bound_mtype, self.frame.mpropdef.mclassdef.bound_mtype, self.frame.mpropdef.mclassdef.mmodule, false)
if mtype isa MNullableType then
mtype = mtype.mtype
accept_null = "1"
end
end
if value.mcasttype.is_subtype(self.frame.mpropdef.mclassdef.mmodule, self.frame.mpropdef.mclassdef.bound_mtype, mtype) then
self.add("{res} = 1; /* easy {value.inspect} isa {mtype}*/")
if compiler.modelbuilder.toolcontext.opt_typing_test_metrics.value then
self.compiler.count_type_test_skipped[tag] += 1
self.add("count_type_test_skipped_{tag}++;")
end
return res
end
var class_ptr
if not value.mtype.is_c_primitive then
class_ptr = "{value}->class->"
else
var mclass = value.mtype.as(MClassType).mclass
self.require_declaration("class_{mclass.c_name}")
class_ptr = "class_{mclass.c_name}."
end
if mtype isa MClassType then
self.require_declaration("class_{mtype.mclass.c_name}")
self.add("{cltype} = class_{mtype.mclass.c_name}.color;")
self.add("{idtype} = class_{mtype.mclass.c_name}.id;")
if compiler.modelbuilder.toolcontext.opt_typing_test_metrics.value then
self.compiler.count_type_test_resolved[tag] += 1
self.add("count_type_test_resolved_{tag}++;")
end
else if mtype isa MVirtualType then
var recv = self.frame.arguments.first
var recv_ptr
if not recv.mtype.is_c_primitive then
recv_ptr = "{recv}->class->"
else
var mclass = recv.mtype.as(MClassType).mclass
self.require_declaration("class_{mclass.c_name}")
recv_ptr = "class_{mclass.c_name}."
end
var entry = self.get_name("entry")
self.add("struct vts_entry {entry};")
self.require_declaration(mtype.mproperty.const_color)
self.add("{entry} = {recv_ptr}vts_table->vts[{mtype.mproperty.const_color}];")
self.add("{cltype} = {entry}.class->color;")
self.add("{idtype} = {entry}.class->id;")
if maybe_null and accept_null == "0" then
var is_nullable = self.get_name("is_nullable")
self.add_decl("short int {is_nullable};")
self.add("{is_nullable} = {entry}.is_nullable;")
accept_null = is_nullable.to_s
end
if compiler.modelbuilder.toolcontext.opt_typing_test_metrics.value then
self.compiler.count_type_test_unresolved[tag] += 1
self.add("count_type_test_unresolved_{tag}++;")
end
else
self.debug("type_test({value.inspect}, {mtype})")
abort
end
# check color is in table
if maybe_null then
self.add("if({value} == NULL) \{")
self.add("{res} = {accept_null};")
self.add("\} else \{")
end
self.add("if({cltype} >= {class_ptr}type_table->size) \{")
self.add("{res} = 0;")
self.add("\} else \{")
self.add("{res} = {class_ptr}type_table->table[{cltype}] == {idtype};")
self.add("\}")
if maybe_null then
self.add("\}")
end
return res
end
redef fun unbox_extern(value, mtype)
do
if mtype isa MClassType and mtype.mclass.kind == extern_kind and
mtype.mclass.name != "CString" then
var pointer_type = compiler.mainmodule.pointer_type
var res = self.new_var_extern(mtype)
self.add "{res} = ((struct instance_{pointer_type.c_name}*){value})->value; /* unboxing {value.mtype} */"
return res
else
return value
end
end
redef fun box_extern(value, mtype)
do
if mtype isa MClassType and mtype.mclass.kind == extern_kind and
mtype.mclass.name != "CString" then
var valtype = compiler.mainmodule.pointer_type
var res = self.new_var(mtype)
if compiler.runtime_type_analysis != null and not compiler.runtime_type_analysis.live_types.has(value.mtype.as(MClassType)) then
self.add("/*no boxing of {value.mtype}: {value.mtype} is not live! */")
self.add("PRINT_ERROR(\"Dead code executed!\\n\"); fatal_exit(1);")
return res
end
self.require_declaration("BOX_{valtype.c_name}")
self.add("{res} = BOX_{valtype.c_name}({value}); /* boxing {value.mtype} */")
self.require_declaration("class_{mtype.c_name}")
self.add("{res}->class = &class_{mtype.c_name};")
return res
else
return value
end
end
redef fun class_name_string(value)
do
var res = self.get_name("var_class_name")
self.add_decl("const char* {res};")
if not value.mtype.is_c_primitive then
self.add "{res} = {value} == NULL ? \"null\" : {value}->class->name;"
else
self.require_declaration("class_{value.mtype.c_name}")
self.add "{res} = class_{value.mtype.c_name}.name;"
end
return res
end
redef fun native_array_instance(elttype, length)
do
var nclass = mmodule.native_array_class
var mtype = nclass.get_mtype([elttype])
var res = self.new_var(mtype)
res.is_exact = true
self.require_declaration("NEW_{nclass.c_name}")
length = autobox(length, compiler.mainmodule.int_type)
self.add("{res} = NEW_{nclass.c_name}({length});")
return res
end
redef fun routine_ref_instance(routine_type, recv, callsite)
do
var mmethoddef = callsite.mpropdef
#debug "ENTER ref_instance"
var mmethod = mmethoddef.mproperty
# routine_mclass is the specialized one, e.g: FunRef1, ProcRef2, etc..
var routine_mclass = routine_type.mclass
var nclasses = mmodule.model.get_mclasses_by_name("RoutineRef").as(not null)
var base_routine_mclass = nclasses.first
# All routine classes use the same `NEW` constructor.
# However, they have different declared `class` and `type` value.
self.require_declaration("NEW_{base_routine_mclass.c_name}")
var recv_class_cname = recv.mcasttype.as(MClassType).mclass.c_name
var my_recv = recv
if recv.mtype.is_c_primitive then
my_recv = autobox(recv, mmodule.object_type)
end
var my_recv_mclass_type = my_recv.mtype.as(MClassType)
# The class of the concrete Routine must exist (e.g ProcRef0, FunRef0, etc.)
self.require_declaration("class_{routine_mclass.c_name}")
self.require_declaration(mmethoddef.c_name)
var thunk_function = mmethoddef.callref_thunk(my_recv_mclass_type)
var runtime_function = mmethoddef.virtual_runtime_function
var is_c_equiv = runtime_function.msignature.c_equiv(thunk_function.msignature)
var c_ref = thunk_function.c_ref
if is_c_equiv then
var const_color = mmethoddef.mproperty.const_color
c_ref = "{class_info(my_recv)}->vft[{const_color}]"
self.require_declaration(const_color)
else
self.require_declaration(thunk_function.c_name)
compiler.thunk_todo(thunk_function)
end
compiler.thunk_todo(thunk_function)
# Each RoutineRef points to a receiver AND a callref_thunk
var res = self.new_expr("NEW_{base_routine_mclass.c_name}({my_recv}, (nitmethod_t){c_ref}, &class_{routine_mclass.c_name})", routine_type)
#debug "LEAVING ref_instance"
return res
end
end
src/compiler/separate_erasure_compiler.nit:535,1--773,3