On Tue, Oct 25, 2005 at 01:53:52PM +0200, Leopold Toetsch wrote:
> The C<newsub> opcode will be removed RSN.
> 
> Subroutines (and coroutines) created just from a label are lacking vital 
> information, like name, namespace, and especially register usage.
> 
> Please read docs/compiler_faq.pod for replacing C<newsub>.

How do I get an anonymous coroutine into a register?

PGE currently does something similar to the following:

    .sub _pge_rule
        .param pmc mob
        .local pmc corou

        ...
        newsub corou, .Coroutine, _pge_rule_coroutine
        setattribute mob, "PGE::Match\x0&:corou", corou
        ...
    .end

    .sub _pge_rule_coroutine
        ...
        .yield()
        ...
    .end

Note that PGE does this for many rule compilations -- i.e., 
"_pge_rule_coroutine" gets re-used over-and-over again.  It 
works because in the C<newsub> above, _pge_rule_coroutine is 
resolved at compile-time and not at run-time.

I haven't tested this, but I fear that if I change the
newsub above to be

    corou = find_global "_pge_rule_coroutine"

then this changes things to a runtime binding instead of a
compile-time one, i.e. the rule would always call the last
coroutine generated, not the one generated when the dynamic code 
was compiled.

Yes, it would be possible for me to generate a unique label
for each coroutine, but I'm concerned that in doing so we'll be
creating lots of non-GCable subroutines (could be bad if we're
dynamically generating lots of rules).

So, any suggestions?  Am I missing something obvious?

Pm

Reply via email to