# The main function of the C
compiler.new_file("{mainmodule.name}.main")
+ compiler.compile_nitni_global_ref_functions
compiler.compile_main_function
# compile methods
# resolution table (for receiver)
if is_live then
- var mclass_type = mtype
- if mclass_type isa MNullableType then mclass_type = mclass_type.mtype
+ var mclass_type = mtype.as_notnullable
assert mclass_type isa MClassType
if resolution_tables[mclass_type].is_empty then
v.add_decl("NULL, /*NO RESOLUTIONS*/")
fun compile_type_resolution_table(mtype: MType) do
- var mclass_type: MClassType
- if mtype isa MNullableType then
- mclass_type = mtype.mtype.as(MClassType)
- else
- mclass_type = mtype.as(MClassType)
- end
+ var mclass_type = mtype.as_notnullable.as(MClassType)
# extern const struct resolution_table_X resolution_table_X
self.provide_declaration("resolution_table_{mtype.c_name}", "extern const struct types resolution_table_{mtype.c_name};")
redef fun compile_nitni_structs
do
- self.header.add_decl("struct nitni_instance \{struct instance *value;\};")
+ self.header.add_decl """
+struct nitni_instance \{
+ struct nitni_instance *next,
+ *prev; /* adjacent global references in global list */
+ int count; /* number of time this global reference has been marked */
+ struct instance *value;
+\};
+"""
+ super
end
-
+
redef fun finalize_ffi_for_module(mmodule)
do
var old_module = self.mainmodule
fun can_be_primitive(value: RuntimeVariable): Bool
do
- var t = value.mcasttype
- if t isa MNullableType then t = t.mtype
+ var t = value.mcasttype.as_notnullable
if not t isa MClassType then return false
var k = t.mclass.kind
return k == interface_kind or t.ctype != "val*"