chibi-scheme icon indicating copy to clipboard operation
chibi-scheme copied to clipboard

Implement delimited continuations

Open mnieper opened this issue 2 years ago • 3 comments

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

mnieper avatar Jan 30 '23 09:01 mnieper

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.

ashinn avatar Jan 30 '23 12:01 ashinn

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.

mnieper avatar Jan 30 '23 15:01 mnieper

The implemented API is in (srfi 226 prompt), (srfi 226 continuation) and in (srfi 226 shift-reset).

mnieper avatar Jan 30 '23 17:01 mnieper