Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement delimited continuations #885

Open
mnieper opened this issue Jan 30, 2023 · 3 comments
Open

Implement delimited continuations #885

mnieper opened this issue Jan 30, 2023 · 3 comments
Assignees

Comments

@mnieper
Copy link
Collaborator

mnieper commented Jan 30, 2023

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

@ashinn
Copy link
Owner

ashinn commented Jan 30, 2023

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.

@mnieper
Copy link
Collaborator Author

mnieper commented Jan 30, 2023

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
Copy link
Collaborator Author

mnieper commented Jan 30, 2023

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

@mnieper mnieper self-assigned this Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants