[pypy-svn] r74094 - in pypy/branch/blackhole-improvement/pypy/jit/codewriter: . test

fijal at codespeak.net fijal at codespeak.net
Tue Apr 27 04:47:40 CEST 2010


Author: fijal
Date: Tue Apr 27 04:47:39 2010
New Revision: 74094

Modified:
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/flatten.py
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_flatten.py
Log:
Write down a first test for exceptions. Incredible algorithmic knowledge
needed for string comparison


Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/flatten.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/flatten.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/flatten.py	Tue Apr 27 04:47:39 2010
@@ -1,4 +1,4 @@
-from pypy.objspace.flow.model import Variable, Constant
+from pypy.objspace.flow.model import Variable, Constant, c_last_exception
 from pypy.jit.metainterp.history import AbstractDescr, getkind
 from pypy.rpython.lltypesystem import lltype
 
@@ -158,6 +158,29 @@
             self.emitline(Label(linkfalse))
             self.make_link(linkfalse)
         #
+        elif block.exitswitch is c_last_exception:
+            # An exception block. Would create something like:
+            # if exception jump first check
+            # defaultcase
+            # if not exc_1 jmp next check
+            # exc_1 case
+            # if not exc_2 jmp next check
+            # exc_2 case
+            # reraise
+            assert block.exits[0].exitcase is None # is this always True?
+            self.emitline('goto_if_exception', TLabel(block.exits[0]))
+            self.make_link(block.exits[0])
+            self.emitline(Label(block.exits[0]))
+            for link in block.exits[1:]:
+                if (link.exitcase is Exception and link.target.operations == ()
+                    and len(link.target.inputargs) == 2):
+                    # default exit-by-exception block
+                    self.emitline("reraise")
+                else:
+                    self.emitline('goto_if_exception_mismatch',
+                                  Constant(link.llexitcase), TLabel(link))
+                    self.make_link(link)
+                    self.emitline(Label(link))
         else:
             # A switch.
             #

Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_flatten.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_flatten.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_flatten.py	Tue Apr 27 04:47:39 2010
@@ -53,9 +53,45 @@
         self.assert_format(ssarepr, expected)
 
     def assert_format(self, ssarepr, expected):
+        def replace_struct(s):
+            """ Replace all $<* struct ...> with $STRUCT
+            """
+            while True:
+                i = s.find('$<* struct')
+                if i == -1:
+                    return s
+                count = 1
+                start = i
+                i += 2
+                while True:
+                    if s[i] == '<':
+                        count += 1
+                    if s[i] == '>':
+                        count -= 1
+                        if count == 0:
+                            break
+                    i += 1
+                s = s[:start] + '$STRUCT' + s[i + 1:]
+        
         asm = format_assembler(ssarepr)
         expected = str(py.code.Source(expected)).strip() + '\n'
-        assert asm == expected
+        asmlines = asm.split("\n")
+        explines = expected.split("\n")
+        for asm, exp in zip(asmlines, explines):
+            asm = replace_struct(asm)
+            if asm != exp:
+                print
+                print "Got:      " + asm
+                print "Expected: " + exp
+                lgt = 0
+                for i in range(len(asm)):
+                    if exp[i] == asm[i]:
+                        lgt += 1
+                    else:
+                        break
+                print "          " + " " * lgt + "^^^^"
+                raise AssertionError
+        assert len(asmlines) == len(explines)
 
     def test_simple(self):
         def f(n):
@@ -204,12 +240,8 @@
         """)
 
     def test_exc_exitswitch(self):
-        py.test.skip("not implemented")
         def g(i):
-            if i == 2:
-                raise ValueError
-            elif i == 3:
-                raise KeyError
+            pass
         
         def f(i):
             try:
@@ -222,4 +254,15 @@
                 return 3
 
         self.encoding_test(f, [65], """
+        direct_call $<* fn g>, %i0
+        goto_if_exception L1
+        int_return $3
+        L1:
+        goto_if_exception_mismatch $STRUCT, L2
+        int_return $1
+        L2:
+        goto_if_exception_mismatch $STRUCT, L3
+        int_return $2
+        L3:
+        reraise
         """)



More information about the Pypy-commit mailing list