[pypy-svn] r42249 - in pypy/dist/pypy/lang/prolog/interpreter: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Sun Apr 22 23:17:14 CEST 2007


Author: cfbolz
Date: Sun Apr 22 23:17:13 2007
New Revision: 42249

Modified:
   pypy/dist/pypy/lang/prolog/interpreter/term.py
   pypy/dist/pypy/lang/prolog/interpreter/test/test_unification.py
Log:
a BlackBox Prolog object that unifies by identity and is meant to be subclassed
for specific purposes.


Modified: pypy/dist/pypy/lang/prolog/interpreter/term.py
==============================================================================
--- pypy/dist/pypy/lang/prolog/interpreter/term.py	(original)
+++ pypy/dist/pypy/lang/prolog/interpreter/term.py	Sun Apr 22 23:17:13 2007
@@ -319,6 +319,29 @@
     def __repr__(self):
         return "Float(%r)" % (self.num, )
 
+class BlackBox(NonVar):
+    # meant to be subclassed
+    TAG = tag()
+    STANDARD_ORDER = 4
+    @specialize.arg(3)
+    def basic_unify(self, other, heap, occurs_check=False):
+        if self is other:
+            return
+        raise UnificationFailed
+
+    def copy(self, heap, memo):
+        return self
+
+    def copy_and_basic_unify(self, other, heap, memo):
+        hint(self, concrete=True)
+        if self is other:
+            return self
+        else:
+            raise UnificationFailed
+
+    def get_unify_hash(self, heap=None):
+        return intmask(id(self) << TAGBITS | self.TAG)
+
 
 # helper functions for various Term methods
 

Modified: pypy/dist/pypy/lang/prolog/interpreter/test/test_unification.py
==============================================================================
--- pypy/dist/pypy/lang/prolog/interpreter/test/test_unification.py	(original)
+++ pypy/dist/pypy/lang/prolog/interpreter/test/test_unification.py	Sun Apr 22 23:17:13 2007
@@ -1,6 +1,6 @@
 import py
 from pypy.lang.prolog.interpreter.error import UnificationFailed
-from pypy.lang.prolog.interpreter.term import Atom, Var, Number, Term, Rule
+from pypy.lang.prolog.interpreter.term import Atom, Var, Number, Term, BlackBox
 from pypy.lang.prolog.interpreter.engine import Heap, Engine
 
 def test_atom():
@@ -51,6 +51,13 @@
     assert X.getvalue(heap).name == "HALLO"
     assert Y.getvalue(heap).name == "hallo"
 
+def test_blackbox():
+    bl1 = BlackBox()
+    bl2 = BlackBox()
+    heap = Heap()
+    bl1.unify(bl1, heap)
+    py.test.raises(UnificationFailed, bl1.unify, bl2, heap)
+
 def test_run():
     e = Engine()
     e.add_rule(Term("f", [Atom.newatom("a"), Atom.newatom("b")]))



More information about the Pypy-commit mailing list