compiler.new_file("{mainmodule.name}.main")
compiler.compile_nitni_global_ref_functions
compiler.compile_main_function
+ compiler.compile_finalizer_function
# compile methods
for m in mainmodule.in_importation.greaters do
# 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};")
v.require_declaration("class_{c_name}")
v.add("{res}->class = &class_{c_name};")
self.generate_init_attr(v, res, mtype)
+ v.set_finalizer res
v.add("return {res};")
end
v.add("\}")
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*"