[pypy-svn] r25659 - in pypy/dist/pypy/translator/stackless: . test
mwh at codespeak.net
mwh at codespeak.net
Mon Apr 10 12:44:42 CEST 2006
Author: mwh
Date: Mon Apr 10 12:44:41 2006
New Revision: 25659
Modified:
pypy/dist/pypy/translator/stackless/code.py
pypy/dist/pypy/translator/stackless/test/test_transform.py
pypy/dist/pypy/translator/stackless/transform.py
Log:
(arigo, mwh)
support resuming with an exception by using a helper to read the return value
or raise as appropriate. you can't catch the excepton thus raised, however...
Modified: pypy/dist/pypy/translator/stackless/code.py
==============================================================================
--- pypy/dist/pypy/translator/stackless/code.py (original)
+++ pypy/dist/pypy/translator/stackless/code.py Mon Apr 10 12:44:41 2006
@@ -93,3 +93,8 @@
# global_state.top = None
# XXX and then insert the rtyped graph of this into functions
+def fetch_retval_long():
+ if global_state.exception:
+ raise global_state.exception
+ else:
+ return global_state.retval_long
Modified: pypy/dist/pypy/translator/stackless/test/test_transform.py
==============================================================================
--- pypy/dist/pypy/translator/stackless/test/test_transform.py (original)
+++ pypy/dist/pypy/translator/stackless/test/test_transform.py Mon Apr 10 12:44:41 2006
@@ -5,6 +5,7 @@
from pypy.translator.c import gc
from pypy.rpython.memory.gctransform import varoftype
from pypy.rpython.lltypesystem import lltype, llmemory
+from pypy.rpython import llinterp
from pypy.translator.translator import TranslationContext, graphof
from pypy.objspace.flow.model import checkgraph
from pypy.annotation import model as annmodel
@@ -74,6 +75,49 @@
assert res == 3
res = run_stackless_function(example, example, g)
assert res == "3"
+
+def test_resume_with_exception():
+ def check(x):
+ if x:
+ raise code.UnwindException
+ def g(x):
+ check(x)
+ if x:
+ raise KeyError
+ else:
+ return x + 1
+ def h(x):
+ return g(x)
+ def example(x):
+ y = h(x)
+ return y + 1
+ info = py.test.raises(
+ llinterp.LLException,
+ "llinterp_stackless_function(example, example, g, h)")
+ assert llinterp.type_name(info.value.args[0]) == 'KeyError'
+
+def test_resume_with_exception_handling():
+ py.test.skip("in progress")
+ def check(x):
+ if x:
+ raise code.UnwindException
+ def g(x):
+ check(x)
+ if x:
+ raise KeyError
+ else:
+ return x + 1
+ def h(x):
+ return g(x)
+ def example(x):
+ try:
+ y = h(x)
+ except KeyError:
+ y = -1
+ return y + 1
+ res = llinterp_stackless_function(example, example, g, h)
+ assert res == 0
+
@@ -137,7 +181,6 @@
r_list_of_strings = t.rtyper.getrepr(
t.annotator.binding(graphof(t, entry_point).startblock.inputargs[0]))
ll_list = r_list_of_strings.convert_const([''])
- from pypy.rpython.llinterp import LLInterpreter
- interp = LLInterpreter(t.rtyper)
+ interp = llinterp.LLInterpreter(t.rtyper)
res = interp.eval_graph(graphof(t, entry_point), [ll_list])
return res
Modified: pypy/dist/pypy/translator/stackless/transform.py
==============================================================================
--- pypy/dist/pypy/translator/stackless/transform.py (original)
+++ pypy/dist/pypy/translator/stackless/transform.py Mon Apr 10 12:44:41 2006
@@ -108,6 +108,14 @@
graph=resume_state_graph),
lltype.Ptr(RESUME_STATE_TYPE))
+ FETCH_RETVAL_LONG_TYPE = lltype.FuncType([], lltype.Signed)
+ fetch_retval_long_graph = mixlevelannotator.getgraph(
+ code.fetch_retval_long, [], annmodel.SomeInteger())
+ self.fetch_retval_long_ptr = model.Constant(lltype.functionptr(
+ FETCH_RETVAL_LONG_TYPE, "fetch_retval_long",
+ graph=fetch_retval_long_graph),
+ lltype.Ptr(FETCH_RETVAL_LONG_TYPE))
+
mixlevelannotator.finish()
s_global_state = bk.immutablevalue(code.global_state)
@@ -196,7 +204,7 @@
for arg in resume_point.link_to_resumption.args:
newarg = copyvar(self.translator, arg)
if arg is resume_point.var_result:
- ops.extend(self.ops_read_global_state_field(newarg, "retval_long"))
+ ops.append(model.SpaceOperation("direct_call", [self.fetch_retval_long_ptr], newarg))
else:
# frame_state_type._names[0] is 'header'
fname = model.Constant(frame_state_type._names[i+1], lltype.Void)
More information about the Pypy-commit
mailing list