[pypy-svn] r24429 - in pypy/dist/pypy: interpreter module/stackless

tismer at codespeak.net tismer at codespeak.net
Thu Mar 16 08:33:23 CET 2006


Author: tismer
Date: Thu Mar 16 08:33:13 2006
New Revision: 24429

Modified:
   pypy/dist/pypy/interpreter/executioncontext.py
   pypy/dist/pypy/module/stackless/coroutine.py
Log:
added subcontext support for coroutines. 
Problem: I cannot get it to annotate, the stack is SomeObject.

Modified: pypy/dist/pypy/interpreter/executioncontext.py
==============================================================================
--- pypy/dist/pypy/interpreter/executioncontext.py	(original)
+++ pypy/dist/pypy/interpreter/executioncontext.py	Thu Mar 16 08:33:13 2006
@@ -15,13 +15,6 @@
         self.ticker = 0
         self.compiler = space.createcompiler()
 
-    # XXX
-    # I think that it is wrong to hide frames here. The stack should
-    # contain all the frames, because we need them for pickling.
-    # better to do the hiding when the stack is accessed. This implies that
-    # we have an explicit frame depth counter.
-    # please comment/correct me! (chris)
-    
     def enter(self, frame):
         if self.framestack.depth() > self.space.sys.recursionlimit:
             raise OperationError(self.space.w_RuntimeError,
@@ -41,9 +34,21 @@
         if not frame.hide():
             self.framestack.pop()
 
-    # coroutine support
-    # XXX still trying and thinking hard
-
+    # coroutine: subcontext support
+    def subcontext_new(coobj):
+        coobj.framestack = Stack()
+        coobj.w_tracefunc = None
+        coobj.w_profilefunc = None
+        coobj.is_tracing = 0
+    new_subcontext = staticmethod(new_subcontext)
+
+    def subcontext_swap(self, coobj):
+        self.framestack,    coobj.framestack    = coobj.framestack,     self.framestack
+        self.w_tracefunc,   coobj.w_tracefunc   = coobj.w_tracefunc,    self.w_tracefunc
+        self.w_profilefunc, coobj.w_profilefunc = coobj.w_profilefunc,  self.w_profilefunc
+        self.is_tracing,    coobj.is_tracing    = coobj.is_tracing,     self.is_tracing
+    # coroutine: I think this is all, folks!
+    
     def get_builtin(self):
         try:
             return self.framestack.top().builtin

Modified: pypy/dist/pypy/module/stackless/coroutine.py
==============================================================================
--- pypy/dist/pypy/module/stackless/coroutine.py	(original)
+++ pypy/dist/pypy/module/stackless/coroutine.py	Thu Mar 16 08:33:13 2006
@@ -50,6 +50,7 @@
         state = self._get_state(space)
         Coroutine.__init__(self, state)
         self.flags = 0
+        space.getexecutioncontext().subcontext_new(self)
 
     def descr_method__new__(space, w_subtype):
         co = space.allocate_instance(AppCoroutine, w_subtype)
@@ -75,7 +76,10 @@
             raise OperationError(space.w_ValueError, space.wrap(
                 "cannot switch to an unbound Coroutine"))
         state = self.costate
+        ec = space.getexecutioncontext()
+        ec.subcontext_switch(state.current, self)
         self.switch()
+        ec.subcontext_switch(state.last, state.current)
         w_ret, state.w_tempval = state.w_tempval, space.w_None
         return w_ret
 



More information about the Pypy-commit mailing list