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

tismer at codespeak.net tismer at codespeak.net
Fri Jan 27 20:01:49 CET 2006


Author: tismer
Date: Fri Jan 27 20:01:47 2006
New Revision: 22759

Modified:
   pypy/dist/pypy/module/stackless/__init__.py
   pypy/dist/pypy/module/stackless/interp_coroutine.py
Log:
more progress: managed to implement get_main and get_current as static methods (not really supported, yet)

Modified: pypy/dist/pypy/module/stackless/__init__.py
==============================================================================
--- pypy/dist/pypy/module/stackless/__init__.py	(original)
+++ pypy/dist/pypy/module/stackless/__init__.py	Fri Jan 27 20:01:47 2006
@@ -13,3 +13,9 @@
         'tasklet'    : 'interp_stackless.tasklet',
         'Coroutine'  : 'interp_coroutine.AppCoroutine',
     }
+
+    def setup_after_space_initialization(self):
+        # post-installing classmethods/staticmethods which
+        # are not yet directly supported
+        from pypy.module.stackless.interp_coroutine import post_install
+        post_install(self)

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	Fri Jan 27 20:01:47 2006
@@ -5,6 +5,7 @@
 from pypy.interpreter.gateway import interp2app, ObjSpace, W_Root
 from pypy.interpreter.error import OperationError
 from pypy.rpython.rarithmetic import intmask
+from pypy.interpreter.function import StaticMethod
 
 from pypy.rpython.rstack import yield_current_frame_to_caller
 from pypy.module.stackless.stackless_flags import StacklessFlags
@@ -201,6 +202,7 @@
             raise OperationError(space.w_ValueError, space.wrap(
                 "cannot switch to an unbound Coroutine"))
         self.switch()
+        appcostate.current = self
 
     def w_kill(self):
         self.kill()
@@ -227,6 +229,24 @@
     return space.wrap(self.get_is_zombie())
 AppCoroutine.w_get_is_zombie = w_get_is_zombie
 
+def w_coro_get_current(space):
+    return space.wrap(appcostate.current)
+
+def w_coro_get_main(space):
+    return space.wrap(appcostate.main)
+
+def installStaticMethod(space, w_klass, func, name=None):
+    if name is None:
+        name = func.__name__
+    smeth = StaticMethod(space.wrap(interp2app(func, name)))
+    space.setattr(w_klass, space.wrap(name), space.wrap(smeth))
+
+def post_install(module):
+    space = module.space
+    w_klass = space.getattr(space.wrap(module), space.wrap('Coroutine'))
+    installStaticMethod(space, w_klass, w_coro_get_current, 'get_current')
+    installStaticMethod(space, w_klass, w_coro_get_main, 'get_main')
+                           
 AppCoroutine.typedef = TypeDef("Coroutine",
     __new__ = interp2app(AppCoroutine.descr_method__new__.im_func),
     bind = interp2app(AppCoroutine.w_bind,
@@ -236,6 +256,12 @@
     is_zombie = GetSetProperty(AppCoroutine.w_get_is_zombie, doc=AppCoroutine.get_is_zombie.__doc__),
 )
 
+class AppCoState(object):
+    def __init__(self):
+        self.current = self.main = AppCoroutine()
+
+appcostate = AppCoState()
+
 """
 Considerations about "current"
 ------------------------------



More information about the Pypy-commit mailing list