For faster navigation, this Iframe is preloading the Wikiwand page for Parrot intermediate representation.

Parrot intermediate representation

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.

While Parrot is still evolving, it is currently being used in many different capacities, and has undergone several releases.

Overview

[edit]

PIR provides a set of abstractions that allow the programmer to ignore certain redundancies in the Parrot bytecode and quickly write code that adheres to the complexities of Parrot, such as the calling conventions.

Abstractions

[edit]

PIR provides both type abstraction and polymorphism to some degree. For example, the "+" operator can be used with int, num or both:

 .local int a
 .local num b
 a = 1
 b = 1.1
 .local num c
 c = a + b

Calling conventions

[edit]

The calling conventions in Parrot are complex, but all of that complexity can be hidden by using PIR directives:

 .sub foo
  .param int a
  .param int b
  .local int tmp
  tmp = a + b
  .return (tmp)
 .end

Each of the directives prefixed with a "." expands to the required Parrot bytecode, but does not directly represent any fundamental Parrot operation.

Example

[edit]

The hello world program in PIR is

 .sub hello :main
  print "Hello world!\n"
 .end

If the program is saved as hello.pir, it can be compiled and executed with this command: parrot hello.pir

[edit]
{{bottomLinkPreText}} {{bottomLinkText}}
Parrot intermediate representation
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 ๐ŸŽ‰! the new version arrives on September 1st! Don't want to wait?