[pypy-svn] r33939 - in pypy/dist/pypy/jit/timeshifter: . test

pedronis at codespeak.net pedronis at codespeak.net
Tue Oct 31 11:22:37 CET 2006


Author: pedronis
Date: Tue Oct 31 11:22:35 2006
New Revision: 33939

Modified:
   pypy/dist/pypy/jit/timeshifter/rtyper.py
   pypy/dist/pypy/jit/timeshifter/test/test_portal.py
Log:
(arre, pedronis)

make the portal cache really work. oops.



Modified: pypy/dist/pypy/jit/timeshifter/rtyper.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rtyper.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/rtyper.py	Tue Oct 31 11:22:35 2006
@@ -195,7 +195,11 @@
         fresh_jitstate = self.ll_fresh_jitstate
         finish_jitstate = self.ll_finish_jitstate
 
-        cache = {}
+        class PortalState(object):
+            def __init__(self):
+                self.cache = {}
+
+        state = PortalState()
         rgenop = self.RGenOp()
         def portalentry(*args):
             i = 0
@@ -207,6 +211,7 @@
                 else:
                     residualargs = residualargs + (args[i],)
                 i = i + 1
+            cache = state.cache
             try:
                 fn = cache[key]
             except KeyError:

Modified: pypy/dist/pypy/jit/timeshifter/test/test_portal.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_portal.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_portal.py	Tue Oct 31 11:22:35 2006
@@ -2,8 +2,10 @@
 from pypy.translator.translator import graphof
 from pypy.jit.timeshifter.test.test_timeshift import hannotate
 from pypy.jit.timeshifter.rtyper import HintRTyper
+from pypy.jit.timeshifter.test.test_timeshift import P_NOVIRTUAL
 from pypy.rpython.llinterp import LLInterpreter
 from pypy.objspace.flow.model import checkgraph
+from pypy.rpython.objectmodel import hint
 
 from pypy.rpython.objectmodel import hint
 
@@ -34,9 +36,10 @@
                                        policy=policy, inline=inline,
                                        backendoptimize=backendoptimize)
 
+            t = rtyper.annotator.translator
+            maingraph = graphof(t, main)
             # make the timeshifted graphs
             hrtyper = HintRTyper(ha, rtyper, self.RGenOp)
-            t = rtyper.annotator.translator
             origportalgraph = graphof(t, portal)
             hrtyper.specialize(origportalgraph=origportalgraph,
                                view = conftest.option.view)
@@ -47,7 +50,7 @@
 
             if conftest.option.view:
                 t.view()
-            maingraph = graphof(t, main)
+
             self._cache[key] = maingraph, rtyper
             self._cache_order.append(key)
 
@@ -73,3 +76,29 @@
         res = self.timeshift_from_portal(main, evaluate, [4, 7])
         assert res == 11
     
+    def test_main_as_portal(self):
+        def main(x):
+            return x
+
+        res = self.timeshift_from_portal(main, main, [42])
+        assert res == 42
+
+    def test_multiple_portal_calls(self):
+        def ll_function(n):
+            hint(None, global_merge_point=True)
+            k = n
+            if k > 5:
+                k //= 2
+            k = hint(k, promote=True)
+            k *= 17
+            return hint(k, variable=True)
+
+        res = self.timeshift_from_portal(ll_function, ll_function, [4],
+                                         policy=P_NOVIRTUAL)
+        assert res == 68
+        #self.check_insns(int_floordiv=1, int_mul=0)
+
+        res = self.timeshift_from_portal(ll_function, ll_function, [4],
+                                         policy=P_NOVIRTUAL)
+        assert res == 68
+        #self.check_insns(int_floordiv=1, int_mul=0)



More information about the Pypy-commit mailing list