[pypy-svn] r62149 - in pypy/branch/pyjitpl5/pypy/jit/metainterp: . test

arigo at codespeak.net arigo at codespeak.net
Wed Feb 25 16:54:44 CET 2009


Author: arigo
Date: Wed Feb 25 16:54:42 2009
New Revision: 62149

Modified:
   pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_basic.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/warmspot.py
Log:
Support for we_are_jitted().


Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py	Wed Feb 25 16:54:42 2009
@@ -3,6 +3,7 @@
 from pypy.objspace.flow.model import Variable, Constant, Link, c_last_exception
 from pypy.rlib import objectmodel
 from pypy.rlib.objectmodel import we_are_translated
+from pypy.rlib.jit import _we_are_jitted
 from pypy.jit.metainterp.history import Const, getkind, getkind_num
 from pypy.jit.metainterp import heaptracker, support, history
 
@@ -243,6 +244,7 @@
         """Generate a constant of the given value.
         Returns its index in the list self.positions[].
         """
+        if constvalue is _we_are_jitted: constvalue = True
         const = Const._new(constvalue, self.cpu)
         return self.get_position(const)
 

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_basic.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_basic.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_basic.py	Wed Feb 25 16:54:42 2009
@@ -1,5 +1,5 @@
 import py
-from pypy.rlib.jit import JitDriver
+from pypy.rlib.jit import JitDriver, we_are_jitted
 from pypy.jit.metainterp.warmspot import ll_meta_interp, get_stats
 from pypy.jit.backend.llgraph import runner
 from pypy.jit.metainterp import support, codewriter, pyjitpl, history
@@ -201,6 +201,22 @@
         assert res == 42
         self.check_loops(int_mul=1, int_mod=0)
 
+    def test_we_are_jitted(self):
+        myjitdriver = JitDriver(greens = [], reds = ['y'])
+        def f(y):
+            while y >= 0:
+                myjitdriver.can_enter_jit(y=y)
+                myjitdriver.jit_merge_point(y=y)
+                if we_are_jitted():
+                    x = 1
+                else:
+                    x = 10
+                y -= x
+            return y
+        assert f(55) == -5
+        res = self.meta_interp(f, [55])
+        assert res == -1
+
 
 class TestOOtype(BasicTests, OOJitMixin):
     pass

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/warmspot.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/warmspot.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/warmspot.py	Wed Feb 25 16:54:42 2009
@@ -23,9 +23,9 @@
     interp, graph = get_interpreter(function, args, backendopt=backendopt,
                                     inline_threshold=0)
     clear_tcache()
-    return jittify_and_run(interp, graph)
+    return jittify_and_run(interp, graph, args, **kwds)
 
-def jittify_and_run(interp, graph):
+def jittify_and_run(interp, graph, args, **kwds):
     translator = interp.typer.annotator.translator
     warmrunnerdesc = WarmRunnerDesc(translator, **kwds)
     warmrunnerdesc.state.set_param_threshold(3)          # for tests



More information about the Pypy-commit mailing list