[pypy-svn] r52091 - in pypy/branch/jit-refactoring/pypy/jit/rainbow: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Mon Mar 3 15:27:21 CET 2008


Author: cfbolz
Date: Mon Mar  3 15:27:15 2008
New Revision: 52091

Modified:
   pypy/branch/jit-refactoring/pypy/jit/rainbow/codewriter.py
   pypy/branch/jit-refactoring/pypy/jit/rainbow/interpreter.py
   pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_2tl.py
   pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_interpreter.py
Log:
fix tiny2 tests by moving the collect_split call into the callee. This is more
natural anyway and less code.


Modified: pypy/branch/jit-refactoring/pypy/jit/rainbow/codewriter.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/rainbow/codewriter.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/rainbow/codewriter.py	Mon Mar  3 15:27:15 2008
@@ -835,15 +835,11 @@
             self.emit(*emitted_args)
             setdescindex = self.indirectcalldesc_position(targets)
             self.emit(fnptrindex, setdescindex)
-
-            if kind == "red":
-                self.emit("red_after_direct_call")
-            elif kind == "yellow":
-                self.emit("yellow_after_direct_call")
+            if kind == "yellow":
                 self.emit("yellow_retrieve_result_as_red")
                 self.emit(self.type_position(op.result.concretetype))
-            elif kind == "gray":
-                self.emit("red_after_direct_call")
+            elif kind in ("gray", "red"):
+                pass
             else:
                 assert 0, "unknown call kind %s" % (kind, )
 
@@ -957,7 +953,6 @@
 
         if kind == "red":
             self.register_redvar(op.result)
-        self.emit("red_after_direct_call")
     
     def handle_gray_call(self, op, withexc):
         return self.handle_red_call(op, withexc, "gray")
@@ -972,7 +967,6 @@
         self.emit("yellow_direct_call")
         self.emit(*emitted_args)
         self.emit(graphindex)
-        self.emit("yellow_after_direct_call")
         self.emit("yellow_retrieve_result")
         self.register_greenvar(op.result)
 

Modified: pypy/branch/jit-refactoring/pypy/jit/rainbow/interpreter.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/rainbow/interpreter.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/rainbow/interpreter.py	Mon Mar  3 15:27:15 2008
@@ -271,7 +271,14 @@
                     assert 0, "unknown graph color %s" % (graph_color, )
 
                 self.newjitstate(newjitstate)
-                if self.frame is None:
+                if self.frame is not None:
+                    newjitstate = rtimeshift.collect_split(
+                        self.jitstate, self.frame.pc,
+                        self.frame.local_green)
+                    assert newjitstate.frame.bytecode is self.frame.bytecode
+                    assert newjitstate.frame.pc == self.frame.pc
+                    self.newjitstate(newjitstate)
+                else:
                     if frame.backframe is not None:
                         frame = frame.backframe
                         queue = frame.dispatchqueue
@@ -526,11 +533,10 @@
     def opimpl_red_direct_call(self, greenargs, redargs, targetbytecode):
         self.run(self.jitstate, targetbytecode, greenargs, redargs,
                  start_bytecode_loop=False)
-        # this frame will be resumed later in the next bytecode, which is
-        # red_after_direct_call
 
-    @arguments()
-    def opimpl_red_after_direct_call(self):
+    @arguments("green_varargs", "red_varargs")
+    def opimpl_portal_call(self, greenargs, redargs):
+        self.portalstate.portal_reentry(greenargs, redargs)
         newjitstate = rtimeshift.collect_split(
             self.jitstate, self.frame.pc,
             self.frame.local_green)
@@ -538,10 +544,6 @@
         assert newjitstate.frame.pc == self.frame.pc
         self.newjitstate(newjitstate)
 
-    @arguments("green_varargs", "red_varargs")
-    def opimpl_portal_call(self, greenargs, redargs):
-        self.portalstate.portal_reentry(greenargs, redargs)
-
     @arguments("green", "calldesc", "green_varargs")
     def opimpl_green_call(self, fnptr_gv, calldesc, greenargs):
         calldesc.green_call(self, fnptr_gv, greenargs)
@@ -550,8 +552,6 @@
     def opimpl_yellow_direct_call(self, greenargs, redargs, targetbytecode):
         self.run(self.jitstate, targetbytecode, greenargs, redargs,
                  start_bytecode_loop=False)
-        # this frame will be resumed later in the next bytecode, which is
-        # yellow_after_direct_call
 
     @arguments("green_varargs", "red_varargs", "red", "indirectcalldesc")
     def opimpl_indirect_call_const(self, greenargs, redargs,
@@ -562,13 +562,6 @@
         self.run(self.jitstate, bytecode, greenargs, redargs,
                  start_bytecode_loop=False)
 
-    @arguments()
-    def opimpl_yellow_after_direct_call(self):
-        newjitstate = rtimeshift.collect_split(
-            self.jitstate, self.frame.pc,
-            self.frame.local_green)
-        assert newjitstate is self.jitstate
-
     @arguments(returns="green")
     def opimpl_yellow_retrieve_result(self):
         # XXX all this jitstate.greens business is a bit messy

Modified: pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_2tl.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_2tl.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_2tl.py	Mon Mar  3 15:27:15 2008
@@ -25,4 +25,4 @@
 
         res = self.timeshift_from_portal(main, tiny2.interpret, [0, 5, 0, 0],
                                          policy=MyHintAnnotatorPolicy())
-        assert res == "5 4 3 2 1"
+        assert "".join(res.chars._obj.items) == "5 4 3 2 1"

Modified: pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_interpreter.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_interpreter.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_interpreter.py	Mon Mar  3 15:27:15 2008
@@ -533,6 +533,49 @@
         self.check_insns({'int_gt': 1, 'int_add': 1,
                           'int_sub': 1, 'int_mul': 1})
 
+    def test_call_5(self):
+        def ll_two(x):
+            if x > 0:
+                return x + 5
+            else:
+                return x - 4
+        def ll_function(y):
+            if y > 2:
+                return ll_two(y) * y
+            else:
+                return ll_two(y + 3) * y
+
+        res = self.interpret(ll_function, [3], [])
+        assert res == 24
+        self.check_insns({'int_gt': 3, 'int_add': 3,
+                          'int_sub': 2, 'int_mul': 2})
+
+        res = self.interpret(ll_function, [-3], [])
+        assert res == 12
+        self.check_insns({'int_gt': 3, 'int_add': 3,
+                          'int_sub': 2, 'int_mul': 2})
+
+    def test_call_6(self):
+        def ll_two(x):
+            if x > 0:
+                return x + 5
+            else:
+                return x - 4
+        def ll_function(y):
+            if y > 2:
+                y -= 2
+            return ll_two(y) * y
+
+        res = self.interpret(ll_function, [3], [])
+        assert res == 6
+        self.check_insns({'int_gt': 2, 'int_add': 1,
+                          'int_sub': 2, 'int_mul': 1})
+
+        res = self.interpret(ll_function, [-3], [])
+        assert res == 21
+        self.check_insns({'int_gt': 2, 'int_add': 1,
+                          'int_sub': 2, 'int_mul': 1})
+
     def test_void_call(self):
         def ll_do_nothing(x):
             pass



More information about the Pypy-commit mailing list