| 1 |
from pypy.interpreter.mixedmodule import MixedModule |
| 2 |
|
| 3 |
|
| 4 |
class Module(MixedModule): |
| 5 |
"""This module exposes 'one-shot continuation containers'. |
| 6 |
|
| 7 |
A 'continulet' object from this module is a container that stores a |
| 8 |
one-shot continuation. It is similar in purpose to the 'f_back' |
| 9 |
attribute of frames, which points to where execution should continue |
| 10 |
after this frame finishes. The difference is that it will be changed |
| 11 |
(often repeatedly) before the frame actually returns. |
| 12 |
|
| 13 |
To make a continulet object, call 'continulet' with a callable and |
| 14 |
optional extra arguments. Later, the first time you switch() to the |
| 15 |
continulet, the callable is invoked with the same continulet object as |
| 16 |
the extra first argument. |
| 17 |
|
| 18 |
At this point, the one-shot continuation stored in the continulet points |
| 19 |
to the caller of switch(). When switch() is called again, this one-shot |
| 20 |
continuation is exchanged with the current one; it means that the caller |
| 21 |
of switch() is suspended, its continuation stored in the container, and |
| 22 |
the old continuation from the continulet object is resumed. |
| 23 |
|
| 24 |
Continulets are internally implemented using stacklets. Stacklets |
| 25 |
are a bit more primitive (they are really one-shot continuations), but |
| 26 |
that idea only works in C, not in Python, notably because of exceptions. |
| 27 |
|
| 28 |
The most primitive API is actually 'permute()', which just permutes the |
| 29 |
one-shot continuation stored in two (or more) continulets. |
| 30 |
""" |
| 31 |
|
| 32 |
appleveldefs = { |
| 33 |
'error': 'app_continuation.error', |
| 34 |
'generator': 'app_continuation.generator', |
| 35 |
} |
| 36 |
|
| 37 |
interpleveldefs = { |
| 38 |
'continulet': 'interp_continuation.W_Continulet', |
| 39 |
'permute': 'interp_continuation.permute', |
| 40 |
'_p': 'interp_continuation.unpickle', |
| 41 |
} |