[pypy-svn] r62739 - in pypy/trunk/pypy: jit/metainterp jit/metainterp/test rpython rpython/lltypesystem translator

fijal at codespeak.net fijal at codespeak.net
Sun Mar 8 23:25:40 CET 2009


Author: fijal
Date: Sun Mar  8 23:25:39 2009
New Revision: 62739

Modified:
   pypy/trunk/pypy/jit/metainterp/support.py
   pypy/trunk/pypy/jit/metainterp/test/test_exception.py
   pypy/trunk/pypy/jit/metainterp/test/test_zrpy_exception.py
   pypy/trunk/pypy/jit/metainterp/warmspot.py
   pypy/trunk/pypy/rpython/llinterp.py
   pypy/trunk/pypy/rpython/lltypesystem/lloperation.py
   pypy/trunk/pypy/translator/exceptiontransform.py
Log:
try to do the right thing with ExitFrameWithExc. It almost works, except for
the fact that it hits wrong exc block when run on top of x86 backend.
IN-PROGRESS


Modified: pypy/trunk/pypy/jit/metainterp/support.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/support.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/support.py	Sun Mar  8 23:25:39 2009
@@ -1,4 +1,4 @@
-from pypy.rpython.lltypesystem import lltype
+from pypy.rpython.lltypesystem import lltype, rclass
 from pypy.rpython.ootypesystem import ootype
 from pypy.rpython import rlist
 from pypy.rpython.lltypesystem import rdict, rstr
@@ -12,6 +12,7 @@
 from pypy.annotation.policy import AnnotatorPolicy
 from pypy.annotation import model as annmodel
 from pypy.rpython.annlowlevel import MixLevelHelperAnnotator
+from pypy.rpython.extregistry import ExtRegistryEntry
 
 def getargtypes(annotator, values):
     if values is None:    # for backend tests producing stand-alone exe's
@@ -221,3 +222,20 @@
     rtyper._builtin_func_for_spec_cache[key] = (c_func, LIST_OR_DICT)
     #
     return c_func, LIST_OR_DICT
+
+def raise_exc_value(tp, value):
+    from pypy.rpython.llinterp import LLException
+    raise LLException(tp, value)
+
+class Entry(ExtRegistryEntry):
+    _about_ = raise_exc_value
+
+    def compute_result_annotation(self, s_tp, s_value):
+        return annmodel.s_ImpossibleValue
+
+    def specialize_call(self, hop):
+        v_list = [hop.inputarg(hop.args_r[0], arg=0),
+                  hop.inputarg(hop.args_r[1], arg=1)]
+        hop.has_implicit_exception(Exception)
+        hop.exception_is_here()
+        return hop.genop('raise_exc_value', v_list)

Modified: pypy/trunk/pypy/jit/metainterp/test/test_exception.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/test/test_exception.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/test/test_exception.py	Sun Mar  8 23:25:39 2009
@@ -321,6 +321,31 @@
         res = self.interp_operations(f, [1, 2])
         assert res == 1
 
+
+    def test_reraise_through_portal(self):
+        jitdriver = JitDriver(greens = [], reds = ['n'])
+
+        class SomeException(Exception):
+            pass
+        
+        def portal(n):
+            while n > 0:
+                jitdriver.can_enter_jit(n=n)
+                jitdriver.jit_merge_point(n=n)
+                if n == 10:
+                    raise SomeException
+                n -= 1
+
+        def f(n):
+            try:
+                portal(n)
+            except SomeException, e:
+                return 3
+            return 2
+
+        res = self.meta_interp(f, [100])
+        assert res == 3
+
 class MyError(Exception):
     def __init__(self, n):
         self.n = n

Modified: pypy/trunk/pypy/jit/metainterp/test/test_zrpy_exception.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/test/test_zrpy_exception.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/test/test_zrpy_exception.py	Sun Mar  8 23:25:39 2009
@@ -1,7 +1,7 @@
 import py
 from pypy.jit.metainterp.test import test_exception
 from pypy.jit.metainterp.test.test_zrpy_basic import LLInterpJitMixin
-
+from pypy.rlib.jit import JitDriver
 
 class TestLLExceptions(test_exception.ExceptionTests, LLInterpJitMixin):
     def interp_operations(self, *args, **kwds):
@@ -14,6 +14,5 @@
     def test_raise_through_wrong_exc(self): skip1()
     def test_raise_through_wrong_exc_2(self): skip1()
 
-
 def skip1():
     py.test.skip("the portal always raises, causing blocked blocks")

Modified: pypy/trunk/pypy/jit/metainterp/warmspot.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/warmspot.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/warmspot.py	Sun Mar  8 23:25:39 2009
@@ -10,6 +10,7 @@
 from pypy.rlib.unroll import unrolling_iterable
 from pypy.rlib.jit import PARAMETERS
 from pypy.rlib.rarithmetic import r_uint
+from pypy.rpython.lltypesystem.lloperation import llop
 
 from pypy.jit.metainterp import support, history, pyjitpl
 from pypy.jit.metainterp.pyjitpl import OOMetaInterp, Options
@@ -304,13 +305,9 @@
                     return unwrap(RESULT, e.resultbox)
                 except ExitFrameWithException, e:
                     value = e.valuebox.getptr(lltype.Ptr(rclass.OBJECT))
-                    if we_are_translated():
-                        # re-raise the exception as it is
-                        raise Exception, value
-                    else:
-                        type = e.typebox.getaddr(self.metainterp.cpu)
-                        type = llmemory.cast_adr_to_ptr(type, rclass.CLASSTYPE)
-                        raise LLException(type, value)
+                    type = e.typebox.getaddr(self.metainterp.cpu)
+                    type = llmemory.cast_adr_to_ptr(type, rclass.CLASSTYPE)
+                    support.raise_exc_value(type, value)
 
         portal_runner_ptr = self.helper_func(lltype.Ptr(PORTALFUNC),
                                              ll_portal_runner)

Modified: pypy/trunk/pypy/rpython/llinterp.py
==============================================================================
--- pypy/trunk/pypy/rpython/llinterp.py	(original)
+++ pypy/trunk/pypy/rpython/llinterp.py	Sun Mar  8 23:25:39 2009
@@ -1181,6 +1181,9 @@
     def op_oohash(self, s):
         return ootype.oohash(s)
 
+    def op_raise_exc_value(self, etype, evalue):
+        raise LLException(etype, evalue)
+
 class Tracer(object):
     Counter = 0
     file = None

Modified: pypy/trunk/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/trunk/pypy/rpython/lltypesystem/lloperation.py	(original)
+++ pypy/trunk/pypy/rpython/lltypesystem/lloperation.py	Sun Mar  8 23:25:39 2009
@@ -397,6 +397,7 @@
     'promote_virtualizable':LLOp(canrun=True),
     'get_exception_addr':   LLOp(),
     'get_exc_value_addr':   LLOp(),
+    'raise_exc_value'   :   LLOp(canraise=(Exception,)),
 
     # __________ GC operations __________
 

Modified: pypy/trunk/pypy/translator/exceptiontransform.py
==============================================================================
--- pypy/trunk/pypy/translator/exceptiontransform.py	(original)
+++ pypy/trunk/pypy/translator/exceptiontransform.py	Sun Mar  8 23:25:39 2009
@@ -199,15 +199,18 @@
                 block.operations[i].opname = "direct_call"
                 block.operations[i].args = [self.rpyexc_fetch_exception_ptr]
 
-            if opname == 'gc_restore_exception':
+            elif opname == 'gc_restore_exception':
                 block.operations[i].opname = "direct_call"
                 block.operations[i].args.insert(0, self.rpyexc_restore_exception_ptr)
-            if opname == 'get_exception_addr':    # only for lltype
+            elif opname == 'get_exception_addr':    # only for lltype
                 block.operations[i].opname = "direct_call"
                 block.operations[i].args.insert(0, self.rpyexc_get_exception_addr_ptr)
-            if opname == 'get_exc_value_addr':    # only for lltype
+            elif opname == 'get_exc_value_addr':    # only for lltype
                 block.operations[i].opname = "direct_call"
                 block.operations[i].args.insert(0, self.rpyexc_get_exc_value_addr_ptr)
+            elif opname == 'raise_exc_value':
+                block.operations[i].opname = 'direct_call'
+                block.operations[i].args.insert(0, self.rpyexc_raise_ptr)
 
     def transform_block(self, graph, block):
         need_exc_matching = False



More information about the Pypy-commit mailing list