[pypy-svn] r34338 - in pypy/branch/resume-point-hack/pypy/rlib: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Tue Nov 7 17:01:06 CET 2006
Author: cfbolz
Date: Tue Nov 7 17:01:04 2006
New Revision: 34338
Modified:
pypy/branch/resume-point-hack/pypy/rlib/rstack.py
pypy/branch/resume-point-hack/pypy/rlib/test/test_rstack.py
Log:
make it possible to resume into a try... finally block
Modified: pypy/branch/resume-point-hack/pypy/rlib/rstack.py
==============================================================================
--- pypy/branch/resume-point-hack/pypy/rlib/rstack.py (original)
+++ pypy/branch/resume-point-hack/pypy/rlib/rstack.py Tue Nov 7 17:01:04 2006
@@ -109,6 +109,9 @@
hop.r_result)
def resume_state_create(prevstate, label, func, *args):
+ if label == "yield_current_frame_to_caller_1":
+ assert func is None
+ XXX
return ResumeData(prevstate, label, func, *args)
def concretify_argument(hop, index):
@@ -265,6 +268,8 @@
self.local_changes = []
self.goto_after = goto_after
self.name = name
+ if isinstance(func, type(self.__init__)):
+ func = func.im_func
self.func = func
self.args = args
self.decision_stack = None
@@ -303,7 +308,7 @@
result = self.func(*dummy_args)
except Exception, e:
if self.goto_after is not None:
- print "caught something, handing it on..."
+ print "caught %s, handing it on..." % (e, )
return self.goto_after.resume(raising=e)
raise
finally:
@@ -345,7 +350,7 @@
val = HomingBlackhole()
newlocals[name] = val
if newlocals:
-# print "fixing locals", newlocals
+ print "fixing locals", newlocals
frame.f_locals.update(newlocals)
if self.fix_globals:
self.previous_globals = {}
@@ -374,6 +379,9 @@
frame.f_locals.update(dict(changes))
return self.resume_tracer
+ def switch(self):
+ return self.resume()
+
# _________________________________________________________________________
# Functions to analyze bytecode to find a way to reach resume_points
@@ -474,7 +482,7 @@
return [(target, "bool", True), (pos + 3, "bool", False)]
elif name == "JUMP_FORWARD":
return [(target, None, None)]
- elif name == "SETUP_LOOP" or name == "SETUP_EXCEPT":
+ elif name in ("SETUP_LOOP", "SETUP_FINALLY", "SETUP_EXCEPT"):
return [(pos + 3, None, None)] #XXX not sure
elif name == "FOR_ITER":
return [(target, "next", "stop")]
Modified: pypy/branch/resume-point-hack/pypy/rlib/test/test_rstack.py
==============================================================================
--- pypy/branch/resume-point-hack/pypy/rlib/test/test_rstack.py (original)
+++ pypy/branch/resume-point-hack/pypy/rlib/test/test_rstack.py Tue Nov 7 17:01:04 2006
@@ -288,6 +288,28 @@
res = resume_state_invoke(int, s)
assert res == 42
+def test_resume_in_finally_block():
+ def g(x):
+ x += 1
+ resume_point("rp0", x)
+ return x + 1
+ def f(x):
+ x = x - 1
+ try:
+ r = g(x)
+ resume_point("rp1", returns=r)
+ finally:
+ r = 42 + r
+ return r - 1
+ def example():
+ s1 = resume_state_create(None, "rp1", f)
+ s0 = resume_state_create(s1, "rp0", g, 0)
+ v2 = resume_state_invoke(int, s0)
+ return v2
+ res = example()
+ assert res == 42
+
+
def test_jump_over_for():
def f(x):
result = 0
More information about the Pypy-commit
mailing list