Parrot virtual machine
From Wikipedia, the free encyclopedia
Parrot is a register-based virtual machine being developed using the C programming language and intended to run dynamic languages efficiently. It uses just-in-time compilation for speed to reduce the interpretation overhead. It is currently possible to compile Parrot assembly language and PIR (an intermediate language) to Parrot bytecode and execute it.
Parrot was started by the Perl community, and is developed with help from the open source and free software communities. As a result, it is focused on license compatibility (Artistic License and GNU GPL), platform compatibility across a broad array of systems, processor architectures compatibility across most modern processors, speed of execution, small size (around 700k depending on platform), and being flexible enough to handle the varying demands of Perl, and most, if not all, other modern dynamic languages. It is also focusing on improving introspection, debugger capabilities, and compile-time semantic modulation.
Contents |
[edit] History
The project started to implement Perl 6 and originally had the very dull name "The software we're writing to run Perl 6". The name Parrot came from an April Fool's joke in which a hypothetical language named Parrot was announced that would unify Python and Perl [1]. The name was later adopted by this project, which aims to support Perl and Python. Several little languages are being developed along with it which target the Parrot virtual machine.
- First source code released to the world September 10, 2001.
- Version 0.1.0 "Leaping Kakapo" released February 20, 2004.
- Version 0.1.1 "Poicephalus" released October 9, 2004.
- Version 0.1.2 "Phoenix" released March 6, 2005.
- Version 0.2.0 "NLNet" released May 8, 2005.
- Version 0.3.0 "Alex" released October 1, 2005.
- Version 0.4.0 "Luthor" released December 4, 2005.
- Version 0.4.1 "Foghorn Leghorn" released January 8, 2006.
- Version 0.4.2 "GPW" released February 22, 2006.
- Version 0.4.3 "Cold Conure" released April 2, 2006.
- Version 0.4.4 "Feather" released May 14, 2006.
- Version 0.4.5 (no name) released June 19, 2006.
- Version 0.4.6 (no name) released August 9, 2006.
- Version 0.4.7 "Caique" released November 14, 2006.
- Version 0.4.8 "Eponymous" released January 16, 2007.
- Version 0.4.9 "Socorro" released February 22, 2007.
- Version 0.4.10 "The Release Formally Known as 'Prince'" released March 20, 2007.
[edit] Languages
The goal of the Parrot virtual machine is to host client languages, and allow interoperation between them. A number of hurdles exist in accomplishing this goal.
[edit] Static and dynamic languages
The differing properties of statically and dynamically typed languages have motivated the design of Parrot. Current popular virtual machines such as the Java virtual machine and the Common Language Runtime have been designed for statically typed languages, while the languages targeted by Parrot are dynamically typed.
Virtual machines like the Java virtual machine and the current Perl 5 virtual machine are also stack based. The developers see it as an advantage of the Parrot machine that it has registers, and therefore more closely resembles an actual hardware design, allowing the vast literature on compiler optimization to be used generating code for the Parrot virtual machine so that it will run bytecode at speeds closer to compiled languages like C.
[edit] Functional concepts
Parrot has rich support for a number of features of functional programming including closures and continuations. Especially in the face of Parrot's rich exception handling and multi-threading features, these can be very difficult features to implement correctly, and solving such problems once at the level of the virtual machine could be a tremendous savings for all of Parrot's client languages.
[edit] Compiler tools
Parrot provides a suite of compiler-writing tools which includes the Parser Grammar Engine (PGE), a hybrid parser-generator that can express a recursive descent parser as well as a operator-precedence parser, allowing free transition between the two in a single grammar. The PGE feeds into the Tree Grammar Engine (TGE) which further transforms the parse-tree generated by PGE for optimization and ultimately for code generation.
[edit] Existing client languages
Besides a subset of the planned Perl 6, an increasing number of languages can be compiled to Parrot assembly language including APL, BASIC, Befunge, Brainfuck, Cola, Forth, Jako, Lisp, m4, Miniperl, Ook!, Parakeet, OpenComal, PHP, Plot, Pheme, Punie, Python, Ruby, Scheme, Span, Tcl (aka partcl), URM, and YAL. Most of these other language implementations are currently still incomplete and experimental.
[edit] Possible future languages and projects
There is strong interest in parts of the Ruby community. The Python community is taking more of a wait-and-see attitude, due to already having Psyco, a just-in-time Python-to-machine-code compiler, Jython, a Python-to-Java-bytecode compiler, and IronPython to compile to the .NET platform, as well the in-development PyPy, a rewrite of Python in Python itself aimed to provide static code generation as well as high-level optimization.
[edit] Internals
Parrot code has three forms. Bytecode is natively interpreted by Parrot. Parrot Assembly Language (PASM) is the low level language that compiles down to bytecode. Parrot Intermediate Representation (PIR) is a slightly higher level language than PASM and also compiles down to Bytecode. It is the primary target of language implementations. PIR transparently manages Parrot's inter-routine calling conventions, provides improved syntax, register allocation, register spilling, and more. PIR code is usually stored in files with the suffix ".pir".
IMCC is the Intermediate Code Compiler for Parrot and compiles PIR.
[edit] Examples
[edit] Registers
Parrot is register-based like most hardware CPUs, unlike most virtual machines, which are stack-based. Parrot provides four types of registers:
- I: native integer type
- N: floating point numbers
- S: advanced string registers with Unicode support
- P: PMC, or Parrot Magic Cookie — Parrot object type
Up until version 0.3.0, Parrot typically provided 32 registers of each type, with the possibility of enabling 64 registers. Later versions provide an unlimited number of registers; each function can allocate as many registers of each type as it needs.
[edit] Arithmetic operations
In PASM
set I1, 4 inc I1 # I1 is now 5 add I1, 2 # I1 is now 7 set N1, 42.0 dec N1 # N1 is now 41.0 sub N1, 2.0 # N1 is now 39.0 print I1 print ", " print N1 print "\n" end
In PIR
.sub main :main $I1 = 4 inc $I1 # $I1 is now 5 $I1 += 2 # $I1 is now 7 $N1 = 42.0 dec $N1 # $N1 is now 41.0 $N1 -= 2.0 # $N1 now 39.0 print $I1 print ", " print $N1 print "\n" .end
[edit] Culture
The current tagline of the Parrot project is "one bytecode to rule them all," a reference to Tolkien's One Ring from The Hobbit and The Lord of the Rings.
Until late 2005, Dan Sugalski was the lead designer and chief architect of Parrot. Chip Salzenberg, a longtime Perl, Linux kernel, and C++ hacker, took over until mid-2006, when he became the lead developer. Allison Randal, the lead developer of Punie and chief architect of Parrot's compiler tools, is now the chief architect.
Development discussions take place primarily on the parrot-porters mailing list, hosted by perl.org. In addition, there are weekly moderated meetings for Parrot and language developers hosted in #parrotsketch on irc.perl.org. The #parrot channel on the same network is often full of Parrot hackers.
Design discussions exist in the form of Parrot Design Documents, or PDDs, in the Parrot repository [2]. The chief architect or another designated designer produces these documents to explain the philosophy of a feature as well as its interface and design notes. Parrot hackers turn these documents into executable tests, and then existing features.
[edit] License
Parrot is a free software project, distributed under the same terms as Perl; that is, dual-licensed under both the GNU General Public License and the Artistic License.