layout_builders: Added comments & documentation
authorAlexandre Terrasa <alexandre@moz-code.org>
Mon, 11 Mar 2013 21:41:19 +0000 (17:41 -0400)
committerJean Privat <jean@pryen.org>
Mon, 15 Jul 2013 18:21:25 +0000 (14:21 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/layout_builders.nit

index fa0eaf3..f8dc94c 100644 (file)
 # limitations under the License.
 
 # Table layout builders
+# Tables are used to implement objects mecanisms like:
+#   * message sending
+#      * attribute accessing
+#      * typing
+#      * resolution (for generic types)
+# This module provides various layout for object tables:
+#      * coloring
+#      * binary matrix
+#      * perfect hashing (and & mod operators)
 module layout_builders
 
 import abstract_compiler
 
 # Layouts
 
+# A layout is the result of computation by builders
+# it contains necessary informations for basic table creation
 class Layout[E: Object]
        # Ids or each element
        var ids: Map[E, Int] = new HashMap[E, Int]
@@ -26,6 +37,8 @@ class Layout[E: Object]
        var pos: Map[E, Int] = new HashMap[E, Int]
 end
 
+# A PHLayout is used everywere the builder used perfect hashing
+# it adds masks and hashes informations to std layout
 class PHLayout[HOLDER: Object, E: Object]
        super Layout[E]
        # Masks used by hash function
@@ -36,23 +49,30 @@ end
 
 # Builders
 
+# TypingLayoutBuilder is used to build a layout for typing tables (by type or by class)
 interface TypingLayoutBuilder[E: Object]
        # Build typing table layout
+       # elements: the set of elements (classes or types) used in typing tables
        fun build_layout(elements: Set[E]): Layout[E] is abstract
 end
 
+# Layout builder dedicated to vft, attribute & VT tables
 interface PropertyLayoutBuilder[E: MProperty]
        # Build table layout for attributes, methods and virtual types
+       # elements: the set of classes containing the properties to use in table layout
        fun build_layout(elements: Set[MClass]): Layout[E] is abstract
 end
 
+# For resolution tables (generics)
 interface ResolutionLayoutBuilder
        # Build resolution table layout
+       # elements: association between classes and resolved types
        fun build_layout(elements: Map[MClassType, Set[MType]]): Layout[MType] is abstract
 end
 
 # Matrice computers
 
+# Abstract layout builder for resolution tables using Binary Matrix (BM)
 abstract class TypingBMizer[E: Object]
        super TypingLayoutBuilder[E]
 
@@ -78,6 +98,7 @@ abstract class TypingBMizer[E: Object]
        private fun reverse_linearize(elements: Set[E]): Array[E] is abstract
 end
 
+# Layout builder for typing tables based on classes using Binary Matrix (BM)
 class MTypeBMizer
        super TypingBMizer[MType]
 
@@ -88,6 +109,7 @@ class MTypeBMizer
        end
 end
 
+# Layout builder for typing tables based on types using Binary Matrix (BM)
 class MClassBMizer
        super TypingBMizer[MClass]
 
@@ -121,7 +143,7 @@ class ResolutionBMizer
        end
 end
 
-# Abstract BMizing for MProperties
+# Abstract Layout builder for mproperties using Binary Matrix (BM)
 abstract class MPropertyBMizer[E: MProperty]
        super PropertyLayoutBuilder[E]
 
@@ -145,6 +167,7 @@ abstract class MPropertyBMizer[E: MProperty]
                return result
        end
 
+       # extract properties of a mclass
        private fun properties(mclass: MClass): Set[E] do
                var properties = new HashSet[E]
                for mprop in self.mmodule.properties(mclass) do
@@ -156,7 +179,7 @@ abstract class MPropertyBMizer[E: MProperty]
        private fun linearize_mclasses(mclasses: Set[MClass]): Array[MClass] is abstract
 end
 
-# BMizing for MMethods
+# Layout builder for vft using Binary Matrix (BM)
 class MMethodBMizer
        super MPropertyBMizer[MMethod]
 
@@ -166,7 +189,7 @@ class MMethodBMizer
        redef fun linearize_mclasses(mclasses) do return self.mmodule.reverse_linearize_mclasses(mclasses)
 end
 
-# BMizing for MMAttributes
+# Layout builder for attribute tables using Binary Matrix (BM)
 class MAttributeBMizer
        super MPropertyBMizer[MAttribute]
 
@@ -188,6 +211,7 @@ end
 
 # Colorers
 
+# Abstract Layout builder for typing table using coloration (CL)
 abstract class TypingColorer[E: Object]
        super TypingLayoutBuilder[E]
 
@@ -336,7 +360,7 @@ abstract class TypingColorer[E: Object]
        private fun reverse_linearize(elements: Set[E]): Array[E] is abstract
 end
 
-# MType coloring
+# Layout builder for typing tables based on types using coloration (CL)
 class MTypeColorer
        super TypingColorer[MType]
 
@@ -351,7 +375,7 @@ class MTypeColorer
        redef fun reverse_linearize(elements) do return self.mmodule.reverse_linearize_mtypes(elements)
 end
 
-# MClass coloring
+# Layout builder for typing tables based on classes using coloration (CL)
 class MClassColorer
        super TypingColorer[MClass]
 
@@ -367,7 +391,7 @@ class MClassColorer
        redef fun reverse_linearize(elements) do return self.mmodule.reverse_linearize_mclasses(elements)
 end
 
-# MProperty coloring
+# Abstract Layout builder for properties tables using coloration (CL)
 abstract class MPropertyColorer[E: MProperty]
        super PropertyLayoutBuilder[E]
 
@@ -459,7 +483,7 @@ abstract class MPropertyColorer[E: MProperty]
        end
 end
 
-# Coloring for MMethods
+# Layout builder for vft using coloration (CL)
 class MMethodColorer
        super MPropertyColorer[MMethod]
 
@@ -467,7 +491,7 @@ class MMethodColorer
        init(mmodule: MModule) do super
 end
 
-# Coloring for MMAttributes
+# Layout builder for attributes using coloration (CL)
 class MAttributeColorer
        super MPropertyColorer[MAttribute]
 
@@ -475,7 +499,7 @@ class MAttributeColorer
        init(mmodule: MModule) do super
 end
 
-# Coloring for MVirtualTypeProps
+# Layout builder for virtual types using coloration (CL)
 class MVirtualTypePropColorer
        super MPropertyColorer[MVirtualTypeProp]
 
@@ -483,7 +507,7 @@ class MVirtualTypePropColorer
        init(mmodule: MModule) do super
 end
 
-# Colorer for type resolution table
+# Layout builder for resolution tables using coloration (CL)
 class ResolutionColorer
        super ResolutionLayoutBuilder
 
@@ -572,6 +596,7 @@ private class PerfectHasher[T: Object, U: Object]
 
        init(operator: PHOperator) do self.operator = operator
 
+       # Compute mask for each holders
        fun compute_masks(conflicts: Map[T, Set[U]], ids: Map[U, Int]): Map[T, Int] do
                var masks = new HashMap[T, Int]
                for mclasstype, mtypes in conflicts do
@@ -598,6 +623,7 @@ private class PerfectHasher[T: Object, U: Object]
                return mask
        end
 
+       # Compute hash for each element in each holder
        fun compute_hashes(elements: Map[T, Set[U]], ids: Map[U, Int], masks: Map[T, Int]): Map[T, Map[U, Int]] do
                var hashes = new HashMap[T, Map[U, Int]]
                for mclasstype, mtypes in elements do
@@ -614,6 +640,7 @@ end
 
 # Abstract operator used for perfect hashing
 abstract class PHOperator
+       # hash `id` using `mask`
        fun op(mask: Int, id:Int): Int is abstract
 end
 
@@ -633,6 +660,7 @@ class PHAndOperator
        redef fun op(mask, id) do return mask.bin_and(id)
 end
 
+# Layout builder for typing tables using perfect hashing (PH)
 class TypingHasher[E: Object]
        super PerfectHasher[E, E]
        super TypingLayoutBuilder[E]
@@ -677,6 +705,7 @@ class TypingHasher[E: Object]
        private fun reverse_linearize(elements: Set[E]): Array[E] is abstract
 end
 
+# Layout builder for typing tables with types using perfect hashing (PH)
 class MTypeHasher
        super TypingHasher[MType]
 
@@ -691,6 +720,7 @@ class MTypeHasher
        end
 end
 
+# Layout builder for typing tables with classes using perfect hashing (PH)
 class MClassHasher
        super TypingHasher[MClass]
 
@@ -705,7 +735,7 @@ class MClassHasher
        end
 end
 
-# Abstract perfect hasher for MProperties
+# Abstract layout builder for properties tables using perfect hashing (PH)
 class MPropertyHasher[E: MProperty]
        super PerfectHasher[MClass, E]
        super PropertyLayoutBuilder[E]
@@ -739,6 +769,7 @@ class MPropertyHasher[E: MProperty]
                return result
        end
 
+       # extract set of properties from mclass
        private fun properties(mclass: MClass): Set[E] do
                var properties = new HashSet[E]
                for mprop in self.mmodule.properties(mclass) do
@@ -750,7 +781,7 @@ class MPropertyHasher[E: MProperty]
        private fun linearize_mclasses(mclasses: Set[MClass]): Array[MClass] is abstract
 end
 
-# Perfect hashing for MMethods
+# Layout builder for vft using perfect hashing (PH)
 class MMethodHasher
        super MPropertyHasher[MMethod]
 
@@ -759,7 +790,7 @@ class MMethodHasher
        redef fun linearize_mclasses(mclasses) do return self.mmodule.reverse_linearize_mclasses(mclasses)
 end
 
-# Perfect hashing for MMAttributes
+# Layout builder for attributes tables using perfect hashing (PH)
 class MAttributeHasher
        super MPropertyHasher[MAttribute]
 
@@ -768,7 +799,7 @@ class MAttributeHasher
        redef fun linearize_mclasses(mclasses) do return self.mmodule.linearize_mclasses_2(mclasses)
 end
 
-# Perfect hashing for MVirtualTypeProps
+# Layout builder for virtual types tables using perfect hashing (PH)
 class MVirtualTypePropHasher
        super MPropertyHasher[MVirtualTypeProp]
 
@@ -777,6 +808,7 @@ class MVirtualTypePropHasher
        redef fun linearize_mclasses(mclasses) do return self.mmodule.reverse_linearize_mclasses(mclasses)
 end
 
+# Layout builder for resolution tables using perfect hashing (PH)
 class ResolutionHasher
        super PerfectHasher[MClassType, MType]
        super ResolutionLayoutBuilder