=head1 Parrot Status Report =head2 Intro Parrot has been in development since late 2001. What do we have to show for the past 6 years of effort? What is in Parrot's future? When will it be complete? This article will hopefully give you some idea as to the answers or at least point you in the general direction of an answer. =head2 What is Parrot? For those who don't already know, Parrot is a virtual machine designed for running dynamic languages such as Perl, Python, Ruby, etc. It was initially concieved to be the underlying virtual machine for Perl 6 but its mission also includes other dynamic languages since the problems faced by those languages are very similar. Parrot is implemented in C, but currently to build Parrot you will also need to have Perl installed. =head2 Where is Parrot today? As of this writing, Parrot has specifications and implementations for bytecode, namespaces, lexical variables, objects, events, exceptions, and basic IO. There are just-in-time compilers for x86, amd64, ia64, ppc, mips, hppa and arm processors. Parrot has been made to run on the following platforms: Linux, Solaris, Mac OS X, FreeBSD, Windows, and cygwin. There are many languages that have a Parrot implementation. Parrot has even been embedded in a certain popular web server. =head2 Low level bits: What makes Parrot tick The following items are available in Parrot to make various software items such as language implementations and execution environments. They may not all be completely implemented, but generally enough has been implemented to be useful. (And indeed, several of the languages that target Parrot, do use these features) =over 4 =item Garbage collection Parrot utilizes a generational mark and sweep garbage collector to ensure timely destruction of objects while also minimizing the impact on performance. =item Continuations Parrot uses something called Continuation Passing Style for calling subroutines and other flow control items. Essentially a continuation is a snapshot of the execution environment that can be resumed at any time. Thus, at the end of a subroutine, a "return" is really just an execution of the continuation that was taken at the start of the subroutine with any values that the subroutine may want to return as arguments to the continuation. (See http://www.intertwingly.net/blog/2005/04/13/Continuations-for-Curmudgeons for more info on continuations and continuation passing style) Parrot hides the explicit nature of continuations behind some syntax for executing and returning from subroutines, but there are opcodes to take and call continuations when you need them. =item Parrot Magic Cookies (PMC) These are fundamental units of stuff in Parrot that aren't numbers or strings. PMCs are like objects in that they implement certain behavior and that behavior can be inherited by other PMCs. Language implementors can use PMCs to describe some detail of their language that Parrot may not natively provide. =item Namespaces Namespaces have been fully specced and implemented. These can be used to partition code/data into useful compartments. For instance, each language that targets Parrot has its own namespace so that multiple languages can interoperate in the same Parrot execution. Namespaces are hierarchical in nature so that languages that support their own idea of namespaces can also make direct use of Parrot's namespace mechanism. =item Objects Many dynamic programming languages are object oriented in nature or have object oriented features. Parrot provides an object model and primitive operations that allow these languages to implement the semantics appropriate for any object system. There is support for classes, attributes on those classes, methods on those classes, inheritance (single and multiple), multi-method dispatch, delegation, class composition (roles), object introspection, etc. =item Events In order to be compatible with event-driven programming, Parrot provides a standard interface for events that works in conjunction with a scheduler to fire actions in response to those events. =item Exceptions When something unusual happens in the course of execution, what is Parrot to do? One of the things it can do is throw an exception. There are facilities for throwing and catching exceptions, adding and removing exception handlers, querying whether or not an exception has been handled or not and terminating execution as appropriate. =item Native Call Interface (NCI) The Native Call Interface allows Parrot to directly interface with existing C libraries without compiling them into Parrot. There is a Parrot opcode for loading the library into Parrot-space and another for creating a linkage between Parrot and the library's subroutines. So, for instance, with a little Parrot code to glue it all together, you can make Parrot subroutines that, when called, actually execute subroutines from within the library. In the Parrot distribution are some examples of how Parrot has been interfaced with the SDL graphics library using the NCI. =item Dynamically Loadable Opcodes Besides invoking C functions in external libraries that you load during runtime, you can also write your own Parrot instructions. Parrot's I is the C language, and after pre-processing your new opcode implementation and compilation into a shared library, the new ops can be loaded. After loading, you can use your new custom ops, just like any other built-in Parrot instruction. This feature is useful if you need to implement certain functionality that needs high performance. =back =head2 Mid level bits: Parrot Compiler Toolkit Since Parrot is designed to be the backend for dynamic programming languages, it provides a set of tools that can be used to help generate programming languages. Below are descriptions of those tools. =over 4 =item Parrot Grammar Engine (PGE) PGE parses a good bit of the Perl 6 Regex syntax so that languages can be described in terms of Perl 6 Regex. PGE has facilities for generating the parse tree for the grammar it is parsing as well as executing bits of Parrot code during the parse. Additionally, PGE can switch seemlessly between recursive descent (top down) and operator precedence parsing (bottom up) where appropriate in the grammar. Also, in keeping with the Perl 6 concept that Regex are just strange looking subroutines, PGE allows named rules to be implemented as Parrot subroutines for when specialized actions are needed. =item Transformation Grammar Engine (TGE) TGE is a tool used to turn tree-like representations into other tree- like representations. This is primarily useful for turning a parse tree into an abstract syntax tree (AST) and then turn that AST into a tree of opcodes. This separation of concerns allows for multiple optimization opportunities. TGE also allows you to attach bits of information to the nodes in the tree so that you can build an "attribute grammar". (See http://en.wikipedia.org/wiki/Attribute_grammar) =item Not Quite Perl (NQP) NQP is small compiler that uses a subset of the Perl 6 syntax. It is primarily designed to quickly transform parse trees created by PGE into some other representation (usually Parrot code) using Perl6ish syntax. Similar to TGE in nature, NQP leverages knowledge of Perl 6 to make code generation easier. =item Parrot Abstract Syntax Tree (PAST) PAST is a standard abstract syntax tree for use by all languages that target Parrot as a backend. PAST contains nodes for common language items such as variables and operators and assignment and control flow. =item HLLCompiler The HLLCompiler class provides a standard set of methods and a framework for compiler writers to use in building a compiler. Some examples of these methods are for registering a language with Parrot, parsing a language, generating syntax tree, and compiling a language. =back =head2 High level bits: Languages What programming languages are targetting Parrot? Currently in the Parrot distribution there are approximately 39 separate language implementations at various stages of completion. Here's a quick list of some of the languages as they appear in the Parrot source: apl, basic, zcode, cardinal (ruby), ecmascript (javascript), forth, lisp, lua, m4, ook, perl5, perl6, plumhead (php), punie (Perl 1), pynie (Python), scheme, and tcl. Several of these languages are nothing more than a parser, but many of them have complete interpreters or compilers. Below are short descriptions of the more actively developed or more complete language implementations. =over 4 =item abc An implementation of the basic calculator found on most unix-ish systems. Since the language of this calculator is relatively small, B is well suited as an example of how to use the Parrot Compiler Toolkit to construct the front end parts of a compiler including parsing and transformation into an abstract syntax tree. Thus C, besides being a functioning implementation of C, is a good tutorial for people who want to learn how to build a compiler. =item pynie An implementation of the Python programming language. Pynie makes a good test bed for the Parrot Compiler Toolkit as a sanity check that Parrot is still on the right track. =item Pheme An implementation of a programming language that is very similar to Scheme. Another language used to sanity test the Parrot Compiler Toolkit. =item ParTcl This is a completly-from-scratch implementation of the programming language tcl. ParTcl is in active development and at last check it passes about 25% of Tcl's actual test suite. =item Perl 6 The raison d'etre for Parrot, the Perl 6 implementation is coming along nicely. A standard grammar is being developed for Perl 6 that not only describes the language, but has placeholders for "actions" to be performed. The other Perl 6 implementations (Perl 5 and Haskell) are also able to make use of this same grammar. The Parrot-based Perl 6 compiler parses a good bit of this grammar and compiles it to Parrot code so that it can be executed. =back =head2 Miscellaneous Jeff Horwitz has created 2 modules for the Apache web server: mod_parrot and mod_perl6. mod_parrot allows for Parrot code to have access to the Apache API so that handlers can be written in Parrot. As a consequence, this means that any language that targets Parrot can also have access to the Apache API. As a first example of this ability, mod_perl6 allows handlers written in Perl 6. They are compiled on-the-fly using the Parrot-based Perl 6 compiler the first time they are executed and then persist in that particular instance of Apache. =head2 What is left to do? Parrot is still under active development. Though it is complete enough to implement many things, it does not quite have all of the features its designers would like. Some things that still need work: =over 4 =item Concurrency Parrot has some support for multi-threaded operations and it has been designed in from the start but there are still details that need to be ironed out of the specification and implementation. =item Complete implementations of all low level bits There are implementations in the Parrot source tree for IO, events, exceptions, concurrency, etc., but many of them are only 90% implemented since just enough was done to scratch someone's itch. Before the 1.0 release we need the other 90% to be implemented. :-) That is, the implementations need to be complete as per the specification and well tested such that there are no segfaults or strange behavior. =item Security model The plan is to give Parrot a sandboxing mechanism such that execution environments can be created within Parrot that are completely separate from Parrot's own execution environment and any other execution environments that may be created. Limits will be placed on such things as CPU time, memory usage, disk usage, and code will be able to run using restricted set of opcodes. This is still in the design phase right now, but is set to be completed sometime in 2008. =item Multiple character sets Parrot is designed to be a Unicode-friendly environment that should support multiple character sets within the same string. However, there is still some design work and implementation to be done. =back For a schedule of the items that are still "in the works" along with projected completion dates and who the head cat-herder is for each subsection, see http://www.perlfoundation.org/parrot_grant_from_nlnet =head2 Getting involved. How can you help out? The friendly folks running the volunteer effort to implement the Parrot virtual machine are always looking for more people to help. Even if you don't know C or Perl, you can still help. Some of the activities that would be helpful are: writing documentation, proofreading, creating tests for Parrot and the various languages that target it, writing C code to flesh out more parts of Parrot, writing Perl 5 code to aid in code generation, etc. The Parrot source code can be retrieved from the subversion repository at http://svn.perl.org/parrot or you can also subscribe or send email to parrot-porters@perl.org or join us on irc.perl.org/#parrot For more information, see L =head2 Thanks Many thanks to the following people (in no particular order) for their input (either in feedback on this article or in code in the Parrot source tree), without which we wouldn't have Parrot nor an article about its status :) Allison Randal chromatic Will Coleda Patrick R. Michaud Jerry Gay Leopold Toetsch Kevin Tew Andy Lester Jonathan Worthington Jeff Horwitz Klaas-Jan Stol And of course, our emeritus cat-herders: Dan Sugalski Chip Salzenberg There are probably many people who regularly contribute to Parrot that I've left out. If you are one of these people, I can assure you I did not leave your name out on purpose, but only because I couldn't think of it at the time of this writing. My humblest apologies to anyone who should be in this list but isn't. =head2 Author Jonathan Scott Duff