X-Git-Url: http://nitlanguage.org diff --git a/src/layout_builders.nit b/src/layout_builders.nit index 0254210..56ee306 100644 --- a/src/layout_builders.nit +++ b/src/layout_builders.nit @@ -51,28 +51,6 @@ interface PropertyLayoutBuilder[E: MProperty] fun build_layout(elements: Set[MClass]): Layout[E] is abstract end -# Layout builder for MProperty using Coloring (CL) -class CLPropertyLayoutBuilder[E: MProperty] - super PropertyLayoutBuilder[E] - - private var colorer: MPropertyColorer[E] - - init(colorer: MPropertyColorer[E]) do - self.colorer = colorer - end - - # Compute mclasses ids and position using BM - redef fun build_layout(mclasses) do - return self.colorer.build_layout(mclasses) - end -end - -# Layout builder for MProperty using Perfect Hashing (PH) -# TODO implement this class without sublcassing CL builder -class PHPropertyLayoutBuilder[E: MProperty] - super CLPropertyLayoutBuilder[E] -end - interface ResolutionLayoutBuilder # Build resolution table layout fun build_layout(elements: Map[MClassType, Set[MType]]): Layout[MType] is abstract @@ -148,6 +126,71 @@ class ResolutionBMizer end end +# Abstract BMizing for MProperties +abstract class MPropertyBMizer[E: MProperty] + super PropertyLayoutBuilder[E] + + type MPROP: MProperty + + var mmodule: MModule + + init(mmodule: MModule) do self.mmodule = mmodule + + redef fun build_layout(elements) do + var result = new Layout[E] + var ids = new HashMap[E, Int] + var lin = linearize_mclasses(elements) + for mclass in lin do + for mproperty in properties(mclass) do + if ids.has_key(mproperty) then continue + ids[mproperty] = ids.length + end + end + result.pos = ids + return result + end + + private fun properties(mclass: MClass): Set[E] do + var properties = new HashSet[E] + for mprop in self.mmodule.properties(mclass) do + if mprop isa MPROP then properties.add(mprop) + end + return properties + end + + private fun linearize_mclasses(mclasses: Set[MClass]): Array[MClass] is abstract +end + +# BMizing for MMethods +class MMethodBMizer + super MPropertyBMizer[MMethod] + + redef type MPROP: MMethod + init(mmodule: MModule) do super(mmodule) + # Less holes in tables with reverse linearization for method tables + redef fun linearize_mclasses(mclasses) do return self.mmodule.reverse_linearize_mclasses(mclasses) +end + +# BMizing for MMAttributes +class MAttributeBMizer + super MPropertyBMizer[MAttribute] + + redef type MPROP: MAttribute + init(mmodule: MModule) do super(mmodule) + # Less holes in tables with linearization for attribute tables + redef fun linearize_mclasses(mclasses) do return self.mmodule.linearize_mclasses_2(mclasses) +end + +# BMizing for MVirtualTypeProps +class MVirtualTypePropBMizer + super MPropertyBMizer[MVirtualTypeProp] + + redef type MPROP: MVirtualTypeProp + init(mmodule: MModule) do super(mmodule) + # Less holes in tables with reverse linearization for method tables + redef fun linearize_mclasses(mclasses) do return self.mmodule.reverse_linearize_mclasses(mclasses) +end + # Colorers abstract class TypingColorer[E: Object] @@ -325,7 +368,7 @@ class MClassColorer fun parent_elements(element: MClass): Set[MClass] do return self.mmodule.parent_mclasses(element) redef fun is_element_mi(element, elements) do return self.parent_elements(element).length > 1 redef fun sub_elements(element, elements) do do return self.mmodule.sub_mclasses(element) - redef fun linearize(elements) do return self.mmodule.linearize_mclasses(elements) + redef fun linearize(elements) do return self.mmodule.linearize_mclasses_2(elements) redef fun reverse_linearize(elements) do return self.mmodule.reverse_linearize_mclasses(elements) end @@ -333,6 +376,8 @@ end abstract class MPropertyColorer[E: MProperty] super PropertyLayoutBuilder[E] + type MPROP: MProperty + private var mmodule: MModule private var class_colorer: MClassColorer private var coloration_result: Map[E, Int] = new HashMap[E, Int] @@ -410,52 +455,37 @@ abstract class MPropertyColorer[E: MProperty] end # Filter properties - private fun properties(mclass: MClass): Set[E] is abstract + private fun properties(mclass: MClass): Set[E] do + var properties = new HashSet[E] + for mprop in self.mmodule.properties(mclass) do + if mprop isa MPROP then properties.add(mprop) + end + return properties + end end # Coloring for MMethods class MMethodColorer super MPropertyColorer[MMethod] + redef type MPROP: MMethod init(mmodule: MModule) do super - - redef fun properties(mclass) do - var properties = new HashSet[MMethod] - for mprop in self.mmodule.properties(mclass) do - if mprop isa MMethod then properties.add(mprop) - end - return properties - end end # Coloring for MMAttributes class MAttributeColorer super MPropertyColorer[MAttribute] + redef type MPROP: MAttribute init(mmodule: MModule) do super - - redef fun properties(mclass) do - var properties = new HashSet[MAttribute] - for mprop in self.mmodule.properties(mclass) do - if mprop isa MAttribute then properties.add(mprop) - end - return properties - end end # Coloring for MVirtualTypeProps class MVirtualTypePropColorer super MPropertyColorer[MVirtualTypeProp] + redef type MPROP: MVirtualTypeProp init(mmodule: MModule) do super - - redef fun properties(mclass) do - var properties = new HashSet[MVirtualTypeProp] - for mprop in self.mmodule.properties(mclass) do - if mprop isa MVirtualTypeProp then properties.add(mprop) - end - return properties - end end # Colorer for type resolution table @@ -680,6 +710,12 @@ class MClassHasher end end +# Layout builder for MProperty using Perfect Hashing (PH) +# TODO implement this class without sublcassing CL builder +class MPropertyHasher[E: MProperty] + super MPropertyColorer[E] +end + class ResolutionHasher super PerfectHasher[MClassType, MType] super ResolutionLayoutBuilder @@ -704,4 +740,4 @@ class ResolutionHasher result.hashes = self.compute_hashes(elements, ids, result.masks) return result end -end \ No newline at end of file +end