Michal Wallace writes: > Luke Palmer wrote: > > > This patch re-implements the register backing stacks as PObjs (so > > they can be garbage-collected), honors their COW flags, and adds > > them to the interpreter context (where they should be, honest!). > > > > As a healthy side-effect, it encapsulates their behavior nicely into > > register.c, when before their guts were splattered all over the > > source. > > Hey Luke, > > I applied this patch, ran make realclean and rebuilt parrot. > All the parrot tests pass (except the two about numbers, and I > think they were failing before) but it doesn't like the code > that pirate's generating. I boiled the problem down to this: > > ####### > .sub __main__ > newsub $P0, .Closure, _func > newsub $P1, .Continuation, done > .pcc_begin non_prototyped > .pcc_call $P0, $P1 > done: > .local object result > .result result > .pcc_end > print result > print "\n" > end > .end > > .pcc_sub _func non_prototyped > .local object res > res = new PerlString > res = "hello!" > .pcc_begin_return > .return res > .pcc_end_return > .end > ######## > > When I run this, parrot says: > > No more I register frames to pop! > > I think the problem is coming from the .pcc_begin_return > line. This code works fine if I change the .Continuation to > a .Closure or .Coroutine... It also worked before the patch. > Do I have my calling conventions screwed up or is this a bug?
Your calling conventions are screwed up. I'm glad this failed, as I was anticipating this failure and it didn't come up anywhere in the tests! If you unroll what .pcc_call is doing, you might see the problem: .pcc_begin non_prototyped .pcc_call $P0, $P1 done: .local object result .result result .pcc_end Turns into: @pcc_sub_call_4: set P0, P17 set P1, P16 set I0, 0 set I1, 0 set I2, 0 set I3, -2 updatecc savetop invoke done: restoretop set P16, P5 When the continuation is invoked, that savetop it just did is completely nullified, and you're back to the state before you created the continuation. So, in order to get this to work properly, your first four lines must be: .sub __main__ newsub $P0, .Closure, _func savetop newsub $P0, .Continuation, done So the restoretop after the invoke has something to pop (and so your register state isn't screwed up when you get back). Or you could do as PCC does and use a .RetContinuation, which doesn't close over the stacks, when you don't actually need a full continuation. Hope this helped, Luke