[pypy-svn] r27181 - in pypy/dist/pypy: rpython rpython/memory rpython/module translator/stackless translator/stackless/test
pedronis at codespeak.net
pedronis at codespeak.net
Sat May 13 18:04:20 CEST 2006
Author: pedronis
Date: Sat May 13 18:04:18 2006
New Revision: 27181
Modified:
pypy/dist/pypy/rpython/extfunctable.py
pypy/dist/pypy/rpython/memory/gctransform.py
pypy/dist/pypy/rpython/module/ll_stack.py
pypy/dist/pypy/rpython/rstack.py
pypy/dist/pypy/translator/stackless/code.py
pypy/dist/pypy/translator/stackless/test/test_depth.py
pypy/dist/pypy/translator/stackless/transform.py
Log:
reusing stack_unwind to return a value was a bad idea, it breaks assumption for the non-stackless and refcounting code.
introudce stack_capture instead.
Modified: pypy/dist/pypy/rpython/extfunctable.py
==============================================================================
--- pypy/dist/pypy/rpython/extfunctable.py (original)
+++ pypy/dist/pypy/rpython/extfunctable.py Sat May 13 18:04:18 2006
@@ -250,7 +250,8 @@
declare(rstack.stack_frames_depth, int, 'll_stackless/stack_frames_depth')
declare(rstack.stack_too_big, bool, 'll_stack/too_big')
declare(rstack.stack_check, noneannotation, 'll_stack/check')
-declare(rstack.stack_unwind, rstack.frame_stack_top, 'll_stack/unwind')
+declare(rstack.stack_unwind, noneannotation, 'll_stack/unwind')
+declare(rstack.stack_capture, rstack.frame_stack_top, 'll_stack/capture')
frametop_type_info = declaregcptrtype(rstack.frame_stack_top,'frame_stack_top',
switch = (rstack.frame_stack_top,
'll_stackless/switch'),
Modified: pypy/dist/pypy/rpython/memory/gctransform.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gctransform.py (original)
+++ pypy/dist/pypy/rpython/memory/gctransform.py Sat May 13 18:04:18 2006
@@ -1152,7 +1152,7 @@
use_stackless = True
def build_stack_root_iterator(self):
- from pypy.rpython.rstack import stack_unwind
+ from pypy.rpython.rstack import stack_capture
sizeofaddr = llmemory.sizeof(llmemory.Address)
gcdata = self.gcdata
@@ -1184,7 +1184,7 @@
return gcdata.static_roots[i]
if self.provide_current_frame:
self.provide_current_frame = False
- frame = stack_unwind()
+ frame = stack_capture()
return llmemory.cast_ptr_to_adr(frame)
return llmemory.NULL
Modified: pypy/dist/pypy/rpython/module/ll_stack.py
==============================================================================
--- pypy/dist/pypy/rpython/module/ll_stack.py (original)
+++ pypy/dist/pypy/rpython/module/ll_stack.py Sat May 13 18:04:18 2006
@@ -5,9 +5,13 @@
ll_stack_too_big.suggested_primitive = True
def ll_stack_unwind():
- return rstack.stack_unwind()
+ rstack.stack_unwind()
ll_stack_unwind.suggested_primitive = True
+def ll_stack_capture():
+ return rstack.stack_capture()
+ll_stack_capture.suggested_primitive = True
+
def ll_stack_check():
if ll_stack_too_big():
ll_stack_unwind()
Modified: pypy/dist/pypy/rpython/rstack.py
==============================================================================
--- pypy/dist/pypy/rpython/rstack.py (original)
+++ pypy/dist/pypy/rpython/rstack.py Sat May 13 18:04:18 2006
@@ -8,6 +8,9 @@
def stack_unwind():
raise RuntimeError("cannot unwind stack in non-translated versions")
+def stack_capture():
+ raise RuntimeError("cannot unwind stack in non-translated versions")
+
def stack_frames_depth():
return len(inspect.stack())
Modified: pypy/dist/pypy/translator/stackless/code.py
==============================================================================
--- pypy/dist/pypy/translator/stackless/code.py (original)
+++ pypy/dist/pypy/translator/stackless/code.py Sat May 13 18:04:18 2006
@@ -154,6 +154,28 @@
else:
# STATE 0: now the stack is unwound. That was the goal.
# Return to caller.
+ global_state.top = frame.null_state
+ global_state.restart_substate = -1
+
+ll_stack_unwind.stackless_explicit = True
+
+INDEX_UNWIND = frame.RestartInfo.add_prebuilt(ll_stack_unwind,
+ [EMPTY_STATE])
+
+# ____________________________________________________________
+
+def ll_stack_capture():
+ if global_state.restart_substate == -1:
+ # normal entry point for stack_frames_depth()
+ # first unwind the stack in the usual way
+ u = UnwindException()
+ s = lltype.malloc(EMPTY_STATE).header
+ s.f_restart = INDEX_CAPTURE
+ add_frame_state(u, s)
+ raise u # goes to STATE 0 below
+ else:
+ # STATE 0: now the stack is unwound. That was the goal.
+ # Return to caller.
cur = global_state.top
global_state.top = frame.null_state
global_state.restart_substate = -1
@@ -161,10 +183,10 @@
# The StacklessFrameworkGCTransformer uses this for introspection.
return lltype.cast_opaque_ptr(frame.OPAQUE_STATE_HEADER_PTR,
cur.f_back)
-ll_stack_unwind.stackless_explicit = True
+ll_stack_capture.stackless_explicit = True
-INDEX_UNWIND = frame.RestartInfo.add_prebuilt(ll_stack_unwind,
- [EMPTY_STATE])
+INDEX_CAPTURE = frame.RestartInfo.add_prebuilt(ll_stack_capture,
+ [EMPTY_STATE])
# ____________________________________________________________
Modified: pypy/dist/pypy/translator/stackless/test/test_depth.py
==============================================================================
--- pypy/dist/pypy/translator/stackless/test/test_depth.py (original)
+++ pypy/dist/pypy/translator/stackless/test/test_depth.py Sat May 13 18:04:18 2006
@@ -88,9 +88,9 @@
res = run_stackless_function(fn)
assert res == 15
-def test_stack_unwind_retval():
+def test_stack_capture():
def fn():
- frame = rstack.stack_unwind()
+ frame = rstack.stack_capture()
return int(bool(frame))
res = llinterp_stackless_function(fn)
Modified: pypy/dist/pypy/translator/stackless/transform.py
==============================================================================
--- pypy/dist/pypy/translator/stackless/transform.py (original)
+++ pypy/dist/pypy/translator/stackless/transform.py Sat May 13 18:04:18 2006
@@ -112,7 +112,7 @@
def analyze_external_call(self, op):
callable = op.args[0].value._obj._callable
#assert getattr(callable, 'suggested_primitive', False)
- return callable in [ll_stack.ll_stack_unwind,
+ return callable in [ll_stack.ll_stack_unwind, ll_stack.ll_stack_capture,
ll_stackless.ll_stackless_stack_frames_depth,
ll_stackless.ll_stackless_switch]
@@ -195,8 +195,12 @@
code.ll_frame_clone, [s_StatePtr], s_StatePtr),
ll_stack.ll_stack_unwind:
mixlevelannotator.constfunc(
- code.ll_stack_unwind, [], s_StatePtr),
+ code.ll_stack_unwind, [], annmodel.s_None),
+ ll_stack.ll_stack_capture:
+ mixlevelannotator.constfunc(
+ code.ll_stack_capture, [], s_StatePtr),
}
+
self.yield_current_frame_to_caller_ptr = mixlevelannotator.constfunc(
code.yield_current_frame_to_caller, [], s_StatePtr)
More information about the Pypy-commit
mailing list