Parrot virtual machine
Encyclopedia
Parrot is a register-based
process virtual machine designed 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 is free
and open source
software.
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 2.0
), platform compatibility across a broad array of systems, processor architecture compatibility across most modern processors, speed of execution, small size (around 700k depending on platform), and the flexibility to handle the varying demands that Perl 6
, and most other modern dynamic languages make. Other goals include improving introspection, debugger
capabilities, and compile-time semantic modulation.
Version 1.0, with a stable API
for development, was released on March 17, 2009. The current stable production release of Parrot is version 3.10.0 "Apple Pi", released on November 16, 2011.
and Perl
. The name was later adopted by this project (initially a part of the Perl 6 development effort) which aims to support Perl 6, Python, and other programming languages. Several languages are being ported
to run on the Parrot virtual machine.
The Parrot Foundation
was created in 2008 to hold the copyright
and trademark
s of the Parrot project, to help drive development of language implementations
and the core codebase, to provide a base for growing the Parrot community, and to reach out to other language communities.
s between languages.
and the Common Language Runtime
have been designed for statically typed languages, while the languages targeted by Parrot are dynamically typed.
Virtual machines such as the Java virtual machine and the current Perl 5 virtual machine are also stack based
. Parrot developers see Parrot's inclusion of registers as an advantage, as it therefore more closely resembles a hardware design, allowing the vast literature on compiler optimization
to be used in generating bytecode for the Parrot virtual machine that could run at speeds closer to machine code
. Other register-based virtual machines have inspired parts of Parrot's design, including the Lua VM and Inferno's Dis
.
including closures
and continuation
s, both of which can be particularly difficult to implement correctly and portably, especially in conjunction with exception handling
and threading
. Implementing solutions to these problems at the virtual machine level prevents repeated efforts to solve these problems in the individual client languages.
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.
PIR transparently manages Parrot's inter-routine calling conventions, provides improved syntax, register allocation, and more. PIR code is usually stored in files with the filename extension ".pir".
, and unlike most virtual machines, which are stack-based. Parrot provides four types of registers:
Parrot provides an arbitrary number of registers; this number is fixed at compile time per subroutine.
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
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, was the chief architect until mid-October 2010 when she stepped down and chose Christoph Otto as the new chief architect.
Development discussions take place primarily on the #parrot channel on irc.perl.org. In addition, there are weekly moderated meetings for Parrot and language developers hosted in #parrotsketch on the same network. Much discussion also occurs on the parrot-dev mailing list, hosted by parrot.org.
Design discussions exist in the form of Parrot Design Documents, or PDDs, in the Parrot repository. 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.
The Parrot team releases a new stable version of the software on the third Tuesday of every month. Core committers take turns producing releases in a revolving schedule, where no single committer is responsible for multiple releases in a row. This practice has improved the project's velocity and stability.
Register machine
In mathematical logic and theoretical computer science a register machine is a generic class of abstract machines used in a manner similar to a Turing machine...
process virtual machine designed to run
Abstraction layer
An abstraction layer is a way of hiding the implementation details of a particular set of functionality...
dynamic languages efficiently. It uses just-in-time compilation
Just-in-time compilation
In computing, just-in-time compilation , also known as dynamic translation, is a method to improve the runtime performance of computer programs. Historically, computer programs had two modes of runtime operation, either interpreted or static compilation...
for speed to reduce the interpretation overhead. It is currently possible to compile Parrot assembly language
Parrot assembly language
The Parrot assembly language is the basic assembly language used by the Parrot virtual machine.PASM is the lowest level assembly language in the Parrot stack...
and PIR
Parrot intermediate representation
The Parrot intermediate representation , previously called Intermediate code , is one of the two assembly languages for the Parrot virtual machine. The other is Parrot assembly language or PASM...
(an intermediate language) to Parrot bytecode
Bytecode
Bytecode, also known as p-code , is a term which has been used to denote various forms of instruction sets designed for efficient execution by a software interpreter as well as being suitable for further compilation into machine code...
and execute it. Parrot is free
Free software
Free software, software libre or libre software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions that only ensure that further recipients can also do...
and open source
Open source
The term open source describes practices in production and development that promote access to the end product's source materials. Some consider open source a philosophy, others consider it a pragmatic methodology...
software.
Parrot was started by the Perl
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...
community and is developed with help from the open source and free software communities
Free software community
The free-software community is an informal term that refers to the users and developers of free software as well as supporters of the free-software movement. The movement is sometimes referred to as the open-source software community or a subset thereof...
. As a result, it is focused on license compatibility
License compatibility
License compatibility refers to the problem with licenses applied to works subject to copyright, particularly licenses of software packages, which can contain contradictory requirements, rendering it impossible to combine source code from such packages or content from such works in order to create...
(Artistic License 2.0
Artistic License
The Artistic License refers most commonly to the original Artistic License , a software license used for certain free and open source software packages, most notably the standard Perl implementation and most CPAN modules, which are dual-licensed under the Artistic License and the GNU General Public...
), platform compatibility across a broad array of systems, processor architecture compatibility across most modern processors, speed of execution, small size (around 700k depending on platform), and the flexibility to handle the varying demands that Perl 6
Perl 6
Perl 6 is a major revision to the Perl programming language. It is still in development, as a specification from which several interpreter and compiler implementations are being written. It is introducing elements of many modern and historical languages. Perl 6 is intended to have many...
, and most other modern dynamic languages make. Other goals include improving introspection, debugger
Debugger
A debugger or debugging tool is a computer program that is used to test and debug other programs . The code to be examined might alternatively be running on an instruction set simulator , a technique that allows great power in its ability to halt when specific conditions are encountered but which...
capabilities, and compile-time semantic modulation.
Version 1.0, with a stable API
Application programming interface
An application programming interface is a source code based specification intended to be used as an interface by software components to communicate with each other...
for development, was released on March 17, 2009. The current stable production release of Parrot is version 3.10.0 "Apple Pi", released on November 16, 2011.
History
The name Parrot came from an April Fool's joke which announced a hypothetical language, named Parrot, that would unify PythonPython (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...
and Perl
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...
. The name was later adopted by this project (initially a part of the Perl 6 development effort) which aims to support Perl 6, Python, and other programming languages. Several languages are being ported
Porting
In computer science, porting is the process of adapting software so that an executable program can be created for a computing environment that is different from the one for which it was originally designed...
to run on the Parrot virtual machine.
The Parrot Foundation
Parrot Foundation
The Parrot Foundation is a non-profit organization based in the United States established under section 501 of the Internal Revenue Code....
was created in 2008 to hold the copyright
Copyright
Copyright is a legal concept, enacted by most governments, giving the creator of an original work exclusive rights to it, usually for a limited time...
and trademark
Trademark
A trademark, trade mark, or trade-mark is a distinctive sign or indicator used by an individual, business organization, or other legal entity to identify that the products or services to consumers with which the trademark appears originate from a unique source, and to distinguish its products or...
s of the Parrot project, to help drive development of language implementations
Programming language implementation
A programming language implementation is a system for executing programs written in a programming language.There are two general approaches to programming language implementation:...
and the core codebase, to provide a base for growing the Parrot community, and to reach out to other language communities.
Languages
The goal of the Parrot virtual machine is to host client languages and allow inter-operation between them. Several hurdles exist in accomplishing this goal, in particular the difficulty of mapping high-level concepts, data, and data structureData structure
In computer science, a data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.Different kinds of data structures are suited to different kinds of applications, and some are highly specialized to specific tasks...
s between languages.
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 machineJava Virtual Machine
A Java virtual machine is a virtual machine capable of executing Java bytecode. It is the code execution component of the Java software platform. Sun Microsystems stated that there are over 4.5 billion JVM-enabled devices.-Overview:...
and the Common Language Runtime
Common Language Runtime
The Common Language Runtime is the virtual machine component of Microsoft's .NET framework and is responsible for managing the execution of .NET programs. In a process known as just-in-time compilation, the CLR compiles the intermediate language code known as CIL into the machine instructions...
have been designed for statically typed languages, while the languages targeted by Parrot are dynamically typed.
Virtual machines such as the Java virtual machine and the current Perl 5 virtual machine are also stack based
Stack machine
A stack machine may be* A real or emulated computer that evaluates each sub-expression of a program statement via a pushdown data stack and uses a reverse Polish notation instruction set....
. Parrot developers see Parrot's inclusion of registers as an advantage, as it therefore more closely resembles a hardware design, allowing the vast literature on compiler optimization
Compiler optimization
Compiler optimization is the process of tuning the output of a compiler to minimize or maximize some attributes of an executable computer program. The most common requirement is to minimize the time taken to execute a program; a less common one is to minimize the amount of memory occupied...
to be used in generating bytecode for the Parrot virtual machine that could run at speeds closer to machine code
Machine code
Machine code or machine language is a system of impartible instructions executed directly by a computer's central processing unit. Each instruction performs a very specific task, typically either an operation on a unit of data Machine code or machine language is a system of impartible instructions...
. Other register-based virtual machines have inspired parts of Parrot's design, including the Lua VM and Inferno's Dis
Dis virtual machine
The Dis virtual machine is the execution environment for application code in the Inferno operating system. Its design is based on a register machine, closely modeling CISC-like architectures on which it runs...
.
Functional concepts
Parrot has rich support for several features of functional programmingFunctional programming
In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions, in contrast to the imperative programming style, which emphasizes changes in state...
including closures
Closure (computer science)
In computer science, a closure is a function together with a referencing environment for the non-local variables of that function. A closure allows a function to access variables outside its typical scope. Such a function is said to be "closed over" its free variables...
and continuation
Continuation
In computer science and programming, a continuation is an abstract representation of the control state of a computer program. A continuation reifies the program control state, i.e...
s, both of which can be particularly difficult to implement correctly and portably, especially in conjunction with exception handling
Exception handling
Exception handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of exceptions, special conditions that change the normal flow of program execution....
and threading
Thread (computer science)
In computer science, a thread of execution is the smallest unit of processing that can be scheduled by an operating system. The implementation of threads and processes differs from one operating system to another, but in most cases, a thread is contained inside a process...
. Implementing solutions to these problems at the virtual machine level prevents repeated efforts to solve these problems in the individual client languages.
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
Recursive descent parser
A recursive descent parser is a top-down parser built from a set of mutually-recursive procedures where each such procedure usually implements one of the production rules of the grammar...
as well as a operator-precedence parser
Operator-precedence parser
An operator precedence parser is a bottom-up parser that interprets an operator-precedence grammar. For example, most calculators use operator precedence parsers to convert from the human-readable infix notation with order of operations format into an internally optimized computer-readable format...
, 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.
Existing client languages
Many languages already have compiler front-ends designed for Parrot; however, many of them are still only partially functional. The languages currently implementable, partially and fully, on Parrot are:- ArcArc (programming language)Arc is a dialect of the Lisp programming language now under development by Paul Graham and Robert Morris.- History :In 2001 Paul Graham announced that he was working on a new dialect of Lisp named "Arc"...
- APL
- bc
- BefungeBefungeBefunge is a stack-based, reflective, esoteric programming language. It differs from conventional languages in that programs are arranged on a two-dimensional grid...
- BrainfuckBrainfuckThe brainfuck programming language is an esoteric programming language noted for its extreme minimalism. It is a Turing tarpit, designed to challenge and amuse programmers, and is not suitable for practical use...
- CC99C99 is a modern dialect of the C programming language. It extends the previous version with new linguistic and library features, and helps implementations make better use of available computer hardware and compiler technology.-History:...
- Common LispCommon LispCommon Lisp, commonly abbreviated CL, is a dialect of the Lisp programming language, published in ANSI standard document ANSI INCITS 226-1994 , . From the ANSI Common Lisp standard the Common Lisp HyperSpec has been derived for use with web browsers...
- ECMAScriptECMAScriptECMAScript is the scripting language standardized by Ecma International in the ECMA-262 specification and ISO/IEC 16262. The language is widely used for client-side scripting on the web, in the form of several well-known dialects such as JavaScript, JScript, and ActionScript.- History :JavaScript...
(aka JavaScript) - Forth
- Generic Imperative Language
- GNU m4GNU m4GNU m4 is the GNU version of the m4 macro preprocessor. It is designed to avoid many kinds of limits found in traditional m4s: limits like maximum line lengths, maximum size of a macro, number of macros, etc...
- HQ9 Plus
- Jako
- JavaJava (programming language)Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
- Java bytecodeJava bytecodeJava bytecode is the form of instructions that the Java virtual machine executes. Each bytecode opcode is one byte in length, although some require parameters, resulting in some multi-byte instructions. Not all of the possible 256 opcodes are used. 51 are reserved for future use...
- Joy
- Lazy K
- Lisp
- LOLCODELOLCODELOLCODE is an esoteric programming language inspired by the language expressed in examples of the lolcat Internet meme. The language was created in 2007 by Adam Lindsay, researcher at the Computing Department of Lancaster University....
- Lua
- MiniPerl (Perl 1.0)
- NQP (Not Quite Perl)
- Octave
- Ook!
- PerlPerl 6Perl 6 is a major revision to the Perl programming language. It is still in development, as a specification from which several interpreter and compiler implementations are being written. It is introducing elements of many modern and historical languages. Perl 6 is intended to have many...
(via Rakudo) - PHPPHPPHP is a general-purpose server-side scripting language originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document...
(via Pipp) - PythonPython (programming language)Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...
- QuickBASICQuickBASICMicrosoft QuickBASIC is an Integrated Development Environment and compiler for the BASIC programming language that was developed by Microsoft. QuickBASIC runs mainly on DOS, though there was a short-lived version for Mac OS...
4.5 - RubyRuby (programming language)Ruby is a dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features. Ruby originated in Japan during the mid-1990s and was first developed and designed by Yukihiro "Matz" Matsumoto...
(via Cardinal) - Scheme
- ShakespeareShakespeare (programming language)The Shakespeare Programming Language is an esoteric programming language designed by Jon Åslund and Karl Hasselström. Like the Chef programming language, it is designed to make programs appear to be something other than programs; in this case, Shakespearean plays.A character list in the beginning...
- SmalltalkSmalltalkSmalltalk is an object-oriented, dynamically typed, reflective programming language. Smalltalk was created as the language to underpin the "new world" of computing exemplified by "human–computer symbiosis." It was designed and created in part for educational use, more so for constructionist...
(via Chitchat) - the "squaak" tutorial language
- TclTclTcl is a scripting language created by John Ousterhout. Originally "born out of frustration", according to the author, with programmers devising their own languages intended to be embedded into applications, Tcl gained acceptance on its own...
(via partcl) - UnlambdaUnlambdaUnlambda is a minimal, "nearly pure" functional programming language invented by David Madore. It is based on combinatory logic, a version of the lambda calculus that omits the lambda operator. It relies mainly on two built-in functions and an "apply" operator...
- WMLScriptWMLScriptWMLScript is the dialect of JavaScript used for WML pages and is part of the Wireless Application Protocol .WMLScript is a client-side scripting language and is very similar to JavaScript...
- .NET bytecodeCommon Intermediate LanguageCommon Intermediate Language is the lowest-level human-readable programming language defined by the Common Language Infrastructure specification and is used by the .NET Framework and Mono...
Internals
There are three forms of program code for Parrot:- BytecodeBytecodeBytecode, also known as p-code , is a term which has been used to denote various forms of instruction sets designed for efficient execution by a software interpreter as well as being suitable for further compilation into machine code...
is binary and is natively interpreted by Parrot. Bytecode is usually stored in files with the filename extensionFilename extensionA filename extension is a suffix to the name of a computer file applied to indicate the encoding of its contents or usage....
".pbc". - Parrot Assembly LanguageParrot assembly languageThe Parrot assembly language is the basic assembly language used by the Parrot virtual machine.PASM is the lowest level assembly language in the Parrot stack...
(PASM) is the low level language that compileCompilerA compiler is a computer program that transforms source code written in a programming language into another computer language...
s down to bytecode. PASM code is usually stored in files with the filename extension ".pasm". - Parrot Intermediate RepresentationParrot intermediate representationThe Parrot intermediate representation , previously called Intermediate code , is one of the two assembly languages for the Parrot virtual machine. The other is Parrot assembly language or PASM...
(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, and more. PIR code is usually stored in files with the filename extension ".pir".
Registers
Parrot is register-based like most hardware CPUsCentral processing unit
The central processing unit is the portion of a computer system that carries out the instructions of a computer program, to perform the basic arithmetical, logical, and input/output operations of the system. The CPU plays a role somewhat analogous to the brain in the computer. The term has been in...
, and unlike most virtual machines, which are stack-based. Parrot provides four types of registers:
- I: native integerIntegerThe integers are formed by the natural numbers together with the negatives of the non-zero natural numbers .They are known as Positive and Negative Integers respectively...
type - N: floating-pointFloating pointIn computing, floating point describes a method of representing real numbers in a way that can support a wide range of values. Numbers are, in general, represented approximately to a fixed number of significant digits and scaled using an exponent. The base for the scaling is normally 2, 10 or 16...
numbers - S: advanced stringString (computer science)In formal languages, which are used in mathematical logic and theoretical computer science, a string is a finite sequence of symbols that are chosen from a set or alphabet....
registers with UnicodeUnicodeUnicode is a computing industry standard for the consistent encoding, representation and handling of text expressed in most of the world's writing systems...
support - P: PMC, or Polymorphic Container — Parrot object type
Parrot provides an arbitrary number of registers; this number is fixed at compile time per subroutine.
Arithmetic operations
In PASMset 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
Development
Until late 2005, Dan SugalskiDan Sugalski
Dan Sugalski was the initial designer and chief architect for the Parrot process virtual machine that was initially created to run Perl 6. In 2005 Dan handed over Parrot lead duties to Chip Salzenberg and shortly thereafter left the Parrot project....
was the lead designer and chief architect of Parrot. Chip Salzenberg
Chip Salzenberg
Chip Salzenberg is an American programmer mostly noted for his involvement in the Perl and Free Software communities. Salzenberg has been involved with Perl development for over 15 years, and with Free Software for more than 20 years....
, a longtime Perl, Linux kernel, and C++ hacker, took over until mid-2006, when he became the lead developer. Allison Randal
Allison Randal
Allison Randal is a linguist, software developer and author. She is the former chief architect of the Parrot virtual machine, a member of the board of directors for The Perl Foundation, a member of the board of directors for the Python Software Foundation...
, the lead developer of Punie
Punie
Punie is a compiler created as a test case for the Parrot virtual machine. Its goal is to compile Perl v1 code and thereby exercise Parrot's compiler tools.-Status:...
and chief architect of Parrot's compiler tools, was the chief architect until mid-October 2010 when she stepped down and chose Christoph Otto as the new chief architect.
Development discussions take place primarily on the #parrot channel on irc.perl.org. In addition, there are weekly moderated meetings for Parrot and language developers hosted in #parrotsketch on the same network. Much discussion also occurs on the parrot-dev mailing list, hosted by parrot.org.
Design discussions exist in the form of Parrot Design Documents, or PDDs, in the Parrot repository. 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.
The Parrot team releases a new stable version of the software on the third Tuesday of every month. Core committers take turns producing releases in a revolving schedule, where no single committer is responsible for multiple releases in a row. This practice has improved the project's velocity and stability.
See also
- Common Language RuntimeCommon Language RuntimeThe Common Language Runtime is the virtual machine component of Microsoft's .NET framework and is responsible for managing the execution of .NET programs. In a process known as just-in-time compilation, the CLR compiles the intermediate language code known as CIL into the machine instructions...
(CLR) - Comparison of application virtual machinesComparison of Application Virtual MachinesThis article lists some software virtual machines that are typically used for allowing application bytecode to be portably run on many different computer architectures and operating systems. The application is usually run on the computer using an interpreter or just-in-time compilation...
- mod parrotMod parrotmod_parrot is an optional module for the Apache web server. It embeds a Parrot virtual machine interpreter into the Apache server and provides access to the Apache API to allow handlers to be written in Parrot assembly language, or any high-level language targeted to Parrot....
- PL/Parrot