Parrot virtual machine

Last updated
Parrot virtual machine
Final release
8.1.0 / February 16, 2016;8 years ago (2016-02-16) [1]
Repository
Written in C
Operating system Cross-platform
Successor MoarVM (for Raku)
Type Virtual machine
License Artistic License 2.0
Website www.parrot.org OOjs UI icon edit-ltr-progressive.svg

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

Contents

Parrot was started 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. [3] The last version is release 8.1.0 "Andean Parakeet". [1] Parrot was officially discontinued in August 2021, after being supplanted by MoarVM in its main use (Raku) and never becoming a mainstream VM for any of its other supported languages. [4]

History

The name Parrot came from an April Fool's joke which announced a hypothetical language, named Parrot, that would unify Python and Perl. [5] [6] 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. [7] 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. [8]

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

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. [10]

Languages

The goal of the Parrot virtual machine was 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 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 [ citation needed ]. 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 these problems in the individual client languages.

Compiler tools

Parrot provides a suite of compiler-writing tools [11] 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 (known at the time as Rakudo Perl 6), Lua and a new language called "Winxed". [12] Projects to implement many other languages were started, including PHP, Python, and Ruby; along with esoteric and demonstration languages such as Befunge and the "squaak" tutorial language. [13] None of these projects were successful in becoming the primary implementation of their respective languages. [4]

Internals

There are three forms of program code for Parrot:

Examples

Registers

Parrot is register-based like most hardware 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

setI1,4incI1# I1 is now 5addI1,2# I1 is now 7setN1,42.0decN1# N1 is now 41.0subN1,2.0# N1 is now 39.0printI1print','printN1print"\n"end

In PIR

 .sub'main' :main$I1 = 4inc$I1# $I1 is now 5$I1 += 2# $I1 is now 7$N1 = 42.0dec$N1# $N1 is now 41.0$N1 -= 2.0# $N1 now 39.0print$I1print', 'print$N1print"\n"  .end

See also

Related Research Articles

<span class="mw-page-title-main">Java virtual machine</span> Virtual machine that runs Java programs

A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode. The JVM is detailed by a specification that formally describes what is required in a JVM implementation. Having a specification ensures interoperability of Java programs across different implementations so that program authors using the Java Development Kit (JDK) need not worry about idiosyncrasies of the underlying hardware platform.

<span class="mw-page-title-main">Perl</span> Interpreted programming language first released in 1987

Perl is a high-level, general-purpose, interpreted, dynamic programming language. Though Perl is not officially an acronym, there are various backronyms in use, including "Practical Extraction and Reporting Language".

In computer programming, a p-code machine is a virtual machine designed to execute p-code. This term is applied both generically to all such machines, and to specific implementations, the most famous being the p-Machine of the Pascal-P system, particularly the UCSD Pascal implementation, among whose developers, the p in p-code was construed to mean pseudo more often than portable, thus pseudo-code meaning instructions for a pseudo-machine.

<span class="mw-page-title-main">Ruby (programming language)</span> General-purpose programming language

Ruby is an interpreted, high-level, general-purpose programming language that supports multiple programming paradigms. It was designed with an emphasis on programming productivity and simplicity. In Ruby, everything is an object, including primitive data types. It was developed in the mid-1990s by Yukihiro "Matz" Matsumoto in Japan.

<span class="mw-page-title-main">Interpreter (computing)</span> Program that executes source code without a separate compilation step

In computer science, an interpreter is a computer program that directly executes instructions written in a programming or scripting language, without requiring them previously to have been compiled into a machine language program. An interpreter generally uses one of the following strategies for program execution:

  1. Parse the source code and perform its behavior directly;
  2. Translate source code into some efficient intermediate representation or object code and immediately execute that;
  3. Explicitly execute stored precompiled bytecode made by a compiler and matched with the interpreter’s Virtual Machine.

Bytecode is a form of instruction set designed for efficient execution by a software interpreter. Unlike human-readable source code, bytecodes are compact numeric codes, constants, and references that encode the result of compiler parsing and performing semantic analysis of things like type, scope, and nesting depths of program objects.

In computing, just-in-time (JIT) compilation is compilation during execution of a program rather than before execution. This may consist of source code translation but is more commonly bytecode translation to machine code, which is then executed directly. A system implementing a JIT compiler typically continuously analyses the code being executed and identifies parts of the code where the speedup gained from compilation or recompilation would outweigh the overhead of compiling that code.

The Parrot assembly language (PASM) is the basic assembly language used by the Parrot virtual machine.

<span class="mw-page-title-main">Raku (programming language)</span> Programming language derived from Perl

Raku is a member of the Perl family of programming languages. Formerly known as Perl 6, it was renamed in October 2019. Raku introduces elements of many modern and historical languages. Compatibility with Perl was not a goal, though a compatibility mode is part of the specification. The design process for Raku began in 2000.

An intermediate representation (IR) is the data structure or code used internally by a compiler or virtual machine to represent source code. An IR is designed to be conducive to further processing, such as optimization and translation. A "good" IR must be accurate – capable of representing the source code without loss of information – and independent of any particular source or target language. An IR may take one of several forms: an in-memory data structure, or a special tuple- or stack-based code readable by the program. In the latter case it is also called an intermediate language.

Pugs is a compiler and interpreter for the Raku programming language, started on February 1, 2005, by Audrey Tang.

The Parrot intermediate representation (PIR), previously called Intermediate code (IMC), is one of the two assembly languages for the Parrot virtual machine. The other is Parrot assembly language or PASM. Compared to PASM, PIR exists at a slightly higher abstraction layer, and provides temporary registers and named registers, simplifying code generation.

In computer programming, a programming language implementation is a system for executing computer programs. There are two general approaches to programming language implementation:

Raku rules are the regular expression, string matching and general-purpose parsing facility of the Raku programming language, and are a core part of the language. Since Perl's pattern-matching constructs have exceeded the capabilities of formal regular expressions for some time, Raku documentation refers to them exclusively as regexes, distancing the term from the formal definition.

The Parser Grammar Engine is a compiler and runtime for Raku rules for the Parrot virtual machine. PGE uses these rules to convert a parsing expression grammar into Parrot bytecode. It is therefore compiling rules into a program, unlike most virtual machines and runtimes, which store regular expressions in a secondary internal format that is then interpreted at runtime by a regular expression engine. The rules format used by PGE can express any regular expression and most formal grammars, and as such it forms the first link in the compiler chain for all of Parrot's front-end languages.

NekoVM is a virtual machine developed by Nicolas Cannasse as part of research and development (R&D) efforts at two independent video game developers in Bordeaux, France: first at Motion Twin and then at Shiro Games. NekoVM's native language is the bytecode for a high-level dynamically typed programming language called Neko. This pairing allows Neko to be used directly as an embedded scripting language, or to target NekoVM by compiling another language to NekoVM bytecode.

<span class="mw-page-title-main">Rakudo</span>

Rakudo is a Raku compiler targeting MoarVM, and the Java Virtual Machine, that implements the Raku specification. It is currently the only major Raku compiler in active development.

The Perl virtual machine is a stack-based process virtual machine implemented as an opcodes interpreter which runs previously compiled programs written in the Perl language. The opcodes interpreter is a part of the Perl interpreter, which also contains a compiler in one executable file, commonly /usr/bin/perl on various Unix-like systems or perl.exe on Microsoft Windows systems.

Tracing just-in-time compilation is a technique used by virtual machines to optimize the execution of a program at runtime. This is done by recording a linear sequence of frequently executed operations, compiling them to native machine code and executing them. This is opposed to traditional just-in-time (JIT) compilers that work on a per-method basis.

Java bytecode is the instruction set of the Java virtual machine (JVM), crucial for executing programs written in the Java language and other JVM-compatible languages. Each bytecode operation in the JVM is represented by a single byte, hence the name "bytecode", making it a compact form of instruction. This intermediate form enables Java programs to be platform-independent, as they are compiled not to native machine code but to a universally executable format across different JVM implementations.

References

  1. 1 2 "New supported release 8.1.0 "Andean Parakeet"". Parrot Foundation. 2016-02-16. Retrieved 2016-09-26.
  2. "Parrot Contributor License Agreement 1.0" (PDF). Parrot Foundation. Archived from the original (PDF) on 2010-08-16. Retrieved 2009-03-18.
  3. "Parrot Roadmap". Parrot Foundation. 2008-11-20. Archived from the original on 2010-04-15. Retrieved 2008-11-20.
  4. 1 2 "Inactive Parrot | Parrot VM". www.parrot.org.
  5. "The Story Behind the Parrot Prank - O'Reilly Media". Oreilly.com. 2001-04-06. Retrieved 2014-02-25.
  6. "Programming Parrot". Perl.com. Archived from the original on 2010-07-18. Retrieved 2014-02-25.
  7. "Corporations Advanced Search". Washington State Department of Licensing. UBI 602 839 536. Retrieved 2021-04-09.
  8. Announcing the Parrot Foundation Archived June 29, 2008, at the Wayback Machine
  9. "Parrot 6.1.0 - Parrot Design Documents (PDDs)". Docs.parrot.org. Retrieved 2014-02-25.
  10. Otto, Christoph (2010-10-21). "reparrot: Parrot has a new architect. What now?". Reparrot.blogspot.com. Retrieved 2014-02-25.
  11. Archived May 9, 2009, at the Wayback Machine
  12. "Languages - Parrot VM". parrot.org. Retrieved 2023-11-18.
  13. "Languages – Parrot". Parrot development wiki. Retrieved 2023-11-18.
  14. "The Parrot Bytecode (PBC) Format - parrotcode". Archived from the original on 2008-12-24. Retrieved 2009-07-15.
  15. Archived July 20, 2009, at the Wayback Machine