[racket] Retrofitting call/cc onto an interpreter not written in CPS

From: Tony Garnock-Jones (tonyg at ccs.neu.edu)
Date: Tue Mar 8 23:28:47 EST 2011

How is your call stack represented? If you're representing 
calls-in-scheme using calls-in-C, you might be in for an interesting 
time. If you're representing calls-in-scheme as explicit activation 
records on a stack maintained by the C code, you can capture that 
structure alongside the environment, code pointer and other 
virtual-machine registers to represent your continuation. (If it's a 
real stack, you'll also need to deal with sharing issues; a simple thing 
to do is to make the activation frames heap-allocated.)

If you're representing calls-in-scheme using calls-in-C, you might be 
able to use a nifty setjmp/longjmp-plus-stack-copying trick I first saw 
in Aubrey Jaffer's SCM interpreter back in the '90s: 
http://cvs.savannah.gnu.org/viewvc/scm/scm/continue.c?revision=1.9&view=markup 
(wow, still using CVS...)

Regards,
   Tony

On 2011-03-08 10:58 PM, Patrick Li wrote:
> Hello,
>
> I'm programming a toy interpreter for Scheme for educational purposes.
> It's programmed in C, and I've got a basic interpreter with the basic
> forms working as well as tail call elimination.
>
> I'm wondering, at this point, what's the easiest way to get call/cc
> working? The interpreter is not programmed in CPS.
>
> And can someone verify whether I'm understanding continuations properly?
> Are they just essentially a "label"? That is, it's just some structure
> that contains the next code to execute, and the environment in which to
> execute that code in?
>
> Thanks for your help
>    -Patrick
>
>
>
> _________________________________________________
>    For list-related administrative tasks:
>    http://lists.racket-lang.org/listinfo/users


Posted on the users mailing list.