Carl Friedrich Bolz  committed f7a52b9

add an intermediate AbstractBindingVar. This is necessary so that BindingVar is
a final class

  • Participants
  • Parent commits fc2fcd0
  • Branches minimal-specialization

Comments (0)

Files changed (1)

File prolog/interpreter/

         assert isinstance(other, Var)
         return rcmp(compute_unique_id(self), compute_unique_id(other))
-class BindingVar(Var):
+class AbstractBindingVar(Var):
     __slots__ = ("binding", "created_after_choice_point")
     def __init__(self):
                 self.setvalue(other, heap)
             next._unify_derefed(other, heap, occurs_check)
+class BindingVar(AbstractBindingVar):
+    def dereference(self, heap):
+        next = self.binding
+        if next is None:
+            return self
+        else:
+            result = next.dereference(heap)
+            if result is not next and heap is not None:
+                # do path compression
+                self.setvalue(result, heap)
+            return result
 class VarInTerm(Var):
     def __init__(self, parent):
     def get_attname_at_index(self, index):
         return self.attnames_in_order[index]
-class AttVar(BindingVar):
+class AttVar(AbstractBindingVar):
     attmap = AttMap()
     def __init__(self):
-        BindingVar.__init__(self)
+        AbstractBindingVar.__init__(self)
         self.value_list = debug.make_sure_not_resized([])
     def setvalue(self, value, heap):
         if self.value_list is not None:
-        BindingVar.setvalue(self, value, heap)
+        AbstractBindingVar.setvalue(self, value, heap)
     def __repr__(self):
         attrs = []
     def get_prolog_signature(self):
         return self.signature().get_prolog_signature()
     def arguments(self):
         argcount = self.argument_count()
         result = [None] * argcount