Carl Friedrich Bolz avatar Carl Friedrich Bolz committed f7a52b9

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

Comments (0)

Files changed (1)

prolog/interpreter/term.py

         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([])
 
     @specialize.arg(3)
     def setvalue(self, value, heap):
         if self.value_list is not None:
             heap.add_hook(self)
-        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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.