# resolution_tables is used to perform a type resolution at runtime in O(1)
private fun compute_resolution_tables(mtypes: Set[MType]) do
# During the visit of the body of classes, live_unresolved_types are collected
# and associated to
# 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[MClass, Set[MType]]
for mtype in self.runtime_type_analysis.live_types do
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
end
# Compute the table layout with the prefered method
var colorer = new BucketsColorer[MClass, MType]
opentype_colors = colorer.colorize(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)
var all_unresolved = new HashSet[MType]
for t in self.live_unresolved_types.values do
all_unresolved.add_all(t)
end
var all_unresolved_types_colors = new HashMap[MType, Int]
for t in all_unresolved do
if opentype_colors.has_key(t) then
all_unresolved_types_colors[t] = opentype_colors[t]
else
all_unresolved_types_colors[t] = -1
end
end
self.compile_color_consts(all_unresolved_types_colors)
#print "tables"
#for k, v in unresolved_types_tables.as(not null) do
# print "{k}: {v.join(", ")}"
#end
#print ""
end
src/compiler/separate_compiler.nit:558,2--607,4