Commits

Carl Friedrich Bolz committed 7c8cf00

implement a special class for ./2 terms.

Comments (0)

Files changed (3)

prolog/interpreter/specialterm.py

 
 signature.Signature.register_extr_attr("shape")
 
+conssig = signature.Signature.getsignature(".", 2)
+
 class ArgumentDescr(object):
     def compatible_with(self, obj):
         return False
     return shape
 
 def build(signature, args):
+    shape = get_shape(signature, args)
+    if signature.eq(conssig):
+        return Cons(shape, args)
     if len(args) <= len(specialized_term_classes):
-        shape = get_shape(signature, args)
         return specialized_term_classes[len(args) - 1](shape, args)
 
 def make_specialized_term_cls(n_args):
     generic_callable.__name__ = 'SpecializedGeneric'+str(n_args)
     return generic_callable
 
+specialized_term_classes = [make_specialized_term_cls(i) for i in range(1, 10)]
+
+class Cons(make_specialized_term_cls(2)):
+    def name(self):
+        return "."
+
+    def signature(self):
+        return conssig
+
+    def _make_new(self, name, signature):
+        return Cons(name, None, signature)
+
 def make_specialized_argument_descr(termcls):
     class cls(ArgumentDescr):
         def compatible_with(self, obj):
     cls.__name__ = termcls.__name__ + "ArgumentDescr"
     return cls()
 
-specialized_term_classes = [make_specialized_term_cls(i) for i in range(1, 10)]
+
 all_argument_descrs.extend([make_specialized_argument_descr(cls)
             for cls in specialized_term_classes])
 all_argument_descrs.append(make_specialized_argument_descr(term.Atom))
+all_argument_descrs.append(make_specialized_argument_descr(Cons))
 
 all_argument_descrs = unroll.unrolling_iterable(all_argument_descrs)
+

prolog/interpreter/test/test_specialized_terms.py

     a3 = specialterm.build(sig, [bar1, Number(1)])
     s3 = a3.get_shape()
     assert s1 is not s3
+
+def test_special_class_for_cons():
+    dotsig = signature.Signature.getsignature(".", 2)
+    barsig = signature.Signature.getsignature("bar", 2)
+    bar = specialterm.build(barsig, [Number(0), Number(1)])
+    dot = specialterm.build(dotsig, [Number(-1), Number(0)])
+    assert bar.__class__ is not dot.__class__
+
+    sig = signature.Signature.getsignature("f", 1)
+    a1 = specialterm.build(sig, [bar])
+    a2 = specialterm.build(sig, [dot])
+    assert a1.get_shape() is not a2.get_shape()
+

prolog/jittest/interpjit.py

 import sys
 from pypy import conftest
 class o:
-    view = False
+    view = True
     viewloops = True
 conftest.option = o
 from pypy.jit.metainterp.test.test_ajit import LLJitMixin
         t6 = parse_query_term("partition([6, 6, 6, 6, 6, 6, 66, 3, 6, 1, 2, 6, 8, 9, 0,4, 2, 5, 1, 106, 3, 6, 1, 2, 6, 8, 9, 0,4, 2, 5, 1, 10, 3, 6, 1, 2, 6, 8, 9, 0,4, 2, 5, 1, 10], 5, X, Y).")
         t7 = parse_query_term("findall(X+Y, app([X|_], [Y|_], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]), L).")
         def interp_w(c):
-            jitdriver.set_param("inlining", True)
             if c == 1:
                 t = t1
             elif c == 2:
         # XXX
         #interp_w(2)
 
-        self.meta_interp(interp_w, [2], listcomp=True, backendopt=True,
-                         listops=True)
+        self.meta_interp(interp_w, [3], listcomp=True, backendopt=True,
+                listops=True, translationoptions={"taggedpointers": True})
         #self.meta_interp(interp_w, [3], listcomp=True,
         #                 listops=True)