[pypy-svn] r60930 - in pypy/trunk/pypy/lang/prolog/interpreter: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Tue Jan 13 17:47:36 CET 2009


Author: cfbolz
Date: Tue Jan 13 17:47:35 2009
New Revision: 60930

Removed:
   pypy/trunk/pypy/lang/prolog/interpreter/test/test_jit.py
Modified:
   pypy/trunk/pypy/lang/prolog/interpreter/engine.py
   pypy/trunk/pypy/lang/prolog/interpreter/term.py
Log:
Kill JIT hints, as the new JIT will need different hacks (had this in my
checkout for a while).


Modified: pypy/trunk/pypy/lang/prolog/interpreter/engine.py
==============================================================================
--- pypy/trunk/pypy/lang/prolog/interpreter/engine.py	(original)
+++ pypy/trunk/pypy/lang/prolog/interpreter/engine.py	Tue Jan 13 17:47:35 2009
@@ -3,9 +3,7 @@
 from pypy.lang.prolog.interpreter.error import UnificationFailed, FunctionNotFound, \
     CutException
 from pypy.lang.prolog.interpreter import error
-from pypy.rlib.jit import hint, we_are_jitted, _is_early_constant, purefunction
-from pypy.rlib.objectmodel import specialize
-from pypy.rlib.unroll import unrolling_iterable
+from pypy.rlib.jit import purefunction
 
 DEBUG = False
 
@@ -90,11 +88,8 @@
         #import pdb;pdb.set_trace()
         while self:
             uh = self.rule.unify_hash
-            hint(uh, concrete=True)
-            uh = hint(uh, deepfreeze=True)
             j = 0
             while j < len(uh):
-                hint(j, concrete=True)
                 hash1 = uh[j]
                 hash2 = uh2[j]
                 if hash1 != 0 and hash2 * (hash2 - hash1) != 0:
@@ -139,9 +134,6 @@
         self.signature2function = {}
         self.parser = None
         self.operations = None
-        #XXX circular imports hack
-        from pypy.lang.prolog.builtin import builtins_list
-        globals()['unrolling_builtins'] = unrolling_iterable(builtins_list) 
 
     def add_rule(self, rule, end=True):
         from pypy.lang.prolog import builtin
@@ -162,11 +154,8 @@
         if signature in builtin.builtins:
             error.throw_permission_error(
                 "modify", "static_procedure", rule.head.get_prolog_signature())
-        function = self.signature2function.get(signature, None)
-        if function is not None:
-            self.signature2function[signature].add_rule(rule, end)
-        else:
-            self.signature2function[signature] = Function(rule)
+        function = self._lookup(signature)
+        function.add_rule(rule, end)
 
     def run(self, query, continuation=DONOTHING):
         if not isinstance(query, Callable):
@@ -197,16 +186,6 @@
         return self.main_loop(CALL, query, continuation)
 
     def _call(self, query, continuation):
-        signature = query.signature
-        from pypy.lang.prolog.builtin import builtins
-        builtins = hint(builtins, deepfreeze=True)
-        signature = hint(signature, promote=True)
-        for bsig, builtin in unrolling_builtins:
-            if signature == bsig:
-                return builtin.call(self, query, continuation)
-        return self.user_call(query, continuation, choice_point=False)
-
-    def _opaque_call(self, query, continuation):
         from pypy.lang.prolog.builtin import builtins
         signature = query.signature
         builtin = builtins.get(signature, None)
@@ -217,32 +196,27 @@
 
     def main_loop(self, where, query, continuation, rule=None):
         next = (DONE, None, None, None)
-        hint(where, concrete=True)
-        hint(rule, concrete=True)
         while 1:
             if where == DONE:
                 return next
             next = self.dispatch_bytecode(where, query, continuation, rule)
             where, query, continuation, rule = next
-            where = hint(where, promote=True)
 
     def dispatch_bytecode(self, where, query, continuation, rule):
         if where == CALL:
             next = self._call(query, continuation)
         elif where == TRY_RULE:
-            rule = hint(rule, promote=True)
             next = self._try_rule(rule, query, continuation)
         elif where == USER_CALL:
             next = self._user_call(query, continuation)
         elif where == CONTINUATION:
-            hint(continuation.__class__, promote=True)
             next = continuation._call(self)
         else:
             raise Exception("unknown bytecode")
         return next
 
     @purefunction
-    def _jit_lookup(self, signature):
+    def _lookup(self, signature):
         signature2function = self.signature2function
         function = signature2function.get(signature, None)
         if function is None:
@@ -255,10 +229,9 @@
         return self.main_loop(USER_CALL, query, continuation)
 
     def _user_call(self, query, continuation):
-        signature = hint(query.signature, promote=True)
-        function = self._jit_lookup(signature)
+        signature = query.signature
+        function = self._lookup(signature)
         startrulechain = function.rulechain
-        startrulechain = hint(startrulechain, promote=True)
         if startrulechain is None:
             error.throw_existence_error(
                 "procedure", query.get_prolog_signature())
@@ -277,7 +250,6 @@
                 choice_point = rulechain is not None
             else:
                 choice_point = False
-            hint(rule, concrete=True)
             if rule.contains_cut:
                 continuation = LimitedScopeContinuation(continuation)
                 try:
@@ -292,13 +264,11 @@
                                                        continuation)
                     raise
             else:
-                inline = rule.body is None # inline facts
                 try:
                     # for the last rule (rulechain is None), this will always
-                    # return, because choice_point is False
+                    # return immediately, because choice_point is False
                     result = self.try_rule(rule, query, continuation,
-                                           choice_point=choice_point,
-                                           inline=inline)
+                                           choice_point=choice_point)
                     self.heap.discard(oldstate)
                     return result
                 except UnificationFailed:
@@ -307,48 +277,12 @@
             rule = rulechain.rule
             rulechain = rulechain.next
 
-    def try_rule(self, rule, query, continuation=DONOTHING, choice_point=True,
-                 inline=False):
+    def try_rule(self, rule, query, continuation=DONOTHING, choice_point=True):
         if not choice_point:
             return (TRY_RULE, query, continuation, rule)
-        if not we_are_jitted():
-            return self.portal_try_rule(rule, query, continuation, choice_point)
-        if inline:
-            return self.main_loop(TRY_RULE, query, continuation, rule)
-        #if _is_early_constant(rule):
-        #    rule = hint(rule, promote=True)
-        #    return self.portal_try_rule(rule, query, continuation, choice_point)
-        return self._opaque_try_rule(rule, query, continuation, choice_point)
-
-    def _opaque_try_rule(self, rule, query, continuation, choice_point):
-        return self.portal_try_rule(rule, query, continuation, choice_point)
-
-    def portal_try_rule(self, rule, query, continuation, choice_point):
-        hint(None, global_merge_point=True)
-        hint(choice_point, concrete=True)
-        if not choice_point:
-            return self._try_rule(rule, query, continuation)
-        where = TRY_RULE
-        next = (DONE, None, None, None)
-        hint(where, concrete=True)
-        hint(rule, concrete=True)
-        signature = hint(query.signature, promote=True)
-        while 1:
-            hint(None, global_merge_point=True)
-            if where == DONE:
-                return next
-            if rule is not None:
-                assert rule.signature == signature
-            next = self.dispatch_bytecode(where, query, continuation, rule)
-            where, query, continuation, rule = next
-            rule = hint(rule, promote=True)
-            if query is not None:
-                signature = hint(query.signature, promote=True)
-            where = hint(where, promote=True)
+        return self.main_loop(TRY_RULE, query, continuation, rule)
 
     def _try_rule(self, rule, query, continuation):
-        rule = hint(rule, deepfreeze=True)
-        hint(self, concrete=True)
         # standardizing apart
         nextcall = rule.clone_and_unify_head(self.heap, query)
         if nextcall is not None:

Modified: pypy/trunk/pypy/lang/prolog/interpreter/term.py
==============================================================================
--- pypy/trunk/pypy/lang/prolog/interpreter/term.py	(original)
+++ pypy/trunk/pypy/lang/prolog/interpreter/term.py	Tue Jan 13 17:47:35 2009
@@ -4,9 +4,7 @@
 from pypy.rlib.rarithmetic import intmask
 from pypy.lang.prolog.interpreter.error import UnificationFailed, UncatchableError
 from pypy.lang.prolog.interpreter import error
-from pypy.rlib.jit import hint
 from pypy.rlib.objectmodel import specialize
-from pypy.rlib.jit import we_are_jitted, hint, purefunction
 
 DEBUG = False
 
@@ -116,7 +114,6 @@
         self.binding = value
 
     def copy(self, heap, memo):
-        hint(self, concrete=True)
         try:
             return memo[self]
         except KeyError:
@@ -124,8 +121,6 @@
             return newvar
 
     def copy_and_unify(self, other, heap, memo):
-        hint(self, concrete=True)
-        self = hint(self, deepfreeze=True)
         try:
             seen_value = memo[self]
         except KeyError:
@@ -242,7 +237,6 @@
         return self
 
     def copy_and_basic_unify(self, other, heap, memo):
-        hint(self, concrete=True)
         if isinstance(other, Atom) and (self is other or
                                         other.name == self.name):
             return self
@@ -250,8 +244,7 @@
             raise UnificationFailed
 
     def get_unify_hash(self, heap):
-        name = hint(self.name, promote=True)
-        return intmask(hash(name) << TAGBITS | self.TAG)
+        return intmask(hash(self.name) << TAGBITS | self.TAG)
 
     def unify_hash_of_children(self, heap):
         return []
@@ -260,7 +253,6 @@
         return Term("/", [self, NUMBER_0])
 
     @staticmethod
-    @purefunction
     def newatom(name):
         result = Atom.cache.get(name, None)
         if result is not None:
@@ -294,7 +286,6 @@
         return self
 
     def copy_and_basic_unify(self, other, heap, memo):
-        hint(self, concrete=True)
         if isinstance(other, Number) and other.num == self.num:
             return self
         else:
@@ -331,7 +322,6 @@
         return self
 
     def copy_and_basic_unify(self, other, heap, memo):
-        hint(self, concrete=True)
         if isinstance(other, Float) and other.floatval == self.floatval:
             return self
         else:
@@ -374,7 +364,6 @@
         return self
 
     def copy_and_basic_unify(self, other, heap, memo):
-        hint(self, concrete=True)
         if self is other:
             return self
         else:
@@ -422,26 +411,20 @@
             raise UnificationFailed
 
     def copy(self, heap, memo):
-        hint(self, concrete=True)
-        self = hint(self, deepfreeze=True)
         newargs = []
         i = 0
         while i < len(self.args):
-            hint(i, concrete=True)
             arg = self.args[i].copy(heap, memo)
             newargs.append(arg)
             i += 1
         return Term(self.name, newargs, self.signature)
 
     def copy_and_basic_unify(self, other, heap, memo):
-        hint(self, concrete=True)
-        self = hint(self, deepfreeze=True)
         if (isinstance(other, Term) and
             self.signature == other.signature):
             newargs = [None] * len(self.args)
             i = 0
             while i < len(self.args):
-                hint(i, concrete=True)
                 arg = self.args[i].copy_and_unify(other.args[i], heap, memo)
                 newargs[i] = arg
                 i += 1
@@ -467,8 +450,7 @@
             return self
 
     def get_unify_hash(self, heap):
-        signature = hint(self.signature, promote=True)
-        return intmask(hash(signature) << TAGBITS | self.TAG)
+        return intmask(hash(self.signature) << TAGBITS | self.TAG)
 
     def unify_hash_of_children(self, heap):
         unify_hash = []
@@ -489,15 +471,7 @@
         
     def eval_arithmetic(self, engine):
         from pypy.lang.prolog.interpreter.arithmetic import arithmetic_functions
-        from pypy.lang.prolog.interpreter.arithmetic import arithmetic_functions_list
-        if we_are_jitted():
-            signature = hint(self.signature, promote=True)
-            func = None
-            for sig, func in arithmetic_functions_list:
-                if sig == signature:
-                    break
-        else:
-            func = arithmetic_functions.get(self.signature, None)
+        func = arithmetic_functions.get(self.signature, None)
         if func is None:
             error.throw_type_error("evaluable", self.get_prolog_signature())
         return func(engine, self)
@@ -537,18 +511,15 @@
     def clone_and_unify_head(self, heap, head):
         memo = {}
         h2 = self.head
-        hint(h2, concrete=True)
         if isinstance(h2, Term):
             assert isinstance(head, Term)
             i = 0
             while i < len(h2.args):
-                i = hint(i, concrete=True)
                 arg2 = h2.args[i]
                 arg1 = head.args[i]
                 arg2.copy_and_unify(arg1, heap, memo)
                 i += 1
         body = self.body
-        hint(body, concrete=True)
         if body is None:
             return None
         return body.copy(heap, memo)



More information about the Pypy-commit mailing list