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

Re: Continuations, basic blocks, loops and register allocation

Thread Previous | Thread Next
From:
Leopold Toetsch
Date:
November 15, 2004 04:03
Subject:
Re: Continuations, basic blocks, loops and register allocation
Message ID:
200411151140.iAFBeS518691@thu8.leo.home
Luke Palmer <luke@luqui.org> wrote:
> Jeff Clites writes:

>> 	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.

No. With the presence of a continuation the "print a" can be executed
twice. If now C<b = 10> reuses a's register, it'll break.

> 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.

Please forget C<saveall>. This was the way to go before we had register
frames.

> 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

Sure. That's what we formerly used to do. Two memcpys รก 640 bytes + 2
stack operations. The memcpys were killing performance.

This isn't needed anymore. A continuation does restore the register
frame. In your code above you emit all possible code to do the rigth
thing. I'm proposing a much simpler syntax:

  RESUMABLE: foo()
     # code here might be executed more then once

> Luke

leo

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