[pypy-commit] pypy stacklet: API and comments describing the goal of the refactoring I'm starting now.
arigo
noreply at buildbot.pypy.org
Wed Aug 17 12:39:12 CEST 2011
Author: Armin Rigo <arigo at tunes.org>
Branch: stacklet
Changeset: r46558:17ff11cb0bc1
Date: 2011-08-17 12:42 +0200
http://bitbucket.org/pypy/pypy/changeset/17ff11cb0bc1/
Log: API and comments describing the goal of the refactoring I'm starting
now.
diff --git a/pypy/module/_continuation/__init__.py b/pypy/module/_continuation/__init__.py
--- a/pypy/module/_continuation/__init__.py
+++ b/pypy/module/_continuation/__init__.py
@@ -2,16 +2,25 @@
class Module(MixedModule):
- """
- This module exposes 'continuations'.
- """
+ """This module exposes 'one-shot continuation containers'.
+
+A 'flexibleframe' object from this module is a container that stores a
+one-shot continuation. It is a frame-like object, attached as the
+'f_back' of the entry point function that it calls, and with an 'f_back'
+of its own. Unlike normal frames, the continuation exposed in this
+'f_back' can be changed, with the switch() and switch2() methods.
+
+Flexible frames are internally implemented using stacklets. Stacklets
+are a bit more primitive (they are one-shot continuations, usable only
+once) but that concept only really works in C, not in Python, notably
+because of exceptions.
+"""
appleveldefs = {
'error': 'app_continuation.error',
+ 'generator': 'app_continuation.generator',
}
interpleveldefs = {
- 'new': 'interp_continuation.stacklet_new',
- 'callcc': 'interp_continuation.stacklet_new', # a synonym
- 'Continuation': 'interp_continuation.W_Stacklet',
+ 'flexibleframe': 'interp_continuation.W_FlexibleFrame',
}
diff --git a/pypy/module/_continuation/app_continuation.py b/pypy/module/_continuation/app_continuation.py
--- a/pypy/module/_continuation/app_continuation.py
+++ b/pypy/module/_continuation/app_continuation.py
@@ -1,4 +1,33 @@
-
class error(Exception):
"Usage error of the _continuation module."
+
+
+from _continuation import flexibleframe
+
+
+class generator(object):
+
+ def __init__(self, callable):
+ self.__func__ = callable
+
+ def __get__(self, obj, type=None):
+ return generator(self.__func__.__get__(obj, type))
+
+ def __call__(self, *args, **kwds):
+ return genlet(self.__func__, *args, **kwds)
+
+
+class genlet(flexibleframe):
+
+ def __iter__(self):
+ return self
+
+ def next(self, value=None):
+ res = self.switch(value)
+ if self.is_alive():
+ return res
+ else:
+ raise StopIteration
+
+ send = next
More information about the pypy-commit
mailing list