[pypy-svn] r28198 - in pypy/dist/pypy/translator/stackless: . test

mwh at codespeak.net mwh at codespeak.net
Sat Jun 3 20:17:07 CEST 2006


Author: mwh
Date: Sat Jun  3 20:17:04 2006
New Revision: 28198

Modified:
   pypy/dist/pypy/translator/stackless/code.py
   pypy/dist/pypy/translator/stackless/test/test_resume_point.py
   pypy/dist/pypy/translator/stackless/transform.py
Log:
(mwh, pedronis)
a test and code for resume_state_invoke(blah, blah, returns=not-int).
mwh learnt a lesson about slice assignment debugging this.


Modified: pypy/dist/pypy/translator/stackless/code.py
==============================================================================
--- pypy/dist/pypy/translator/stackless/code.py	(original)
+++ pypy/dist/pypy/translator/stackless/code.py	Sat Jun  3 20:17:04 2006
@@ -2,7 +2,7 @@
 from pypy.rpython import rarithmetic
 from pypy.rpython import extfunctable
 from pypy.translator.stackless import frame
-from pypy.translator.stackless.frame import STATE_HEADER, SAVED_REFERENCE
+from pypy.translator.stackless.frame import STATE_HEADER, SAVED_REFERENCE, STORAGE_FIELDS
 
 EMPTY_STATE = frame.make_state_header_type('empty_state')
 
@@ -215,15 +215,16 @@
                                                          [RESUME_AFTER_STATE,
                                                           EMPTY_STATE])
 
-def resume_after_long(state, retvalue):
+template = """\
+def resume_after_%(typename)s(state, retvalue):
     if global_state.restart_substate == -1:
         # normal entry point for a call to state.switch()
         # first unwind the stack
         u = UnwindException()
         s = lltype.malloc(RESUME_AFTER_STATE)
-        s.header.f_restart = INDEX_RESUME_AFTER_LONG
+        s.header.f_restart = INDEX_RESUME_AFTER_%(TYPENAME)s
         s.c = state
-        global_state.retval_long = retvalue
+        global_state.retval_%(typename)s = retvalue
         add_frame_state(u, s.header)
         raise u
     elif global_state.restart_substate == 0:
@@ -242,10 +243,16 @@
         global_state.top = targetstate
         raise UnwindException()
 
-resume_after_long.stackless_explicit = True
-INDEX_RESUME_AFTER_LONG = frame.RestartInfo.add_prebuilt(resume_after_long,
+
+resume_after_%(typename)s.stackless_explicit = True
+INDEX_RESUME_AFTER_%(TYPENAME)s = frame.RestartInfo.add_prebuilt(resume_after_%(typename)s,
                                                          [RESUME_AFTER_STATE,
                                                           EMPTY_STATE])
+"""
+
+for typename in STORAGE_FIELDS.values():
+    if typename == 'weak': continue
+    exec template%dict(typename=typename, TYPENAME=typename.upper())
 
 # ____________________________________________________________
 

Modified: pypy/dist/pypy/translator/stackless/test/test_resume_point.py
==============================================================================
--- pypy/dist/pypy/translator/stackless/test/test_resume_point.py	(original)
+++ pypy/dist/pypy/translator/stackless/test/test_resume_point.py	Sat Jun  3 20:17:04 2006
@@ -57,6 +57,24 @@
     res = llinterp_stackless_function(example)
     assert res == 412
 
+def test_returns_with_instance():
+    class C:
+        def __init__(self, x):
+            self.x = x
+    def g(x):
+        return C(x+1)
+    def f(x, y):
+        r = g(x)
+        rstack.resume_point("rp1", y, returns=r)
+        return r.x + y
+    def example():
+        v1 = f(one(),one()+one())
+        s = rstack.resume_state_create(None, "rp1", 5*one())
+        v2 = rstack.resume_state_invoke(int, s, returns=C(one()*3))
+        return v1*100 + v2
+    res = llinterp_stackless_function(example, assert_unwind=False)
+    assert res == 408
+
 def test_call_exception_handling():
     def g(x,y):
         if x == 0:

Modified: pypy/dist/pypy/translator/stackless/transform.py
==============================================================================
--- pypy/dist/pypy/translator/stackless/transform.py	(original)
+++ pypy/dist/pypy/translator/stackless/transform.py	Sat Jun  3 20:17:04 2006
@@ -243,22 +243,22 @@
                 code.resume_after_long,
                 [s_hdrptr, annmodel.SomeInteger()],
                 annmodel.s_None),
-##             lltype.SignedLongLong: mixlevelannotator.constfunc(
-##                 code.resume_after_longlong,
-##                 [s_hdrptr, annmodel.SomeInteger(knowntype=rarithmetic.r_longlong)],
-##                 annmodel.s_None),
-##             lltype.Float: mixlevelannotator.constfunc(
-##                 code.resume_after_float,
-##                 [s_hdrptr, annmodel.SomeFloat()],
-##                 annmodel.s_None),
-##             llmemory.Address: mixlevelannotator.constfunc(
-##                 code.resume_after_addr,
-##                 [s_hdrptr, annmodel.SomeAddress()],
-##                 annmodel.s_None),
-##             SAVED_REFERENCE: mixlevelannotator.constfunc(
-##                 code.resume_after_ref,
-##                 [s_hdrptr, annmodel.SomePtr(SAVED_REFERENCE)],
-##                 annmodel.s_None),
+            lltype.SignedLongLong: mixlevelannotator.constfunc(
+                code.resume_after_longlong,
+                [s_hdrptr, annmodel.SomeInteger(knowntype=rarithmetic.r_longlong)],
+                annmodel.s_None),
+            lltype.Float: mixlevelannotator.constfunc(
+                code.resume_after_float,
+                [s_hdrptr, annmodel.SomeFloat()],
+                annmodel.s_None),
+            llmemory.Address: mixlevelannotator.constfunc(
+                code.resume_after_addr,
+                [s_hdrptr, annmodel.SomeAddress()],
+                annmodel.s_None),
+            SAVED_REFERENCE: mixlevelannotator.constfunc(
+                code.resume_after_ref,
+                [s_hdrptr, annmodel.SomePtr(SAVED_REFERENCE)],
+                annmodel.s_None),
             }
 
         mixlevelannotator.finish()
@@ -551,16 +551,20 @@
         # because the non-exceptional link has been stored in
         # self.resume_points and we don't want a constant "zero" in
         # there.
-        retvar = varoftype(lltype.Void)
-        realrettype = op.result.concretetype
+        v_state = op.args[0]
         v_returns = op.args[1]
-        resume_after_ptr = self.resume_afters[storage_type(v_returns.concretetype)]
-        if storage_type(v_returns.concretetype) != v_returns.concretetype:
-            raise NotImplementedError
-        args = [resume_after_ptr] + op.args
-        newop = model.SpaceOperation('direct_call', args, retvar)
-        block.operations[-1] = newop
+        erased_returns_type = storage_type(v_returns.concretetype)
+        resume_after_ptr = self.resume_afters[erased_returns_type]
+        llops = LowLevelOpList()
+        if erased_returns_type != v_returns.concretetype:
+            v_returns = gen_cast(llops, erased_returns_type, v_returns)
+        llops.genop('direct_call', [resume_after_ptr, v_state, v_returns],
+                    resulttype=lltype.Void)
+        del block.operations[-1]
+        block.operations.extend(llops)
+
         noexclink = block.exits[0].copy()
+        realrettype = op.result.concretetype
         for i, a in enumerate(noexclink.args):
             if a is op.result:
                 noexclink.args[i] = model.Constant(realrettype._defl(), realrettype)



More information about the Pypy-commit mailing list