# 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]
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
# 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]
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]
end
end
+# Layout builder for typing tables based on types using Binary Matrix (BM)
class MClassBMizer
super TypingBMizer[MClass]
end
end
-# Abstract BMizing for MProperties
+# Abstract Layout builder for mproperties using Binary Matrix (BM)
abstract class MPropertyBMizer[E: MProperty]
super PropertyLayoutBuilder[E]
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
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]
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]
# Colorers
+# Abstract Layout builder for typing table using coloration (CL)
abstract class TypingColorer[E: Object]
super TypingLayoutBuilder[E]
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]
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]
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]
end
end
-# Coloring for MMethods
+# Layout builder for vft using coloration (CL)
class MMethodColorer
super MPropertyColorer[MMethod]
init(mmodule: MModule) do super
end
-# Coloring for MMAttributes
+# Layout builder for attributes using coloration (CL)
class MAttributeColorer
super MPropertyColorer[MAttribute]
init(mmodule: MModule) do super
end
-# Coloring for MVirtualTypeProps
+# Layout builder for virtual types using coloration (CL)
class MVirtualTypePropColorer
super MPropertyColorer[MVirtualTypeProp]
init(mmodule: MModule) do super
end
-# Colorer for type resolution table
+# Layout builder for resolution tables using coloration (CL)
class ResolutionColorer
super ResolutionLayoutBuilder
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
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
# Abstract operator used for perfect hashing
abstract class PHOperator
+ # hash `id` using `mask`
fun op(mask: Int, id:Int): Int is abstract
end
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]
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]
end
end
+# Layout builder for typing tables with classes using perfect hashing (PH)
class MClassHasher
super TypingHasher[MClass]
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]
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
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]
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]
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]
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