Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!news.iecc.com!nerds-end From: torbenm@diku.dk (Torben Ægidius Mogensen) Newsgroups: comp.compilers Subject: Re: grab the continuation at specific point in a program Date: Mon, 11 Jun 2012 13:22:16 +0200 Organization: SunSITE.dk - Supporting Open source Lines: 31 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <12-06-031@comp.compilers> References: <12-06-025@comp.compilers> NNTP-Posting-Host: news.iecc.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: leila.iecc.com 1339421833 52146 64.57.183.58 (11 Jun 2012 13:37:13 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Mon, 11 Jun 2012 13:37:13 +0000 (UTC) Keywords: analysis Posted-Date: 11 Jun 2012 09:37:13 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com X-Received-Bytes: 2742 Xref: csiph.com comp.compilers:692 Yakov Z writes: > AFAIU, to grab the continuation at specific point in a program I still > have to do CPS conversion of the whole program (because CPS is global) > I then end up with a lot of uninteresting continuations (like for > constants and variables etc.) > > If I want to get rid of those and leave only one "at that point" > continuation (with everything on which it depends upward the call > path) I need to perform another transformation. Do you know if > approaches exist to do the above in one run? You don't need CPS conversion if you can get access to the computation state -- specifically the function call stack. The continuation is in that case "just" a copy of the call stack. This makes it rather costly to grab or call a continuation, but there is next to no cost for programs not using call/cc. If the call "stack" is represented by a linked list, grabbing and using continuations is cheaper, but it means you have to GC the call frames instead of unstacking them, which may or may not be more expensive. CPS transformation gives essentially the same effect, as closures are typically heap allocated. In all cases, continuations are a bit questionable if you have mutable variables: When a continuation is called, do you want to return these to the state they had at the time the continuation was grabbed, or do they keep the values they have at the time of the call? Is there a difference between register-allocated variables, stack-alloctaed variables and heap-allocated variables? The answers to these questions may limit the choices of how to implement continuations. Torben