# Collect all live_unresolved_types (visited in the body of classes)
# Determinate fo each livetype what are its possible requested anchored types
- var mtype2unresolved = new HashMap[MClassType, Set[MType]]
+ var mtype2unresolved = new HashMap[MClass, Set[MType]]
for mtype in self.runtime_type_analysis.live_types do
- var set = new HashSet[MType]
+ var mclass = mtype.mclass
+ var set = mtype2unresolved.get_or_null(mclass)
+ if set == null then
+ set = new HashSet[MType]
+ mtype2unresolved[mclass] = set
+ end
for cd in mtype.collect_mclassdefs(self.mainmodule) do
if self.live_unresolved_types.has_key(cd) then
set.add_all(self.live_unresolved_types[cd])
end
end
- mtype2unresolved[mtype] = set
end
# Compute the table layout with the prefered method
- var colorer = new BucketsColorer[MType, MType]
+ var colorer = new BucketsColorer[MClass, MType]
+
opentype_colors = colorer.colorize(mtype2unresolved)
- resolution_tables = self.build_resolution_tables(mtype2unresolved)
+ resolution_tables = self.build_resolution_tables(self.runtime_type_analysis.live_types, mtype2unresolved)
# Compile a C constant for each collected unresolved type.
# Either to a color, or to -1 if the unresolved type is dead (no live receiver can require it)
#print ""
end
- fun build_resolution_tables(elements: Map[MClassType, Set[MType]]): Map[MClassType, Array[nullable MType]] do
+ fun build_resolution_tables(elements: Set[MClassType], map: Map[MClass, Set[MType]]): Map[MClassType, Array[nullable MType]] do
var tables = new HashMap[MClassType, Array[nullable MType]]
- for mclasstype, mtypes in elements do
+ for mclasstype in elements do
+ var mtypes = map[mclasstype.mclass]
var table = new Array[nullable MType]
for mtype in mtypes do
var color = opentype_colors[mtype]
var mtype = mclass.intro.bound_mtype
var c_name = mclass.c_name
- var vft = self.method_tables[mclass]
- var attrs = self.attr_tables[mclass]
var v = new_visitor
var rta = runtime_type_analysis
v.add_decl("const struct class class_{c_name} = \{")
v.add_decl("{self.box_kind_of(mclass)}, /* box_kind */")
v.add_decl("\{")
- for i in [0 .. vft.length[ do
+ var vft = self.method_tables.get_or_null(mclass)
+ if vft != null then for i in [0 .. vft.length[ do
var mpropdef = vft[i]
if mpropdef == null then
v.add_decl("NULL, /* empty */")
else
var res = v.new_named_var(mtype, "self")
res.is_exact = true
- v.add("{res} = nit_alloc(sizeof(struct instance) + {attrs.length}*sizeof(nitattribute_t));")
+ var attrs = self.attr_tables.get_or_null(mclass)
+ if attrs == null then
+ v.add("{res} = nit_alloc(sizeof(struct instance));")
+ else
+ v.add("{res} = nit_alloc(sizeof(struct instance) + {attrs.length}*sizeof(nitattribute_t));")
+ end
v.add("{res}->type = type;")
hardening_live_type(v, "type")
v.require_declaration("class_{c_name}")
v.add("{res}->class = &class_{c_name};")
- self.generate_init_attr(v, res, mtype)
- v.set_finalizer res
+ if attrs != null then
+ self.generate_init_attr(v, res, mtype)
+ v.set_finalizer res
+ end
v.add("return {res};")
end
v.add("\}")
var res = self.new_var(mtype)
if compiler.runtime_type_analysis != null and not compiler.runtime_type_analysis.live_types.has(valtype) then
self.add("/*no autobox from {value.mtype} to {mtype}: {value.mtype} is not live! */")
- self.add("PRINT_ERROR(\"Dead code executed!\\n\"); show_backtrace(1);")
+ self.add("PRINT_ERROR(\"Dead code executed!\\n\"); fatal_exit(1);")
return res
end
self.require_declaration("BOX_{valtype.c_name}")
# Bad things will appen!
var res = self.new_var(mtype)
self.add("/* {res} left unintialized (cannot convert {value.mtype} to {mtype}) */")
- self.add("PRINT_ERROR(\"Cast error: Cannot cast %s to %s.\\n\", \"{value.mtype}\", \"{mtype}\"); show_backtrace(1);")
+ self.add("PRINT_ERROR(\"Cast error: Cannot cast %s to %s.\\n\", \"{value.mtype}\", \"{mtype}\"); fatal_exit(1);")
return res
end
end
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\"); show_backtrace(1);")
+ self.add("PRINT_ERROR(\"Dead code executed!\\n\"); fatal_exit(1);")
return res
end
self.require_declaration("BOX_{valtype.c_name}")
self.add("count_type_test_resolved_{tag}++;")
end
else
- self.add("PRINT_ERROR(\"NOT YET IMPLEMENTED: type_test(%s, {mtype}).\\n\", \"{value.inspect}\"); show_backtrace(1);")
+ self.add("PRINT_ERROR(\"NOT YET IMPLEMENTED: type_test(%s, {mtype}).\\n\", \"{value.inspect}\"); fatal_exit(1);")
end
# check color is in table