March 25, 2009
This article was contributed by Nathan Willis
The Parrot project released version
1.0 of its dynamic language interpreting virtual machine last week, marking
the culmination of seven years of work. Project leader Allison Randal
explains that although end users won't see the benefits yet, 1.0 does mean
that Parrot is ready for serious work by language implementers. General
developers can also begin to get a feel for what working with Parrot is like
using popular languages like Ruby, Lua, Python, and, of course, Perl.
The evolution of Parrot
Parrot originated in 2001 as the planned interpreter for Perl 6, but
soon expanded its scope to provide portable compilation and execution for
Perl, Python, and any other dynamic language. In the intervening
years, the structure of the project solidified — the Parrot team
focused on implementing its virtual machine, refining the bytecode format,
assembly language, instruction formats, and other core components, while
separate teams focused on implementing the various languages, albeit
working closely with the core Parrot developers.
The primary target for 1.0 was to have a stable platform ready for
language implementers to write to, and a robust set of compiler tools
suitable for any dynamic language. The 1.4 release, tentatively set for
this July, will target general developers, and next January's 2.0 should be
ready for production systems.
The promise of Parrot is tantalizing: rather than separate runtimes for
Perl, Python, Ruby, and every other language, a single virtual machine that
can compile each of them down to the same instruction set and run them.
That opens the possibility of applications that incorporate code and call
libraries written in multiple languages. "A big part of development
these days isn't rolling everything from scratch, it's combining existing
libraries to build your product or service,"
Randal said. "Access to multiple languages expands your available
resources, without making you learn the syntax of a new language. It's also
an advantage for new languages, because they can use the libraries from
other existing languages and get a good jump-start."
The Parrot VM itself is register-based, which the project says
better mirrors the design of underlying CPU hardware and thus permits
compilation to more efficient native machine language than the stack-based
VMs used for Java and .Net. It provides separate registers for integers,
strings, floating-point numbers, and "polymorphic containers" (PMCs; an
abstract type allowing language-specific custom use), and performs garbage
collection. Parrot can directly execute code in its own native Parrot
Bytecode (PBC) format, and uses just-in-time compilation to run programs
written in higher-level host languages. In addition to PBC, developers and
compilers can also generate two higher-level formats: Parrot Assembly
(PASM) and Parrot Intermediate Representation (PIR). A fourth format,
Parrot Abstract Syntax Tree (PAST), is designed specifically for compiler
output. The differences between them, including the level of detail
exposed, is documented
at the Parrot web site.
Parrot includes a suite of core libraries that implement common data
types like arrays, associative arrays, and complex numbers, as well as
standard event, I/O, and exception handling. It also features a
next-generation regular expression engine called Parser Grammar Engine
(PGE). PGE is actually a fully-functional recursive descent parser, which
Randal notes makes it a good deal more powerful than a standard regular
expression engine, and a bit cleaner and easier to use.
The project plans to keep the core of Parrot light, however, and extend
its functionality through libraries running on the dynamic languages that
Parrot interprets. Keeping the core as small as possible will make Parrot
usable on resource-constrained hardware like mobile devices and embedded
systems.
Language experts wanted
The "getting
started" documentation includes sample code written in PASM and PIR,
but it is the high level language support that interests most developers.
The project site maintains a list of active efforts to
implement languages for the Parrot VM. As of today, there are 46 projects
implementing 36 different languages. Three of the most prominent are Rakudo, the implementation of
Perl 6 being developed by the Perl community, Cardinal, an implementation
of Ruby, and Pynie, an
implementation of Python. Among the rest there is serious work pursuing
Lua and Lisp variants, as well as work on novelty languages such as Befunge and
LOLCODE. Not all are complete, but Randal said development has accelerated
in recent months after the 1.0 release date was announced, and she expects
production ready releases of the key languages soon.
Language implementers come from within the Parrot project and from the
language communities themselves. As Randal explained it, "we see it
as our responsibility as a project to develop the core of the key language
implementations, and to actively reach out to the language
communities."
1.0 includes a set of parsing utilities called the Parrot
Compiler Tools (PCT) to help implement dynamic languages on the Parrot
VM. PCT includes the PGE parser, as well as classes to handle the lexical
analyzer and compiler front-end, and to create the driver program that
Parrot itself will call to run the compiler. Owing to its
Perl heritage, PCT uses a subset of Perl 6 called Not Quite Perl (NQP).
Developer
documentation for NQP and all of the PCT components is available with
Parrot 1.0 as well as on the Parrot Developer
Wiki.
Parrot packages have been available for many Linux distributions and
BSDs for much of its development cycle, but now that it has reached 1.0,
Randal expects to see it ship by default in upcoming releases. For now,
however, developers and language implementers interested in testing and
running Parrot 1.0 can download source code releases
from the project's web site or check out a copy from its Subversion
repository. Building Parrot requires Perl, a C compiler, and a standard
make utility.
Parrot has been a long time in coming, but now that 1.0 is out of the
gate, the real work can begin, as the major language projects make their
own stable releases and developers start to use the Parrot VM as a runtime
environment. Although the technical work continues at full pace, Randal
said the project is also pushing forward on the education and outreach
front, with a book soon to be published through Onyx Neon Press, and Parrot
sessions planned for upcoming open source conferences and workshops as
well.
(
Log in to post comments)