Reference articles on history, science, culture and more
Encyclopedia

Parrot virtual machine

Software to run programming languages

Parrot is a discontinued register-based process virtual machine designed to run dynamic languages efficiently. It is possible to compile Parrot assembly language (PASM) and Parrot intermediate representation (PIR, an intermediate language) to Parrot bytecode and execute it. Parrot is free and open-source software with an Artistic License 2.0.

Parrot was begun by the Perl community and developed with help from the open-source and free software communities. As a result, it was focused on license compatibility with Perl (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 made by Raku and other modern dynamic languages.

Version 1.0, with a stable application programming interface (API) for development, was released on March 17, 2009. The last version is release 8.1.0 "Andean Parakeet".

01History

The name Parrot came from an April Fool's joke which announced a hypothetical language, named Parrot, that would unify Python and Perl. The name was later adopted by the Parrot project (initially a part of the Raku development effort) which aimed to support Raku, Python, and other programming languages.

The Parrot Foundation was dissolved in 2014. The Foundation was created in 2008 to hold the copyright and trademarks 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.

Historical design decisions are documented in the form of Parrot Design Documents, or PDDs, in the Parrot repository.

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, was the chief architect until mid-October 2010 when she stepped down and chose Christoph Otto as the new chief architect.

In August 2021, it was announced that Parrot virtual machine was no longer being actively developed. The post suggested that the role of Parrot as a virtual machine for Perl 6 has been filled by MoarVM.

02Languages

The goal of the Parrot virtual machine was to host client languages and allow inter-operation between them. Several hurdles existed in accomplishing this goal, in particular the difficulty of mapping high-level concepts, data, and data structures between languages.

Static and dynamic languages

The differing properties of statically and dynamically typed languages motivated the design of Parrot. Current popular virtual machines such as the Java virtual machine and the Common Language Runtime (for the .NET platform) 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 chose a register-based design, reasoning that it 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 inspired parts of Parrot's design, including LLVM, the Lua VM and Inferno's Dis.

Functional concepts

Parrot has rich support for several features of functional programming including closures and continuations, both of which can be particularly difficult to implement correctly and portably, especially in conjunction with exception handling and threading. The biggest advantage is the dynamic extendability of objects with methods, which allows for polymorphic containers (PMCs) and associated opcodes. Implementing solutions to these problems at the virtual machine level obviates the need to solve them 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 as well as an 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.

Implementations

The most complete language implementations targeting the Parrot VM were Raku (then named Rakudo Perl 6), Lua, and Winxed. Projects to implement many other languages were started, including BASIC, PHP, Python, and Ruby; and esoteric and demonstration languages such as Befunge and the "squaak" tutorial language. None of these projects were successful in becoming the primary implementation of their respective languages.

03Internals

For Parrot, three forms of program code exist:

  • Bytecode is binary and is natively interpreted by Parrot. Bytecode is usually stored in files with the filename extension ".pbc".
  • Parrot assembly language (PASM) is the low level language that compiles down to bytecode. PASM code is usually stored in files with the filename extension ".pasm".
  • 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, and more. PIR code is usually stored in files with the filename extension ".pir".

04Examples

Registers

Parrot is register-based like most hardware central processing unit (CPUs), 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.

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

05mod_parrot

mod_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.

Watch videos about Parrot virtual machineExplainers and documentaries on YouTube (opens in a new tab)

Sources and credits

This article is adapted from the Wikipedia article Parrot virtual machine, written by its contributors and licensed under CC BY-SA 4.0. Fathomly has changed the layout, removed citation markers, navigation and maintenance notices, and adjusted punctuation. This adapted version is shared under the same license. For references, see the original article.

Fathomly is not affiliated with or endorsed by the Wikimedia Foundation. Spotted a problem? Tell us.