Parrot: Writing PIR

Last modification: 2008/07/20 23:55

Writing PIR

PIR stands for Parrot Intermediate Representation.

It is half-way between PASM (the Parrot Assembly Language) and a full-blown language such as Perl.

Whenever writing programs targeting the Parrot runtime directly, you will almost always use PIR. It abstracts away a number of the nastier problems with assembly language, such as running out of registers for storage and the need to hard code GOTO jumps.

Here's the classic 'Hello World' program:

.sub hello # Trivial example print "Hello world!\n" .end

To run this, save this text as hello.pir, fire up a command line shell with the parrot executable on the path and type:

parrot hello.pir

"Hello world!" should be printed on the screen.


More detailed tutorials can be accessed from the following links:

Tutorial 1: Local variables
Tutorial 2: Branch control
Tutorial 3: Perl Magic Cookies
Tutorial 4: Subroutines
Tutorial 5: Arrays and Hashes
Tutorial 6: Classes and Objects