[pypy-svn] r23230 - pypy/dist/pypy/module/stackless

tismer at codespeak.net tismer at codespeak.net
Sat Feb 11 16:49:44 CET 2006


Author: tismer
Date: Sat Feb 11 16:49:43 2006
New Revision: 23230

Modified:
   pypy/dist/pypy/module/stackless/interp_coroutine.py
Log:
reverted lots of changes (not checked in) in an attempt to publish continuations. Going to do a re-design and simplification of coroutines, because the mechanics of context switches are formally clearer for me. Will write about this.

Modified: pypy/dist/pypy/module/stackless/interp_coroutine.py
==============================================================================
--- pypy/dist/pypy/module/stackless/interp_coroutine.py	(original)
+++ pypy/dist/pypy/module/stackless/interp_coroutine.py	Sat Feb 11 16:49:43 2006
@@ -101,10 +101,8 @@
     _update_state = staticmethod(_update_state)
 
     def kill(self):
-#        if costate.current is self:
- #           raise CoroutineExit
         if self.frame is None:
-            raise CoroutineExit
+            return
         costate.things_to_do = True
         costate.temp_exc = CoroutineExit()
         self.parent = costate.current
@@ -205,6 +203,10 @@
     def __init__(self):
         Coroutine.__init__(self)
         self.flags = 0
+        if appcostate is None:
+            self.parent = self
+        else:
+            self.parent = appcostate.current
 
     def descr_method__new__(space, w_subtype):
         co = space.allocate_instance(AppCoroutine, w_subtype)
@@ -259,6 +261,12 @@
         return space.wrap(appcostate.main)
     getmain = staticmethod(getmain)
 
+    def setmain(space, w_obj):
+        hold = appcostate.main
+        main = space.interp_w(AppCoroutine, w_obj, can_be_None=False)
+        appcostate.main = main
+        main.frame, hold.frame = hold.frame, main.frame
+    setmain = staticmethod(setmain)
 
 # _mixin_ did not work
 for methname in StacklessFlags.__dict__:
@@ -284,6 +292,7 @@
     appcostate.post_install(module.space)
     makeStaticMethod(module, 'Coroutine', 'getcurrent')
     makeStaticMethod(module, 'Coroutine', 'getmain')
+    makeStaticMethod(module, 'Coroutine', 'setmain')
 
 # space.appexec("""() :
 
@@ -298,6 +307,7 @@
     is_zombie = GetSetProperty(AppCoroutine.w_get_is_zombie, doc=AppCoroutine.get_is_zombie.__doc__),
     getcurrent = interp2app(AppCoroutine.getcurrent),
     getmain = interp2app(AppCoroutine.getmain),
+    setmain = interp2app(AppCoroutine.setmain),
 )
 
 class AppCoState(object):
@@ -308,7 +318,7 @@
         appcostate.current.space = space
         appcostate.tempval = space.w_None
 
-
+appcostate = None
 appcostate = AppCoState()
 
 """



More information about the Pypy-commit mailing list