Joined: 08 Jul 2006
Location: Off the scale in the third direction
Would anyone have any ideas or suggestions on how to implement partial continuations in assembly?
To create a continuation I need to make a snapshot of the current state of the program and wrap that into a callable object which accepts as an argument a value which will be used as the return value for the expression from which the execution continues when the continuation is called.
But how can I delimit the continuation in a sensible way?
Yes, kind of. If a continuation is the machine code combined with a snapshot of the state of a program including the stack at that point so that I can jump back to that point in time and continue from there then yes I guess it could be used for that too. One common example of what continuations can be used for is that of implementing backtracking algorithms.
If one common problem with continuations is that they switch the entire the execution context so that they never return unless you pass them another a continuation telling where to return. A partial continuation is supposed to be a slice of a continuation created so that it actually does return to the caller automatically when done and thus can be treated like a function.
I'm trying to figure out the implementation alternatives so I could the make an informed choice between support for continuations, partial continuations or coroutines based on the trade-offs involved.
People seem to say that implementing coroutines is trivial if you have continuations. But I'm wondering if what you gain by supporting continuations is worth the pain compared to coroutines which I assume can be used just by creating a new stack for each instance and then passing the arguments and jumping to the entrypoint.
And then there is the question of multiple entrypoints and exits with different signatures. I'm assuming that coroutines might make this a little more intuitive use if supported. Continuations and partial such seem to be more parts of the whole program as a big ball of mud while I kind of find it easier to imagine coroutines as separate modules. Modularity being a good thing. And if I were to go towards coroutines there might not be that huge of a leap towards actors if I were to want to experiment with them too.
The main issues here are the same as usual with continuations, coroutines, etc. To go for a cactus stack or multiple linear ones? Will the caller or the callee save registers? How should parameter passing work? Do we need return values or will output parameters suffice? Pretty basic but fundamental decisions which need to be made. Unless I can go for cheap prototypes and test a whole variety of different approaches.
With the partial continuations I'd need to figure out what a compiler supporting them would generate to make them happen. How do I create just a slice of the future of a program or in other words of the snapshot? Save the registers and other state on the stack and add code which restores all of it from the stack? Copy the stack starting from the top, fix the pointers and after I come to the mark which designates where the continuation needs to be cut I gather up the bindings in the lexical frames below it and insert a return instruction to make the continuation return like a partial one should?
Oh well. Time to eat and to leave the rest of the ponderings for the afternoon.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum