All about Perl 6 – interview of Flávio Glock
In this interview, which completes a trilogy on implementations of Perl 6, we talk to Flávio Glock about Perlito, the compiler collection that implements a subset of Perl 5 and Perl 6. It is a very interesting discussion that revolves around topics like parsing, bootstraping, VM’s, optimizations and much more.
Flávio Glock Soibelmann has developed several CPAN modules for the DateTime Dashboard. He is currently one of the developers of Perl and Perlito is his main current project.
Perlito’s potential is very exciting as it is open to hacking extensions and backends, while also acts as a platform for experimenting with language semantics, optimizations and code generation. Aside from that research and develop aspect, it also bears a practical face for end-users, as Perl in the browser demonstrates.
Looking into the future and in the case that Perlito manages to implement the full language set, then it maybe would spearhead the reshaping of Perl’s landscape.
NV: So Flávio, you work for Booking.com in the code optimization sector?
FG: Yes, for about 5 years now.
NV: What is this area of activity occupied with – code refactoring, experimenting with algorithms, tweaking Perl’s internals?
FG: It is mostly about identifying bottlenecks – and then fixing; we have some people tweaking Perl’s internals too, but this is not my area.
NV: So what is the motivation behind Perlito?
FG: Perlito started as a bootstrapping compiler for Pugs – we wanted to rewrite Pugs in Perl6. It was called “mini-perl6” at that time. The plan was to support both Haskell and Perl5 as backends
I think the regex compiler for Pugs still uses mini-perl6:
This is the mini-perl6 source code for the module:
NV: Can you provide a short high level overview of Perlito’s underlying architecture or how does it work behind the scenes?
FG: Perlito has 2 compilers – a Perl6 compiler written in Perl6, and a Perl5 compiler written in Perl5
This is an old picture, but this is still pretty much how the Perlito compilers work:
There is a grammar, which transforms the input text into a data tree (AST), and there is an emitter, which transforms the tree into machine-readable code. Other modules are provided to handle other more complex cases.
In Perlito5, the grammar is implemented as Perl5 modules which you an see here:
NV: Perlito’s definition is : “a compiler collection that implements a subset of Perl5 and Perl6 “. Why a subset, what is left out and what cannot be done in comparison to the full-set?
There are several steps in the compilation. Perlito parses the code, and then emits code that will be executed by a specific virtual machine. In some cases, there is no easy way to generate specific instructions, it is a limitation of the backend
I’m currently working on the x64 backend, this is very low level and should have fewer or no limitations.
FG: You can try it out at :
There is also a Perl6 version, but that is quite behind, because I’ve spent most of the past year working on the Perl5 compiler.
There are a few features specific to the js backend, such as
This comes from the Pugs-js implementation.
The compiler supports perl objects, simple regexes, as well as more “advanced” features like tied arrays. There is also a more complete js backend, the ‘js3’ version – which emulates more closely Perl5 but that comes at a performance price.
NV: As an industry insider working for one of the biggest Perl5 advocates (if not the biggest) do you think that an organization of such a size would someday consider switching from Perl5 to Perl6?
When would the setting be mature enough for such a switch?
FG: It will eventually happen. At some point people will use it for one-off scripts, and then somebody will use it on a cronjob, but it will not replace Perl5 in this environment – it will instead compete with alternate languages, like Go.
NV: So what are Perlito’s potential uses for developers and end-users alike?
FG: The main product for end-users are the Perl-js compilers. They can be integrated in other projects, like azawawi++ did with the Farabi web-based IDE.
For developers there are a lot of possibilities. Perlito is pretty open to hacking, there are no hard coded limits
NV: Finally, what are your expectations for the future?
FG: The Perlito5::X64::Assembler package should allow for building an efficient, Perl-specific environment. At some point, if this becomes the main development platform for Perlito, we don’t need to work around virtual machine limitations anymore.
The other side of the Perlito development is to allow better Perl5/Perl6 inter-operation;there is already a Perl6-to-Perl5 compiler in CPAN :
This is based on Perlito6. The plan is to finish the Perl5-to-Perl6 compiler, that would work about the same way as v6.pm.
For the full interview please follow Perlito – An Interview With Flávio Glock