(sorry for duplicate post, changing the title to be accurate here...)
On Wed, Jun 8, 2011 at 4:14 PM, Jason E. Aten j.e.aten@gmail.com wrote:
Hi Marc,
I was wondering if there is a write-up of the details of how Gambit implements first-class continuations?
I'm writing a little language for research purposes, but I'm not sure how to do continuations efficiently, and the Inside-out slides whetted my appetite, but I couldn't grok it fully from them.
If others on the list have pointers to papers as well, I'd enjoy reading about the best thoughts on how to implement continuations.
Thanks!
Jason
Afficher les réponses par date
On Wed, Jun 08, 2011 at 04:15:21PM -0500, Jason E. Aten wrote:
(sorry for duplicate post, changing the title to be accurate here...)
On Wed, Jun 8, 2011 at 4:14 PM, Jason E. Aten j.e.aten@gmail.com wrote:
Hi Marc,
I was wondering if there is a write-up of the details of how Gambit implements first-class continuations?
I'm writing a little language for research purposes, but I'm not sure how to do continuations efficiently, and the Inside-out slides whetted my appetite, but I couldn't grok it fully from them.
If others on the list have pointers to papers as well, I'd enjoy reading about the best thoughts on how to implement continuations.
Thanks!
Jason
One hack -- Just let your C functions keep calling and never returning. When it's time too return, call the continuation as you'd expect. You'll never see old stack frames again unless they contain data you need to point to. Even cons will just give you stack storage, fill it in, and call the continuation with a pointer to the consed cell.
Of course, the stack will get rather big.
So, now and then, test whether the stack is too big, and if it is, do a copying garbage collection. If it's generational, treat the stack as the newest generation. Anything you still need to access on the stack gets copied to the heap. THen do a longjump to clear off the stack and keep going.
I have no idea how efficient this is, but it will keep a lot of transient garbage from ever arriving on the real heap.
-- hendrik
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
Hallo,
On Wed, Jun 8, 2011 at 11:35 PM, Hendrik Boom hendrik@topoi.pooq.com wrote:
One hack -- Just let your C functions keep calling and never returning. When it's time too return, call the continuation as you'd expect. You'll never see old stack frames again unless they contain data you need to point to. Even cons will just give you stack storage, fill it in, and call the continuation with a pointer to the consed cell.
This is the Cheney on the MTA technique: http://home.pipeline.com/~hbaker1/CheneyMTA.html
Thank you Alex! Excellent pointers.
Thank you Hendrik. I guess I should have specified that I am interested in how to implement first class serializable continuations, and to interface with them. As you point out, continuation passing style is simply never returning.
A friend of mine was explaining that Microsoft's new Async C# offers a nice interface programatic interface to continuations, where the compiler notices the "yield" keyword, and automatically generates a finite state machine where the current state is captured as a continuation, and then the interface to the continuation is done via IEnumerable. This sounds elegant. Has anyone compared it's ease of use to the gambit/scheme style API?
On Wed, Jun 8, 2011 at 4:41 PM, Alex Queiroz asandroq@gmail.com wrote:
Hallo,
On Wed, Jun 8, 2011 at 11:35 PM, Hendrik Boom hendrik@topoi.pooq.com wrote:
One hack -- Just let your C functions keep calling and never returning. When it's time too return, call the continuation as you'd expect. You'll never see old stack frames again unless they contain data you need to point to. Even cons will just give you stack storage, fill it in, and call the continuation with a pointer to the consed cell.
On Wed, Jun 8, 2011 at 11:14 PM, Jason E. Aten j.e.aten@gmail.com wrote:
If others on the list have pointers to papers as well, I'd enjoy reading about the best thoughts on how to implement continuations.
"Representing Control in the Presence of First-Class Continuations" http://www.cs.indiana.edu/~dyb/papers/stack.ps
"A portable implementation of first-class continuations for unrestricted interoperability with C in a multithreaded Scheme" http://repository.readscheme.org/ftp/papers/sw2000/feeley.pdf
"Implementation strategies for first-class continuations" http://www.springerlink.com/content/h5808n962434j275/fulltext.pdf
More in: http://library.readscheme.org/page6.html
Cheers, -- -alex http://www.artisancoder.com/