On Tue, Oct 25, 2005 at 04:56:57PM +0200, Leopold Toetsch wrote:
> >How do I get an anonymous coroutine into a register?
>
> As these 2 .subs are generated in one bunch and compiled ...
>
> > .sub _pge_rule
> > .param pmc mob
>
> ... drop the var decl:
>
> > .local pmc corou
>
> > newsub corou, .Coroutine, _pge_rule_coroutine
>
> and use a .Sub constant (.Sub is ok despite the PMC is a Coroutine).
>
> .const .Sub corou = "_pge_rule_coroutine"
>
> The coroutine label is resolved at compile-time.
I tried the .Sub constant and I get an error:
[EMAIL PROTECTED] pge]$ ./parrot Library.pir
error:imcc:parse error, unexpected INTC
in file 'Library.pir' line 5
[EMAIL PROTECTED] pge]$
See attached Library.pir.
Better still, is there an easy way for a sub (coroutine) to get
its own PMC when it's running? Is C<interpinfo> the right
way to do it? What I'd like to do now is the equivalent of...
.sub ident
.param pmc mob
$I0 = find_type "PGE::Match"
mob = new $I0
setattribute mob, "PGE::Match\x0&:corou", CURRENT_SUB
...
.yield()
...
.end
where the C<setattribute> line somehow stores the currently executing
coroutine into mob's attribute table.
Thanks,
Pm
# <PGE::Rule::ident>
.namespace [ "PGE::Rule" ]
.const .Sub corou = "_ident_coroutine"
.sub ident
.param pmc mob
$P0 = find_global "PGE::Match", "newfrom"
mob = $P0(mob)
setattribute mob, "PGE::Match\x0&:corou", corou
corou(mob)
.return (mob)
.end
.sub _ident_coroutine
.param pmc mob
loop:
print mob
.yield()
goto loop
.end