Skip to content

All about Perl 6 – interview of Flávio Glock

2013 April 30
by Nikos Vaggalis

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 is an intriguing piece of technology capable of compiling Perl 5 or Perl 6 programs into various backends, currently including JavaScript, Python, Ruby and Go. It may be extended to other backends as the project is very active.

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:
http://search.cpan.org/dist/Pugs-Compiler-Rule/

This is the mini-perl6 source code for the module:

http://cpansearch.perl.org/src/FGLOCK/Pugs-Compiler-Rule-0.37/examples/Grammar.grammar

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:

Perlito

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:

http://github.com/fglock/Perlito/tree/master/src5/lib/Perlito5/Grammar

The internal structure of Perlito6 is more “monolithic”, it needs some refactoring.  There is a third component, which is the Runtime.This is where the backend-specific features (and workarounds) are implemented – for example, the CORE module for javascript:

https://github.com/fglock/Perlito/blob/master/src5/lib/Perlito5/Javascript2/CORE.pm

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?

FG: The plan is to support the full language, but this is not possible yet. Each backend supports a set of features; for example this file is a description for Perl5-in-Javascript.

Javascript does not support sleep(), for example. On virtual machines that do automated garbage collection, reference counting is hard and it is important to support DESTROY and automatic closing of file handles.  You can work around in most cases, but there is usually an impact on performance

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.

NV: From all the backends the show stealer is the Javascript backend which allows controlling the browser through Perl! What is the generated Javascript capable of, how far can it go?

FG: You can try it out at :

http://perlcabal.org/~fglock/perlito5.html

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

JS::inline(‘document.getElementById(“print-result”).value’)

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.

The version that you see online has a reasonable balance between functionality and performance and is good enough to compile the Perlito source code to Javascript;that is how perlito5.js is built:

http://perlcabal.org/~fglock/perlito5.js

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 :

http://search.cpan.org/dist/v6/

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

nikosNikos Vaggalis has a BSc in Computer Science and a MSc in Interactive Multimedia. He works as a Software Engineer/Database Application Developer and codes in Perl and C#.

 

Leave a Reply