Dan Sugalski <[EMAIL PROTECTED]> wrote:At 8:07 AM +0100 12/10/04, Leopold Toetsch wrote:
* What is the intended usage of the action handler? * Specifically is this also ment for lazy DOD runs? * How is the relationship to the C<pop_pad> opcode?
The one thing that I figure *will* be done is that languages will push a sweep or collect op in their scope cleanup in those cases where the language knows that there's potentially easy temp cleanup that needs doing, for example filehandles that should be closed when the scope's exited if there are no outstanding references to them.
That'll not be really easy:
[ subroutine frame ] | | [ cleanup handler subroutine frame ]
Which does argue that it ought not be a sub, I suppose, but something simpler. A plain bsr sort of thing.
If the cleanup handler is a plain subroutine, the previous one, which should be cleaned, is alive. A lazy DOD will find the filehandle in the lexicals and likely in registers.
Well, maybe. Subs are going to have multiple scopes in them (which argues for a faster-than-sub cleanup handler dispatch) so it's more than just a 'cleanup before leaving the sub' sort of thing. There's an awful lot of code around that looks like:
sub foo { # Insert code here foreach (@some_array) { }
{ # Some code that needs its own block } if (foo) { } else { } }
Besides cleaning up on sub exit, there's also a potential cleanup when the foreach is left, the bare block is left, and each of the legs of the if are left. (Potentially once on each foreach iteration, I suppose)
Also, since the compilers are in control of when things get established when entering a sub, if they've noted that there's a reason for a cleanup handler they can push one before establishing the lexical pad it needs to clean up after so that pad'll be disposed of before the cleanup handler runs. (Or, I suppose, two can be pushed, one for before and one for after, if it's noted that's needed)
--
Dan
--------------------------------------it's like this------------------- Dan Sugalski even samurai [EMAIL PROTECTED] have teddy bears and even teddy bears get drunk