Earlier, I sent in a patch for PGE to support S05-style single-curly
closures (RT#60186). The next thing I'm trying to do is to get this
to work:
./perl6 -e '"" ~~ m/:lang(Perl6) { say "hi" }/'
The PIR version works perfectly:
./perl6 -e '"" ~~ m/:lang(PIR) { say "hi" }/'
Out of the box, the Perl6 version fails like this:
invoke() not implemented in class 'Perl6::Compiler'
current instr.: '_block17_corou' pc 209 (EVAL_11:87)
called from Sub '_block17' pc 84 (EVAL_11:40)
called from Sub 'parrot;Code;ACCEPTS' pc 5402 (src/
gen_builtins.pir:3517)
called from Sub '_block11' pc 28 (EVAL_11:14)
called from Sub 'parrot;PCT;HLLCompiler;eval' pc 864 (src/PCT/
HLLCompiler.pir:498)
called from Sub 'parrot;PCT;HLLCompiler;command_line' pc 1355 (src/
PCT/HLLCompiler.pir:725)
called from Sub 'parrot;Perl6;Compiler;main' pc 17089 (perl6.pir:184)
I edited perl6.pir to add this debug code:
.sub 'invoke' :vtable :method
say 'invoke called'
.return ()
.end
so now I get:
./perl6 -e '"" ~~ m/:lang(Perl6) { say "hi" }/'
invoke called
invoke called
as expected (well, I don't understand why it's doubled, but I'm happy
that it's called). But I'm still a novice and I can't figure out the
next step. I know that this code is being called from code generated
in the [PGE;Exp;Closure;'pir'] method in compilers/pge/PGE/Exp.pir,
and the closure $P1 is being invoked like so:
($P0 :optional, $I0 :opt_flag) = $P1(mob)
I think "mob" is the default Match instance, aka $/. It looks like
$I0 is a boolean indicating whether the closure has significance to
the match (true) or is pure side effect (false). It also looks like
$P0 is the 'make' result for the closure. But, I'm not really sure
I'm interpreting that code correctly.
Can anyone offer some advice on how I should write the 'invoke'
method? My goal is to build arbitrarily complex data structures from
closures fired in my grammar. Specifically, I'm trying to write a
PDF parser -- my grammar is parsing correctly now, but I'd rather not
have to write the closures in PIR if I can help it.
Chris