develooper Front page | perl.perl6.internals | Postings from November 2004

Re: Continuations, basic blocks, loops and register allocation

Thread Previous | Thread Next
From:
Luke Palmer
Date:
November 15, 2004 02:03
Subject:
Re: Continuations, basic blocks, loops and register allocation
Message ID:
20041115095438.GA11186@navi.cx
Jeff Clites writes:
> On Nov 14, 2004, at 3:03 AM, Leopold Toetsch wrote:
> 
> >Matt Fowles <ubermatt@gmail.com> wrote:
> >
> >>Yes, but in the case of the continuation resuming after foo, the
> >>continuation should restore the frame to the point where it was taken.
> >> Thus all of the registers will be exactly as they were when the
> >>continuation was taken (i.e. in the correct place).
> >
> >Yes, but Jeff's example wasn't really reflecting the problem.
> 
> How come? (Not quibbling--just afraid I'm missing something.) It seems 
> that even this function body shows the problem:
> 
> 	a = 1
> 	foo()
> 	print a
> 	b = 10
> 	return b
> 
> It would seem (w/o continuations) that b should be able to re-use a's 
> register, but if it does then we'll print 10 instead of 1 "the second 
> time".

It can.  You can't reuse the same PMC (if you're using PMCs), but you
can reuse the register. 

It all comes down to how the code is generated.  I've done this in a
project of mine, and it takes a little thought, but it works.  When you
take a continuation, you have to saveall before you take it, and
restoreall at the point where the continuation is to resume.

This is the trick I used (modulo brain code rot--I haven't written PIR
in a really long time):

    saveall
    $P0 = new Continuation
    set_addr $P0, RESUME
    save $P0
    restoreall
    restore $P0
    # ... $P0 is your continuation

    RESUME:
    restoreall
    # ...

On the other hand, this may be completely irrelavent, since I haven't
been following the discussion.

Luke

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About