Rakudo now supports inline PIR

The Raku Programming Language Collect, Conserve and Remaster Project

Rakudo now supports inline PIR

Originally published on 4 December 2008 by Patrick Michaud.

I’ve just added the capability to write inline PIR directly in Raku subroutines in Rakudo Perl. This is done using the :PIR adverb on the ‘q’ quote operator, thus one can write:

q:PIR { say 'hello' }

and whatever is in the bracketing characters will be embedded “inline” with the surrounding Raku code. The special %r placeholder can be used in the PIR to specify the return value of the PIR:

my $a = q:PIR { %r = box '123' };
say $a;  # "123\n"

Within the PIR it’s safe to use any of the PIR registers $P0..$P9, $S0..$S9, $I0..$I9, and $N0..$N9. Register numbers higher than 9 run the risk of conflicting with automatically-generated registers generated by PCT. One can also declare local symbols, but may need to be careful not to conflict with any local symbols generated by PCT (those are somewhat rare, however).

Of course, we don’t expect this to ever be a fixture of “true” Raku programs – this is just here to make it easier to write Raku builtins for Rakudo (i.e., the “Prelude”) and perhaps help others who are bootstrapping modules on Parrot. Ultimately the :PIR flag will only be available via an appropriate ‘use PIR’ statement or the like.

Also, the quote sequence will eventually become ‘Q:PIR’ with an uppercase ‘Q’, but a parser issue constrains us to stick with the lowercase ‘q’ for now.

More coming soon!