Science Fair Project Encyclopedia
Parrot virtual machine
Parrot is a register-based virtual machine being developed using the C programming language and intended to run interpreted languages efficiently. It uses Just-in-time compilation for speed because interpreters tend to be quite slow. Currently you can compile Parrot assembly language and PIR (an intermediate language) to Parrot bytecode and execute it.
It was started by the Perl comunity, and is developped with help from the open source and free software community. As a result it's focused on license compatibility (Artistic|GNU GPL), platform compatibility (Unix, Windows, Mac OS X and Classic, VMS, Crays, Windows CE, and Palm OS, just to name a few), processor architectures compatibility (x86, SPARC, Alpha, IA-64, ARM, Palms, old Macs), speed of execution, size of only 700k depending on platform, and flexible enough to handle the varying demands of Perl, Python, Tcl, Ruby, Scheme, and whatever else. It is also focusing to improve introspection, debugger capabilities, compile-time semantic modulation, etc
By separating the parsing from the compilation and the runtime, we're opening the doors for multiple languages to cooperate. So why not just use the .NET platform? The Perl community has embarked on the design and implementation of the new Perl 6 interpreter, designed from scratch, both the language and the interpreter, and started before they knew about the Microsoft's newer .NET platform. Other, more realistic reason, would be because .NET and also the java virtual machine JVM suffer from serious limitations: they are designed for statically typed languages. (NB: perl, python, ruby, etc are all dynamicaly typed languages). As a result, Perl6 is still going to run on the .NET and JVM platforms, but this will not be its primary target.
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.
Besides a subset of the planned Perl 6, an increasing number of languages can be compiled to Parrot assembly language, these include: BASIC, Befunge, Brainfuck, Cola, Forth, Jako, m4, Miniperl , Ook, Parakeet, OpenComal , PHP, Plot , Python, Ruby, Scheme, Span, Tcl, URM , and YAL. Most of these other language implementations are currently still incomplete and experimental.
There is strong interest in parts of the Ruby community. The Python community is taking more of a wait-and-see attitude (for now). Note that there already is Psyco a JIT-Compiler for Python, and Jython that will compile Python into JAVA bytecode. And also various aproaches to extend Python to the .NET platform (CLI).
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 . Later, the name was adopted by this project whose intent is to do just that. Several tiny languages are developed along with it which target the parrot virtual machine.
The Parrot source code was first released to the world on September 10, 2001. Parrot 0.1.0 "Leaping Kakapo" was released on February 20, 2004. Parrot 0.1.1 "Poicephalus" was released on October 9, 2004.
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 the primary target of language implementations. PIR transparently manages Parrot's inter-routine calling conventions, provides improved syntax, register allocation, register spilling, and more.
IMCC is the Intermediate Code Compiler for Parrot and compiles PIR. It is also known as IMC and is usually stored in files with the suffix ".imc".
Unlike most virtual machines (which are stack-based), Parrot is register-based, just like most hardware CPUs. It provides four types of, typically of 32 registers each:
- I0-I31: native integer type
- N0-N31: floating point numbers
- S0-S31: advanced string registers with Unicode support
- P0-P31: PMC, or Parrot Magic Cookie — Parrot object type
It is possible to enable 64 registers, for enhanced speed in certain scenarios.
set I1, 10 inc I1 # I1 is now 11 add I1, 2 # I1 is now 13 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
- use Perl::Parrot
- The soul of a new virtual machine
- The Parrot Answers
- Parrot: Some Assembly Required
- Articles at parrotcode.org
- Articles at sidhe.org
The contents of this article is licensed from www.wikipedia.org under the GNU Free Documentation License. Click here to see the transparent copy and copyright details