self.toolcontext.info("*** COMPILING TO C ***", 1)
var compiler = new SeparateErasureCompiler(mainmodule, runtime_type_analysis, self)
+ compiler.compile_header
# compile class structures
+ compiler.new_file
for m in mainmodule.in_importation.greaters do
for mclass in m.intro_mclasses do
compiler.compile_class_to_c(mclass)
end
# The main function of the C
+ compiler.new_file
compiler.compile_main_function
# compile methods
for m in mainmodule.in_importation.greaters do
+ compiler.new_file
compiler.compile_module_to_c(m)
end
+ compiler.display_stats
+
write_and_make(compiler)
end
end
redef fun compile_header_structs do
self.header.add_decl("typedef void(*nitmethod_t)(void); /* general C type representing a Nit method. */")
- self.header.add_decl("typedef void* nitattribute_t; /* general C type representing a Nit attribute. */")
+ self.compile_header_attribute_structs
self.header.add_decl("struct class \{ int id; const char *name; int box_kind; int color; struct vts_table *vts_table; struct type_table *type_table; nitmethod_t vft[1]; \}; /* general C type representing a Nit class. */")
self.header.add_decl("struct type_table \{ int size; int table[1]; \}; /* colorized type table. */")
self.header.add_decl("struct vts_entry \{ short int is_nullable; struct class *class; \}; /* link (nullable or not) between the vts and is bound. */")
self.header.add_decl("struct vts_table \{ struct vts_entry vts[1]; \}; /* vts list of a C type representation. */")
end
- self.header.add_decl("typedef struct \{ struct class *class; nitattribute_t attrs[1]; \} val; /* general C type representing a Nit instance. */")
+ self.header.add_decl("typedef struct val \{ struct class *class; nitattribute_t attrs[1]; \} val; /* general C type representing a Nit instance. */")
end
redef fun compile_class_to_c(mclass: MClass)
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)
+ 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)
return self.new_expr("NEW_{mtype.mclass.c_name}()", mtype)
end
- redef fun type_test(value, mtype)
+ redef fun type_test(value, mtype, tag)
do
self.add("/* type test for {value.inspect} isa {mtype} */")
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
if maybe_null == 0 then
self.add("{is_nullable} = 0;")
end
+ 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 maybe_null == 0 then
self.add("{is_nullable} = {entry}.is_nullable;")
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