flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > Partial continuations

Author
Thread Post new topic Reply to topic
nyrtzi



Joined: 08 Jul 2006
Posts: 192
Location: Off the scale in the third direction
nyrtzi 01 May 2015, 18:48
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?
Post 01 May 2015, 18:48
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20298
Location: In your JS exploiting you and your system
revolution 02 May 2015, 00:35
Do you mean something like state saving for hibernation, suspension or migration of a task?
Post 02 May 2015, 00:35
View user's profile Send private message Visit poster's website Reply with quote
nyrtzi



Joined: 08 Jul 2006
Posts: 192
Location: Off the scale in the third direction
nyrtzi 02 May 2015, 06:27
revolution wrote:
Do you mean something like state saving for hibernation, suspension or migration of a task?


http://en.wikipedia.org/wiki/Delimited_continuation

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.
Post 02 May 2015, 06:27
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.