[pypy-svn] r63712 - in pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp: . test
arigo at codespeak.net
arigo at codespeak.net
Mon Apr 6 12:47:17 CEST 2009
Author: arigo
Date: Mon Apr 6 12:47:16 2009
New Revision: 63712
Modified:
pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/compile.py
pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/pyjitpl.py
pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/test/test_exception.py
Log:
The same with exceptions instead of returns.
Note that this may put Consts in FAIL operations...
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/compile.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/compile.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/compile.py Mon Apr 6 12:47:16 2009
@@ -122,16 +122,15 @@
resultbox = fail_op.args[0]
raise metainterp.DoneWithThisFrame(resultbox)
-#XXX later:
-#class ExitFrameWithExceptionDescr(AbstractDescr):
-# def handle_fail_op(self, metainterp, fail_op):
-# typebox = fail_op.args[0]
-# valuebox = fail_op.args[1]
-# raise metainterp.ExitFrameWithException(typebox, valuebox)
+class ExitFrameWithExceptionDescr(AbstractDescr):
+ def handle_fail_op(self, metainterp, fail_op):
+ typebox = fail_op.args[0]
+ valuebox = fail_op.args[1]
+ raise metainterp.ExitFrameWithException(typebox, valuebox)
done_with_this_frame_descr_0 = DoneWithThisFrameDescr0()
done_with_this_frame_descr_1 = DoneWithThisFrameDescr1()
-#exit_frame_with_exception_descr = ExitFrameWithExceptionDescr()
+exit_frame_with_exception_descr = ExitFrameWithExceptionDescr()
map_loop2descr = {}
# pseudo-loops to make the life of optimize.py easier
@@ -153,11 +152,12 @@
loops_done_with_this_frame_void = [_loop]
map_loop2descr[_loop] = done_with_this_frame_descr_0
-#loop_exit_frame_with_exception = TreeLoop('exit_frame_with_exception')
-#loop_exit_frame_with_exception.specnodes = [NotSpecNode(), NotSpecNode()]
-#loop_exit_frame_with_exception.inputargs = [BoxInt(), BoxPtr()]
-#loops_exit_frame_with_exception = [loop_exit_frame_with_exception]
-#map_loop2descr[loop_exit_frame_with_exception]=exit_frame_with_exception_descr
+_loop = TreeLoop('exit_frame_with_exception')
+_loop.specnodes = [NotSpecNode(), NotSpecNode()]
+_loop.inputargs = [BoxInt(), BoxPtr()]
+loops_exit_frame_with_exception = [_loop]
+map_loop2descr[_loop] = exit_frame_with_exception_descr
+del _loop
class ResumeGuardDescr(AbstractDescr):
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/pyjitpl.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/pyjitpl.py Mon Apr 6 12:47:16 2009
@@ -783,9 +783,8 @@
if not we_are_translated():
self._debug_history.append(['leave_exc', frame.jitcode, None])
self.framestack.pop()
- #XXX later:
- #if not isinstance(self.history, history..BlackHole):
- # self.compile_exit_frame_with_exception(exceptionbox, excvaluebox)
+ if not isinstance(self.history, history.BlackHole):
+ self.compile_exit_frame_with_exception(exceptionbox, excvaluebox)
raise self.ExitFrameWithException(exceptionbox, excvaluebox)
def create_empty_history(self):
@@ -999,6 +998,13 @@
target_loop = compile.compile_new_bridge(self, loops, self.resumekey)
assert target_loop is loops[0]
+ def compile_exit_frame_with_exception(self, typebox, valuebox):
+ # temporarily put a JUMP to a pseudo-loop
+ self.history.record(rop.JUMP, [typebox, valuebox], None)
+ loops = compile.loops_exit_frame_with_exception
+ target_loop = compile.compile_new_bridge(self, loops, self.resumekey)
+ assert target_loop is loops[0]
+
def get_residual_args(self, loop, args):
if loop.specnodes is None: # it is None only for tests
return args
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/test/test_exception.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/test/test_exception.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/test/test_exception.py Mon Apr 6 12:47:16 2009
@@ -362,6 +362,31 @@
res = self.meta_interp(f, [100])
assert res == 3
+ def test_bridge_from_interpreter_exc(self):
+ mydriver = JitDriver(reds = ['n'], greens = [])
+
+ def f(n):
+ while n > 0:
+ mydriver.can_enter_jit(n=n)
+ mydriver.jit_merge_point(n=n)
+ n -= 2
+ raise MyError(n)
+ def main(n):
+ try:
+ f(n)
+ except MyError, e:
+ return e.n
+
+ res = self.meta_interp(main, [41], repeat=7)
+ assert res == -1
+ self.check_tree_loop_count(2) # the loop and the entry path
+ # we get:
+ # ENTER - compile the new loop
+ # ENTER (BlackHole) - leave
+ # ENTER - compile the entry bridge
+ # ENTER - compile the leaving path (raising MyError)
+ self.check_enter_count(4)
+
class MyError(Exception):
def __init__(self, n):
self.n = n
More information about the Pypy-commit
mailing list