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

cfbolz at codespeak.net cfbolz at codespeak.net
Sat Feb 2 17:01:36 CET 2008


Author: cfbolz
Date: Sat Feb  2 17:01:35 2008
New Revision: 51214

Modified:
   pypy/branch/jit-refactoring/pypy/jit/rainbow/bytecode.py
   pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_interpreter.py
   pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_serializegraph.py
Log:
two tests about loops and a small bug fix


Modified: pypy/branch/jit-refactoring/pypy/jit/rainbow/bytecode.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/rainbow/bytecode.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/rainbow/bytecode.py	Sat Feb  2 17:01:35 2008
@@ -322,7 +322,7 @@
             self.emit(index)
         elif len(block.exits) == 1:
             link, = block.exits
-            self.insert_renaming(link.args)
+            self.insert_renaming(link)
             self.make_bytecode_block(link.target, insert_goto=True)
         elif len(block.exits) == 2:
             linkfalse, linktrue = block.exits
@@ -333,10 +333,10 @@
             self.emit("%s_goto_iftrue" % color)
             self.emit(index)
             self.emit(tlabel(linktrue))
-            self.insert_renaming(linkfalse.args)
+            self.insert_renaming(linkfalse)
             self.make_bytecode_block(linkfalse.target, insert_goto=True)
             self.emit(label(linktrue))
-            self.insert_renaming(linktrue.args)
+            self.insert_renaming(linktrue)
             self.make_bytecode_block(linktrue.target, insert_goto=True)
         else:
             XXX
@@ -365,8 +365,8 @@
         self.emit(num)
         self.emit(keyindex)
 
-    def insert_renaming(self, args):
-        reds, greens = self.sort_by_color(args)
+    def insert_renaming(self, link):
+        reds, greens = self.sort_by_color(link.args, link.target.inputargs)
         for color, args in [("red", reds), ("green", greens)]:
             result = []
             for v in args:

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	Sat Feb  2 17:01:35 2008
@@ -193,5 +193,16 @@
         res = self.interpret(f, [1, 2, 3])
         assert res == 0
 
+    def test_loop_merging(self):
+        def ll_function(x, y):
+            tot = 0
+            while x:
+                tot += y
+                x -= 1
+            return tot
+        res = self.interpret(ll_function, [7, 2])
+        assert res == 14
+
+
 class TestLLType(AbstractInterpretationTest):
     type_system = "lltype"

Modified: pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_serializegraph.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_serializegraph.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_serializegraph.py	Sat Feb  2 17:01:35 2008
@@ -170,5 +170,34 @@
         assert len(jitcode.constants) == 1
         assert len(jitcode.typekinds) == 1
 
+    def test_loop(self):
+        def f(x):
+            r = 0
+            while x:
+                r += x
+                x -= 1
+            return r
+        writer, jitcode = self.serialize(f, [int])
+        expected = assemble(writer.interpreter,
+                            "make_redbox", -1, 0,
+                            "make_new_redvars", 2, 0, 1,
+                            "make_new_greenvars", 0,
+                            label("while"),
+                            "merge", 0, -1, 
+                            "red_int_is_true", 0,
+                            "red_goto_iftrue", 2, tlabel("body"),
+                            "make_new_redvars", 1, 0,
+                            "make_new_greenvars", 0,
+                            "red_return", 0,
+                            label("body"),
+                            "make_new_redvars", 2, 0, 1,
+                            "make_new_greenvars", 0,
+                            "red_int_add", 1, 0,
+                            "make_redbox", -2, 0,
+                            "red_int_sub", 0, 3,
+                            "make_new_redvars", 2, 2, 4,
+                            "goto", tlabel("while"))
+
+
 class TestLLType(AbstractSerializationTest):
     type_system = "lltype"



More information about the Pypy-commit mailing list