chibi-scheme
chibi-scheme copied to clipboard
Implement delimited continuations
Since yesterday, I have been working on a SRFI 226-compatible implementation of delimited continuations for Chibi Scheme (see here for the current development: https://github.com/mnieper/chibi-scheme/tree/srfi-226).
It basically replaces the call/cc & dynamic-wind implementation in init-7.scm so that delimited continuations can be supported.
After I have added thread support (similar to how the old implementation used the %dk
parameter), the implementation should be ready to merge.
For efficiency reasons, it would be good if a continuation could be captured early when (a) a program is run or (b) an expression in the REPL is evaluated. Calling this continuation with a thunk should call this thunk and deliver its values to the program runner or expression evaluator. @ashinn, can you point out to me where it is best to capture such a continuation?
Thanks,
Marc
Thanks for working on this!
The start for running programs is in main.c (where it says "load the module or script").
In the same file is the repl
function, but perhaps more important is (chibi repl)
.
The latter runs each expression in a separate thread so it can be terminated.
Thank you for the immediate response. After having thought about it, I have implemented a new opcode, SEXP_OP_ABORT
that clears the stack and then executes a thunk in this empty stack. This may also be useful in other cases to save stack space when stack frames become essentially dead.
The implemented API is in (srfi 226 prompt)
, (srfi 226 continuation)
and in (srfi 226 shift-reset)
.