[svn:parrot] r38812 - trunk/docs/imcc

coke at svn.parrot.org coke at svn.parrot.org
Sat May 16 02:13:00 UTC 2009


Author: coke
Date: Sat May 16 02:13:00 2009
New Revision: 38812
URL: https://trac.parrot.org/parrot/changeset/38812

Log:
[docs] Mark & test more PIR/PASM examples.

This pointed out some remnants of some old 'global' syntax, updated so test passes.

Modified:
   trunk/docs/imcc/imcfaq.pod
   trunk/docs/imcc/operation.pod

Modified: trunk/docs/imcc/imcfaq.pod
==============================================================================
--- trunk/docs/imcc/imcfaq.pod	Sat May 16 02:08:14 2009	(r38811)
+++ trunk/docs/imcc/imcfaq.pod	Sat May 16 02:13:00 2009	(r38812)
@@ -137,11 +137,15 @@
 The basic block of execution of an IMC program is the subroutine. Subs can be
 simple, with no arguments or returns. Line comments are allowed in IMC using #.
 
+=begin PIR
+
 	# Hello world
 	.sub main :main
 	  print "Hello world.\n"
 	.end
 
+=end PIR
+
 =head2 Tutorial
 
 For more examples see the PIR tutorial in F<examples/tutorial>.
@@ -207,11 +211,15 @@
 
 Example:
 
+=begin PIR_FRAGMENT
+
 	$S1 = "hiya"
 	$S2 = $S1 . "mel"
 	$I1 = 1 + 2
 	$I2 = $I1 * 3
 
+=end PIR_FRAGMENT
+
 This example uses symbolic STRING and INTVAL registers as temporaries. This is
 the typical sort of code that compilers generate from the syntax tree.
 
@@ -225,6 +233,8 @@
 
 Example:
 
+=begin PIR
+
 	.sub _main :main
 	   .local int i
 	   .local num n
@@ -232,24 +242,28 @@
 	   n = 5.003
 	.end
 
+=end PIR
 
 =head2 How do I declare global or package variables in PIR?
 
 You can't. You can explicitly create global variables at runtime, however,
 but it only works for PMC types, like so:
 
+=begin PIR
+
 	.sub _main :main
 	   .local pmc i
 	   .local pmc j
 	   i = new 'Integer'
 	   i = 123
 	   # Create the global
-	   global "i" = i
+	   set_global "i", i
 
 	   # Refer to the global
-	   j = global "i"
+	   j = get_global "i"
 	.end
 
+=end PIR
 
 Happy Hacking.
 

Modified: trunk/docs/imcc/operation.pod
==============================================================================
--- trunk/docs/imcc/operation.pod	Sat May 16 02:08:14 2009	(r38811)
+++ trunk/docs/imcc/operation.pod	Sat May 16 02:13:00 2009	(r38812)
@@ -68,15 +68,19 @@
 This also means that you currently can't use the same global symbol (e.g.
 subroutine name) in different namespaces. The following creates invalid code:
 
+=begin PIR_INVALID
+
   .sub main
-     ...
+     #...
   .end
 
    .namespace ["main"]
   .sub main
-     ...
+     #...
   .end
 
+=end PIR_INVALID
+
 Local labels in different I<compilation units> with the same name are
 allowed, though assembling the generated PASM doesn't work. However,
 running this code inside imcc is ok. This will probably change in the
@@ -94,14 +98,22 @@
 of another variable, they might get the same parrot register. For
 instance:
 
+=begin PIR_FRAGMENT
+
    $I0 = 10
    $I1 = 20
 
+=end PIR_FRAGMENT
+
 will translate to
 
+=begin PASM
+
    set I0, 10
    set I0, 20
 
+=end PASM
+
 provided that $I0 is not used after these lines. In this case, the
 assignment to $I0 is redundant and will be optimized away if IMCC is
 run with optimization level B<-O2>.
@@ -143,33 +155,39 @@
 
 Consider these two code snippets (block numbers are attached):
 
+=begin PIR
+
   .sub main :main
- 0      $I0 = 0     # initialized
- 0      if $I0 goto l1
- 1      $I1 = 1     # init in block 1
- 1      goto l2
- 2  l1:
- 2      $I1 = 2     # init in block 2
- 3  l2:
- 3      print $I0
- 3      print $I1   # all paths leading here do init
- 3      print "\n"
- 3      end
+      $I0 = 0        # 0 initialized
+      if $I0 goto l1 # 0
+      $I1 = 1        # 1 init
+      goto l2        # 1
+  l1:                # 2
+      $I1 = 2        # 2 init
+  l2:                # 3
+      print $I0      # 3
+      print $I1      # 3 all paths leading here do init
+      print "\n"     # 3
   .end
 
+=end PIR
+
 and:
 
+=begin PIR
+
   .sub main :main
- 0      $I0 = 0     # initialized
- 0      if $I0 goto l1  # branch to bb 1 or 2
- 1      $I1 = 1     # init only in block 1
- 2  l1:
- 2      print $I0
- 2      print $I1   # no init in code path from block 0
- 2      print "\n"
- 2      end
+      $I0 = 0         # 0 initialized
+      if $I0 goto l1  # 0 branch to bb 1 or 2
+      $I1 = 1         # 1 init only in block 1
+  l1:                 # 2
+      print $I0       # 2
+      print $I1       # 2 no init in code path from block 0
+      print "\n"      # 2
   .end
 
+=end PIR
+
 The latter of these emits the warning:
 
   warning:imcc:propagate_need: '$I1' might be used \
@@ -208,18 +226,30 @@
 
 A sequence of code:
 
+=begin PIR_FRAGMENT
+
+    .local pmc cond
+    # ...
     if cond, L1
     branch L2
  L1:
- ...
+    # ...
  L2:
 
+=end PIR_FRAGMENT
+
 will be converted to
 
+=begin PIR_FRAGMENT
+    
+    .local pmc cond
+    # ...
     unless cond, L2
-    ...
+    # ...
  L2:
 
+=end PIR_FRAGMENT
+
 The same is done for other conditional branches B<gt>, B<ge>, B<eq>
 and their reverse meanings.
 
@@ -245,14 +275,22 @@
 
 For a sequence of code
 
+=begin PIR_FRAGMENT
+
    $I0 = 10
    $I1 = 20
 
+=end PIR_FRAGMENT
+
 where B<$I0> is not used again, the first assignment will be tossed,
 resulting in code like:
 
+=begin PASM
+
    set I0, 20
 
+=end PASM
+
 =head2 Loop optimization
 
 Instructions which are invariant to a loop are pulled out of the loop


More information about the parrot-commits mailing list