Today's hackathon with fglock++ focused on the design and implementation of MiniPerl6, an extended surface syntax language for native PIL nodes. Oud rallying cry is one single Pugs codebase in Perl 6, as we seek to remove the massive code duplication in the current Haskell and Perl 5 runtimes.
As a strict subset of Perl 6, the design of MiniPerl6 removes some of the most complex parts of Perl 6:
- List context
- Inheritance
- BEGIN{...} blocks
- Runtime-evaluated type constraints
- Global and package-wide variables
- Named arguments to positional parameters
- Distinction between assignment and binding
On the other hand, it still retains many handy Perl 6 constructs that massively simplifies syntax tree construction and deconstruction:
- Closures and currying
- Class accessors and delegators
- Array, Hash, and Object unpacking
- Type annotations on variables and parameters
- Deconstructing pattern bindings with smartmatch and Signatures
- Temporary, hypothetical, state, and constant declarators
- Class accessors and delegators
To facilitate the migration, I've amended the relevant part of the Modules spec (S11), so now we can trivially inline Perl 5 code inside a Perl 6 programs, with use v5
at the beginning of a lexical block. Such blocks can nest arbitrarily deeply to switch between Perl versions:
use v6-alpha;
# ...some Perl 6 code...
{
use v5;
# ...some Perl 5 code...
{
use v6-alpha;
# ...more Perl 6 code...
}
}
And indeed, this now Just Works in Pugs:
sub add_with_perl5 ($x, $y) {
use v5;
$x + $y; # This is Perl 5 code
}
say add_with_perl5(21, 21); # 42
With this in place, we can bootstrap the self-hosted MiniPerl6 trivially, by reusing the existing v6.pm code and gradually take away "use v5" declarations in each block.
Because we carefully designed MiniPerl6 to emit to native Perl 5 that has no runtime overhead, that means whatever part bootstrapped in Perl6 -- e.g. the Grammar engine -- will actually gain performance over e.g. fglock++'s hand-coded PCR codebase, effectively make MiniPerl6 a DSL for Perl 5.
That's it for today. Tomorrow cmarcelo++ will join us, and maybe MiniPerl6 will turn into a DSL for Haskell as well... :-)
Hi Audrey,
I'm not sure I understand what MiniPerl6 is about. Is it to move some of the code written in Haskell to Perl?
Thank you for helping me understand,
Vincent.
Posted by: Vincent Foley | 2006.11.03 at 05:49 AM
Vincent: Yes, it's for moving Haskell and Perl 5 implementations of Perl 6 into something that's implemented in (a subset) of Perl 6.
Posted by: Audrey Tang | 2006.11.03 at 05:56 AM