[pypy-svn] r21330 - pypy/dist/pypy/translator/c/test

rxe at codespeak.net rxe at codespeak.net
Mon Dec 19 21:52:19 CET 2005


Author: rxe
Date: Mon Dec 19 21:52:18 2005
New Revision: 21330

Modified:
   pypy/dist/pypy/translator/c/test/test_coroutine.py
Log:
A failing test trying to understand exiting of coroutines and bind from outside
main.
 



Modified: pypy/dist/pypy/translator/c/test/test_coroutine.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_coroutine.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_coroutine.py	Mon Dec 19 21:52:18 2005
@@ -160,3 +160,82 @@
 
     data = wrap_stackless_function(f)
     assert int(data.strip()) == 12345678
+
+def test_coroutine2():
+
+    class TBase:
+        def call(self):
+            pass
+        
+    class T(TBase):
+        def __init__(self, func, arg1, arg2):
+            self.func = func
+            self.arg1 = arg1
+            self.arg2 = arg2
+        def call(self):
+            self.res = self.func(self.arg1, self.arg2)
+
+    class T1(TBase):
+        def __init__(self, func, arg1):
+            self.func = func
+            self.arg1 = arg1
+        def call(self):
+            self.res = self.func(self.arg1)
+
+    def g(lst, coros):
+        coro_f1, coro_g, coro_h = coros
+        lst.append(2)
+        output('g appended 2')
+        coro_h.switch()
+        lst.append(5)
+        output('g appended 5')
+        output('exiting g')
+        
+    def h(lst, coros):
+        coro_f1, coro_g, coro_h = coros
+        lst.append(3)
+        output('h appended 3')
+        coro_f1.switch()
+        lst.append(7)
+        output('h appended 7')
+        output('exiting h')
+
+    def f1(coro_f1):
+        lst = [1]
+        coro_g = Coroutine()
+        coro_h = Coroutine()
+        coros = [coro_f1, coro_g, coro_h]
+        thunk_g = T(g, lst, coros)
+        output('binding g after f1 set 1')
+        coro_g.bind(thunk_g)
+        thunk_h = T(h, lst, coros)
+        output('binding h after f1 set 1')
+        coro_h.bind(thunk_h)
+        output('switching to g')
+        coro_g.switch()
+        lst.append(4)
+        output('f1 appended 4')
+        coro_g.switch()
+        lst.append(6)
+        output('f1 appended 6')
+        coro_h.switch()
+        lst.append(8)
+        output('f1 appended 8')
+        n = 0
+        for i in lst:
+            n = n*10 + i
+        output('exiting f1')
+        return n     
+
+    def f():
+        coro_f = costate.main
+        coro_f1 = Coroutine()
+        thunk_f1 = T1(f1, coro_f1)
+        output('binding f1 after f set 1')
+        coro_f1.bind(thunk_f1)
+        coro_f1.switch()        
+        output('return to main :-(')
+        return thunk_f1.res
+        
+    data = wrap_stackless_function(f)
+    assert int(data.strip()) == 12345678



More information about the Pypy-commit mailing list