[svn:parrot] r37604 - trunk/docs
coke at svn.parrot.org
coke at svn.parrot.org
Fri Mar 20 01:22:53 UTC 2009
Author: coke
Date: Fri Mar 20 01:22:52 2009
New Revision: 37604
URL: https://trac.parrot.org/parrot/changeset/37604
Log:
[docs/t] add more PIR targets so this code is eventually validated.
Modified:
trunk/docs/intro.pod
Modified: trunk/docs/intro.pod
==============================================================================
--- trunk/docs/intro.pod Fri Mar 20 01:10:13 2009 (r37603)
+++ trunk/docs/intro.pod Fri Mar 20 01:22:52 2009 (r37604)
@@ -173,10 +173,14 @@
Create a file called F<hello.pir> that contains the following code.
+=begin PIR
+
.sub main
print "Hello world!\n"
.end
+=end PIR
+
Then run it by typing:
parrot hello.pir
@@ -195,30 +199,42 @@
We can modify hello.pir to first store the string C<Hello world!\n> in a
register and then use that register with the print instruction.
+=begin PIR
+
.sub main
set S0, "Hello world!\n"
print S0
.end
+=end PIR
+
Here we have stated exactly which register to use. However, by
replacing C<S0> with C<$S0> we can delegate the choice of which
register to use to Parrot. It is also possible to use an C<=>
notation instead of writing the C<set> instruction.
+=begin PIR
+
.sub main
$S0 = "Hello world!\n"
print $S0
.end
+=end PIR
+
To make PIR even more readable, named registers can be used. These are later
mapped to real numbered registers.
+=begin PIR
+
.sub main
.local string hello
hello = "Hello world!\n"
print hello
.end
+=end PIR
+
The C<.local> directive indicates that the named register is only needed inside
the current subroutine (that is, between C<.sub> and C<.end>). Following
C<.local> is a type. This can be C<int> (for I registers), C<float> (for N
@@ -236,6 +252,8 @@
This example introduces some more instructions and PIR syntax. Lines starting
with a C<#> are comments.
+=begin PIR
+
.sub main
# State the number of squares to sum.
.local int maxnum
@@ -262,6 +280,8 @@
print ".\n"
.end
+=end PIR
+
PIR provides a bit of syntactic sugar that makes it look more high level than
assembly. For example:
@@ -299,6 +319,8 @@
In this example we define a factorial function and recursively call it to
compute factorial.
+=begin PIR
+
.sub factorial
# Get input parameter.
.param int n
@@ -338,6 +360,8 @@
if i <= 10 goto loop
.end
+=end PIR
+
The first line, C<.param int n>, specifies that this subroutine takes one
integer parameter and that we'd like to refer to the register it was passed in
by the name C<n> for the rest of the sub.
More information about the parrot-commits
mailing list