Parrot

from Wikipedia, the free encyclopedia
Parrot logo

Parrot is a register-based virtual machine under development , which is primarily geared towards the needs of dynamic programming languages ​​such as Perl or Python . Parrot was designed by Dan Sugalski primarily as an interpreter for Perl 6 . The development is led by Allison Randal and supported and coordinated by the Parrot Foundation.

Etymology / origin of the word

During the planning phase of Parrot, Simon Cozens published an elaborate joke article (including book announcement) on April 1, 2001 on the Perl website of O'Reilly Verlag, with the official announcement by Larry Wall and Guido van Rossum that Perl and Python would merge into a common language called Parrot in the future. Of course, this merger did not take place, but the name of a virtual machine that should be usable for different languages ​​was born.

development

Parrot was originally designed by Dan Sugalski and managed for several years. It was a free software project from the start and is published under the Artistic License 2.0 . Allison Randal is now leading the work of the volunteers, with the Parrot Foundation, founded in autumn 2008 and also managed by her, winning the support of the first companies in November. Patrick Michaud , lead author of the PGE, leads the development of the PCT (Parrot Compiler Tools) and Rakudo (Perl 6 Compiler).

The project has been in active development for several years. Individual parts were rewritten several times until a satisfactory implementation was achieved. However, not all capabilities for a complete VM are fully implemented. The current version is 5.0.0, released on January 29, 2013.

The book "Perl 6 and Parrot Essentials, 2nd edition", published by O'Reilly, offers a now outdated overview of Parrot and has now been released under a Creative Commons license to make it easier to keep it up to date.

architecture

Unlike other virtual machines, such as the JVM for Java, which are stack-oriented (0-address machine), Parrot is a register machine (3-address machine). This is hoped for better optimization possibilities and parallel processing of commands both within a processor and distributed over several processors.

Parrot allows you to allocate any number of registers . Registers are differentiated according to type, there are registers for whole numbers, floating point numbers , character strings and for any objects, so-called PMC. As far as the platform allows, they are mapped to hardware registers in order to increase execution speed.

Parrot is written in C to be available on all platforms that Perl 5 runs on.

Intermediate codes

A program can go through several intermediate stages during compilation. In the first step, the source text is transferred to the syntax tree , which still strongly reflects the structure of the source text. The second step is usually the translation into an Abstract Syntax Tree (AST), which is based more on the logical than the textual structure of the program.

Parrot defines a form of AST called PAST (Parrot Abstract Syntax Tree) that can be used by almost all programming languages. This form can be converted into bytecode via a further intermediate stage called POST (Parrot Opcode Syntax Tree) . POST serves as an interface for bytecode optimizers and converters to and from bytecode of other virtual machines.

As with Perl 5, a bytecode is ultimately executed, which is generated from source code or intermediate code directly before execution or can be compiled in a separate step. A new feature for Perl with Parrot is the ability to save the bytecode in files (usually with the extension .pbc) in order to execute them later.

While PAST and POST are defined as data structures without direct textual representation, there are also intermediate codes that can be written by humans called PIR (Parrot Intermediate Representation) and PASM (Parrot Assembler). PIR is similar to traditional programming languages ​​in terms of the legibility of the code, but dispenses with control structures. PASM has the same structure as Bytecode and is very much adapted to Parrot's internal structure.

Tools

The Parrot Compiler Tools (PCT for short) are a collection of software, largely written in PIR, that is supplied with Parrot to make the creation of parsers and compilers for Parrot much easier.

PCT consists of the following components:

  • Parrot Grammar Engine (PGE for short), a library that can convert source text into a syntax tree with the help of context-free languages (mostly Perl 6 rules )
  • Not Quite Perl (NQP), a subset of Perl 6 that is used to create an abstract syntax tree from a syntax tree and to be able to carry out static analyzes
  • A compiler that translates PAST into POST
  • A compiler that translates POST into bytecode

All of these components are modular and can be used independently of one another.

Support of other programming languages

Parrot was designed to support a large number of other languages such as Python , Ruby , Tcl or BASIC . Compilers that translate these programming languages ​​into Perl6 intermediate code executed by Parrot have been tackled. However, since Parrot itself was not yet complete and some of the features used by these compilers were removed, all of these compilers no longer work and their development has also been partially discontinued. Many other compilers for the Parrot intermediate code are still in the works, but like Parrot itself only a few have been completed.

In the final version, all these languages ​​should be usable together, i.e. every language should be able to use the modules of every other language.

The development of Ponie , a translator who was supposed to make existing Perl5 code executable under Parrot, has meanwhile been canceled.

As of November 2006

Parrot is currently:

  • A highly optimized interpreter that works much more efficiently than the current Perl5 interpreter. Depending on the benchmark , it currently executes optimized intermediate code three times as fast as perl5 a corresponding Perl program. It is still a little slower than native C code, but in some benchmarks it is no longer several factors slower than the current Perl 5.
  • There was a JIT compiler that converted code at runtime into machine code that should run the program faster. However, the JIT implementation had practically no increase in performance. Since its design also hindered the development of the rest of Parrot's components, it was removed before Parrot 1.7 was released. Since September 2009 there is a plan to use the LLVM JIT compiler in Parrot.
  • A code generator for compiled, executable files . This generator uses the JIT compiler and can therefore only be available on platforms on which there is also a JIT compiler. This function, called "Native exec", is currently only available on i386 / Linux and i386 / BSD . At least on i386 / Linux, however, this function currently seems to have a bug: Programs that are properly compiled by the JIT compiler trigger a segmentation error in Parrot when they are converted into object code .

Web links

Individual evidence

  1. Parrot Press Release
  2. Joke interview with Larry & Guido , perl.com
  3. Programming Parrot in a Nutshell ( Memento from October 10, 2014 in the Internet Archive )
  4. http://www.parrot.org/news/parrot-5.0.0-johnny-five-alive-released
  5. "Perl 6 and Parrot Essentials, 2nd edition" ( Memento of the original from August 7, 2008 in the Internet Archive ) Info: The archive link was inserted automatically and has not yet been checked. Please check the original and archive link according to the instructions and then remove this notice. @1@ 2Template: Webachiv / IABot / use.perl.org
  6. Archived copy ( Memento of the original from January 15, 2010 in the Internet Archive ) Info: The archive link was inserted automatically and has not yet been checked. Please check the original and archive link according to the instructions and then remove this notice. @1@ 2Template: Webachiv / IABot / use.perl.org
  7. http://lists.parrot.org/pipermail/parrot-dev/2009-September/002811.html
  8. http://wknight8111.blogspot.com/2009/09/jit-first-project-challenge.html