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

cfbolz at codespeak.net cfbolz at codespeak.net
Fri Feb 1 14:11:25 CET 2008


Author: cfbolz
Date: Fri Feb  1 14:11:24 2008
New Revision: 51177

Modified:
   pypy/branch/jit-refactoring/pypy/jit/rainbow/bytecode.py
   pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_interpreter.py
Log:
first test with a green switch passes


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	Fri Feb  1 14:11:24 2008
@@ -102,7 +102,11 @@
         self.frame.pc = target
 
     def opimpl_green_goto_iftrue(self):
-        XXX
+        genconst = self.get_greenarg()
+        target = self.load_4byte()
+        arg = genconst.revealconst(lltype.Bool)
+        if arg:
+            self.frame.pc = target
 
     def opimpl_red_goto_iftrue(self):
         XXX
@@ -115,7 +119,10 @@
         return STOP
 
     def opimpl_green_return(self):
-        XXX
+        rtimeshift.save_return(self.jitstate)
+        newstate = rtimeshift.leave_graph_yellow(self.queue)
+        self.jitstate = newstate
+        return STOP
         return STOP # XXX wrong, of course
 
     def opimpl_make_new_redvars(self):
@@ -154,12 +161,13 @@
         numargs = unrolling_iterable(range(opdesc.nb_args))
         if color == "green":
             def implementation(self):
-                args = ()
+                args = (opdesc.RESULT, )
                 for i in numargs:
                     genconst = self.get_greenarg()
-                    arg = self.jitstate.curbuilder.revealconst(opdesc.ARGS[i])
+                    arg = genconst.revealconst(opdesc.ARGS[i])
                     args += (arg, )
-                result = opdesc.llop(*args)
+                rgenop = self.jitstate.curbuilder.rgenop
+                result = rgenop.genconst(opdesc.llop(*args))
                 self.green_result(result)
         elif color == "red":
             if opdesc.nb_args == 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	Fri Feb  1 14:11:24 2008
@@ -11,6 +11,7 @@
 from pypy.rpython.lltypesystem import lltype, rstr
 from pypy.rpython.llinterp import LLInterpreter
 from pypy.annotation import model as annmodel
+from pypy.rlib.jit import hint
 from pypy import conftest
 
 def getargtypes(annotator, values):
@@ -79,7 +80,9 @@
         ARGS = []
         for var in self.graph.getargs():
             # XXX ignoring virtualizables for now
-            ARGS.append(originalconcretetype(self.hannotator.binding(var)))
+            binding = self.hannotator.binding(var)
+            if not binding.is_green():
+                ARGS.append(originalconcretetype(binding))
         FUNC = lltype.FuncType(ARGS, RESTYPE)
         sigtoken = rgenop.sigToken(FUNC)
         builder, gv_generated, inputargs_gv = rgenop.newgraph(sigtoken, "generated")
@@ -106,7 +109,7 @@
         i = 0
         for color, ll_val in zip(argcolors, values):
             if color == "green":
-                greenargs.append(writer.RGenOp.constPrebuiltGlobal(const.value))
+                greenargs.append(writer.RGenOp.constPrebuiltGlobal(ll_val))
             else:
                 TYPE = lltype.typeOf(ll_val)
                 kind = rgenop.kindToken(TYPE)
@@ -136,5 +139,16 @@
         res = self.interpret(f, [1, 2])
         assert res == 3
 
+    def test_green_switch(self):
+        def f(green, x, y):
+            green = hint(green, concrete=True)
+            if green:
+                return x + y
+            return x - y
+        res = self.interpret(f, [1, 1, 2])
+        assert res == 3
+        res = self.interpret(f, [0, 1, 2])
+        assert res == -1
+
 class TestLLType(AbstractInterpretationTest):
     type_system = "lltype"



More information about the Pypy-commit mailing list