nitg-s: moved resolution table building to separate_compiler
authorAlexandre Terrasa <alexandre@moz-code.org>
Fri, 8 Feb 2013 05:20:13 +0000 (00:20 -0500)
committerAlexandre Terrasa <alexandre@moz-code.org>
Mon, 4 Mar 2013 18:20:01 +0000 (13:20 -0500)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/coloring.nit
src/separate_compiler.nit

index 96be1df..f77c1d7 100644 (file)
@@ -607,25 +607,6 @@ class UnanchoredTypeColoring
                return coloration_result
        end
 
-       fun build_tables(elements: Map[MClassType, Set[MType]]): Map[MClassType, Array[nullable MType]] do
-               var tables = new HashMap[MClassType, Array[nullable MType]]
-
-               for mclasstype, mtypes in elements do
-                       var table = new Array[nullable MType]
-                       for mtype in mtypes do
-                               var color = self.coloration_result[mtype]
-                               if table.length <= color then
-                                       for i in [table.length .. color[ do
-                                               table[i] = null
-                                       end
-                               end
-                               table[color] = mtype
-                       end
-                       tables[mclasstype] = table
-               end
-               return tables
-       end
-
        # Colorize a collection of elements
        fun colorize_elements(elements: Map[MClassType, Set[MType]]) do
                var min_color = 0
@@ -731,25 +712,6 @@ abstract class UnanchoredTypePerfectHashing
                return mask
        end
 
-       redef fun build_tables(elements: Map[MClassType, Set[MType]]): Map[MClassType, Array[nullable MType]] do
-               var tables = new HashMap[MClassType, Array[nullable MType]]
-
-               for mclasstype, mtypes in elements do
-                       var table = new Array[nullable MType]
-                       for mtype in mtypes do
-                               var color = phash(self.coloration_result[mtype], masks[mclasstype])
-                               if table.length <= color then
-                                       for i in [table.length .. color[ do
-                                               table[i] = null
-                                       end
-                               end
-                               table[color] = mtype
-                       end
-                       tables[mclasstype] = table
-               end
-               return tables
-       end
-
        private fun op(mask: Int, id:Int): Int is abstract
        private fun phash(id: Int, mask: Int): Int do return op(mask, id)
 end
index f76c0d7..716dc4d 100644 (file)
@@ -411,21 +411,21 @@ class SeparateCompiler
                if modelbuilder.toolcontext.opt_bm_typing.value then
                        var unanchored_type_coloring = new NaiveUnanchoredTypeColoring
                        self.unanchored_types_colors = unanchored_type_coloring.colorize(mtype2unanchored)
-                       self.unanchored_types_tables = unanchored_type_coloring.build_tables(mtype2unanchored)
+                       self.unanchored_types_tables = self.build_resolution_tables(mtype2unanchored)
                else if modelbuilder.toolcontext.opt_phmod_typing.value then
                        var unanchored_type_coloring = new UnanchoredTypeModPerfectHashing
                        self.unanchored_types_colors = unanchored_type_coloring.colorize(mtype2unanchored)
                        self.unanchored_types_masks = unanchored_type_coloring.compute_masks(mtype2unanchored)
-                       self.unanchored_types_tables = unanchored_type_coloring.build_tables(mtype2unanchored)
+                       self.unanchored_types_tables = self.hash_resolution_tables(mtype2unanchored, unanchored_type_coloring)
                else if modelbuilder.toolcontext.opt_phand_typing.value then
                        var unanchored_type_coloring = new UnanchoredTypeAndPerfectHashing
                        self.unanchored_types_colors = unanchored_type_coloring.colorize(mtype2unanchored)
                        self.unanchored_types_masks = unanchored_type_coloring.compute_masks(mtype2unanchored)
-                       self.unanchored_types_tables = unanchored_type_coloring.build_tables(mtype2unanchored)
+                       self.unanchored_types_tables = self.hash_resolution_tables(mtype2unanchored,  unanchored_type_coloring)
                else
                        var unanchored_type_coloring = new UnanchoredTypeColoring
                        self.unanchored_types_colors = unanchored_type_coloring.colorize(mtype2unanchored)
-                       self.unanchored_types_tables = unanchored_type_coloring.build_tables(mtype2unanchored)
+                       self.unanchored_types_tables = self.build_resolution_tables(mtype2unanchored)
                end
 
                # Compile a C constant for each collected unanchored type.
@@ -451,6 +451,44 @@ class SeparateCompiler
                #print ""
        end
 
+       fun build_resolution_tables(elements: Map[MClassType, Set[MType]]): Map[MClassType, Array[nullable MType]] do
+               var tables = new HashMap[MClassType, Array[nullable MType]]
+
+               for mclasstype, mtypes in elements do
+                       var table = new Array[nullable MType]
+                       for mtype in mtypes do
+                               var color = self.unanchored_types_colors[mtype]
+                               if table.length <= color then
+                                       for i in [table.length .. color[ do
+                                               table[i] = null
+                                       end
+                               end
+                               table[color] = mtype
+                       end
+                       tables[mclasstype] = table
+               end
+               return tables
+       end
+
+       fun hash_resolution_tables(elements: Map[MClassType, Set[MType]], colorer: UnanchoredTypePerfectHashing): Map[MClassType, Array[nullable MType]] do
+               var tables = new HashMap[MClassType, Array[nullable MType]]
+
+               for mclasstype, mtypes in elements do
+                       var table = new Array[nullable MType]
+                       for mtype in mtypes do
+                               var color = colorer.phash(self.unanchored_types_colors[mtype], self.unanchored_types_masks[mclasstype])
+                               if table.length <= color then
+                                       for i in [table.length .. color[ do
+                                               table[i] = null
+                                       end
+                               end
+                               table[color] = mtype
+                       end
+                       tables[mclasstype] = table
+               end
+               return tables
+       end
+
        fun retieve_live_partial_types(mtype: MType) do
                # add formal types arguments to mtypes
                if mtype isa MGenericType then