[pypy-svn] r26107 - in pypy/dist/pypy/translator/stackless: . test
mwh at codespeak.net
mwh at codespeak.net
Fri Apr 21 16:44:32 CEST 2006
Author: mwh
Date: Fri Apr 21 16:44:30 2006
New Revision: 26107
Added:
pypy/dist/pypy/translator/stackless/test/test_depth.py (contents, props changed)
Modified:
pypy/dist/pypy/translator/stackless/code.py
pypy/dist/pypy/translator/stackless/transform.py
Log:
add another test for the stackless transform, copied from the tests for the c
version, which required a small fix to the way i make function pointers but
pleasingly required no deep changes to the transform itself.
Modified: pypy/dist/pypy/translator/stackless/code.py
==============================================================================
--- pypy/dist/pypy/translator/stackless/code.py (original)
+++ pypy/dist/pypy/translator/stackless/code.py Fri Apr 21 16:44:30 2006
@@ -20,6 +20,7 @@
('c', llmemory.Address))
def switch(c):
+ # this is untested so far!
if not global_state.restartstate:
u = UnwindException()
s = lltype.malloc(SWITCH_STATE)
@@ -35,18 +36,24 @@
global_state.top = s.c
return top.f_back
+
+
def stack_frames_depth():
- if not global_state.restartstate:
+ if not global_state.restart_substate:
u = UnwindException()
s = lltype.malloc(STATE_HEADER)
s.restartstate = 1
- s.function = llmemory.cast_ptr_to_adr(count_stack_depth)
- s.retval_type = RETVAL_VOID
- add_frame_state(u, s.header)
+ # the next three lines are pure rtyper-pleasing hacks
+ f = stack_frames_depth
+ if global_state.restart_substate:
+ f = None
+ s.function = llmemory.cast_ptr_to_adr(f)
+ s.retval_type = RETVAL_LONG
+ add_frame_state(u, s)
raise u
else:
cur = global_state.top
- global_state.restartstate = 0
+ global_state.restart_substate = 0
depth = 0
while cur:
depth += 1
Added: pypy/dist/pypy/translator/stackless/test/test_depth.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/stackless/test/test_depth.py Fri Apr 21 16:44:30 2006
@@ -0,0 +1,30 @@
+from pypy.translator.stackless.test.test_transform import \
+ llinterp_stackless_function, run_stackless_function
+from pypy.translator.stackless import code
+import os
+
+def test_simple():
+ def g1():
+ "just to check Void special cases around the code"
+ def g2(ignored):
+ pass
+ g1()
+ def f(n):
+ g1()
+ if n > 0:
+ res = f(n-1)
+ else:
+ res = code.stack_frames_depth()
+ g2(g1)
+ return res
+
+ def fn(ignored):
+ count0 = f(0)
+ count10 = f(10)
+ return count10 - count0
+
+ res = llinterp_stackless_function(fn, fn, f, g2, g1)
+ assert res == 10
+
+ res = run_stackless_function(fn, fn, f, g2, g1)
+ assert res.strip() == "10"
Modified: pypy/dist/pypy/translator/stackless/transform.py
==============================================================================
--- pypy/dist/pypy/translator/stackless/transform.py (original)
+++ pypy/dist/pypy/translator/stackless/transform.py Fri Apr 21 16:44:30 2006
@@ -8,6 +8,7 @@
from pypy.rpython.annlowlevel import MixLevelHelperAnnotator
from pypy.translator.stackless import code
from pypy.rpython.rclass import getinstancerepr
+from pypy.rpython.typesystem import getfunctionptr
from pypy.translator.stackless.code import STATE_HEADER, null_state
@@ -99,9 +100,8 @@
ADD_FRAME_STATE_TYPE = lltype.FuncType(
[self.unwind_exception_type, lltype.Ptr(STATE_HEADER)],
lltype.Void)
- self.add_frame_state_ptr = model.Constant(lltype.functionptr(
- ADD_FRAME_STATE_TYPE, "add_frame_state",
- graph=add_frame_state_graph),
+ self.add_frame_state_ptr = model.Constant(
+ getfunctionptr(add_frame_state_graph),
lltype.Ptr(ADD_FRAME_STATE_TYPE))
RESUME_STATE_TYPE = lltype.FuncType([], lltype.Signed)
More information about the Pypy-commit
mailing list