[svn:parrot] r38802 - in trunk/docs/book: . draft

coke at svn.parrot.org coke at svn.parrot.org
Fri May 15 21:14:55 UTC 2009


Author: coke
Date: Fri May 15 21:14:54 2009
New Revision: 38802
URL: https://trac.parrot.org/parrot/changeset/38802

Log:
[docs] Validate more PIR samples; Fix a bug this turned up in one of the samples!

Modified:
   trunk/docs/book/ch05_pge.pod
   trunk/docs/book/ch06_nqp.pod
   trunk/docs/book/draft/chXX_hlls.pod

Modified: trunk/docs/book/ch05_pge.pod
==============================================================================
--- trunk/docs/book/ch05_pge.pod	Fri May 15 21:02:05 2009	(r38801)
+++ trunk/docs/book/ch05_pge.pod	Fri May 15 21:14:54 2009	(r38802)
@@ -99,6 +99,8 @@
 Next, create a small PIR script to run your grammar. Save it as
 F<grammar_test.pir>:
 
+=begin PIR
+
   .sub main :main
       load_bytecode 'PGE.pbc'        # load some required modules
       load_bytecode 'dumper.pbc'
@@ -117,6 +119,8 @@
       _dumper(match, "match")
   .end
 
+=end PIR
+
 Run the test script:
 
   $ B<parrot grammar_test.pir>
@@ -1349,6 +1353,8 @@
 
 ... and its corresponding PIR rule:
 
+=begin PIR
+
  .sub 'infix:+'
     .param pmc a
     .param pmc b
@@ -1357,6 +1363,8 @@
     .return(c)
  .end
 
+=end PIR
+
 You may ask "Why have an C<is subname()> property, if you can define all
 operators as subroutines?" Using the C<is subname()> property allows PCT to
 call a subroutine of a different name then the operator.  This is a good idea
@@ -1366,18 +1374,22 @@
 The great thing about protos being overloadable is that you can specify
 different functions to call with different signatures:
 
+=begin PIR
+
  .sub 'infix:+' :multi('Integer', 'Integer')
-    ...
+    #...
  .end
 
  .sub 'infix:+' :multi('CLispRatio', 'Number')
-    ...
+    #...
  .end
 
  .sub 'infix:+' :multi('Perl6Double', 'PythonInteger')
-    ...
+    #...
  .end
 
+=end PIR
+
 This list can be a bit intimidating, and it's hard to imagine that it would be
 necessary to write up a new function to handle addition between every
 conceivable pair of operands. Fortunately, this is rarely the case in Parrot,

Modified: trunk/docs/book/ch06_nqp.pod
==============================================================================
--- trunk/docs/book/ch06_nqp.pod	Fri May 15 21:02:05 2009	(r38801)
+++ trunk/docs/book/ch06_nqp.pod	Fri May 15 21:14:54 2009	(r38802)
@@ -67,12 +67,16 @@
 
 Which calls the PIR function:
 
+=begin PIR
+
  .namespace []
  .sub 'create_new_array'
      .param pmc elems :slurpy
      .return(elems)
  .end
 
+=end PIR
+
 Remember how we said NQP was a bare-bones subset of Perl 6? It really doesn't
 have a lot of features that programmers might expect. In this chapter we will
 talk about some of the features and capabilities that it does have.

Modified: trunk/docs/book/draft/chXX_hlls.pod
==============================================================================
--- trunk/docs/book/draft/chXX_hlls.pod	Fri May 15 21:02:05 2009	(r38801)
+++ trunk/docs/book/draft/chXX_hlls.pod	Fri May 15 21:14:54 2009	(r38802)
@@ -64,8 +64,12 @@
 will have a common form. If a compiler object is in register C<$P0>, it can
 be stored using the following C<compreg> syntax:
 
+=begin PIR_FRAGMENT
+
   compreg 'MyCompiler', $P0
 
+=end PIR_FRAGMENT
+
 There are two built-in compiler objects: One for PIR and one for PASM. These
 two don't need to be stored first, they can simply be retrieved and used.
 The PIR and PASM compiler objects are Sub PMCs that take a single string
@@ -81,15 +85,23 @@
 importance to many modern dynamic languages.  Here's an example using
 the PIR compiler:
 
+=begin PIR_FRAGMENT
+
+  .local string code
+  code = "..."
   $P0 = compreg 'PIR'      # Get the compiler object
   $P1 = $P0(code)          # Compile the string variable "code"
 
+=end PIR_FRAGMENT
+
 The returned value from invoking the compiler object is an array of PMCs
 that contains the various executable subroutines from the compiled source.
 Here's a more verbose example of this:
 
+=begin PIR_FRAGMENT
+
   $P0 = compreg 'PIR'
-  $S0 = << "END_OF_CODE"
+  $S0 = <<"END_OF_CODE"
 
     .sub 'hello'
        say 'hello world!'
@@ -99,7 +111,7 @@
        say 'goodbye world!'
     .end
 
-  END_OF_CODE
+END_OF_CODE
 
   $P1 = $P0($S0)
   $P2 = $P1[0]      # The sub "hello"
@@ -108,8 +120,12 @@
   $P2()             # "hello world!"
   $P3()             # "goodbye world!"
 
+=end PIR_FRAGMENT
+
 Here's an example of a Read-Eval-Print-Loop (REPL) in PIR:
 
+=begin PIR
+
   .sub main
     $P0 = getstdin
     $P1 = compreg 'PIR'
@@ -124,6 +140,8 @@
       goto loop_top
   .end
 
+=end PIR
+
 The exact list of HLL packages installed on your system may vary. Some
 language compiler packages will exist as part of the Parrot source code
 repository, but many will be developed and maintained separately. In any
@@ -149,20 +167,28 @@
 instead of using the normal built-in types. Mappings can be created with the
 C<"hll_map"> method of the interpreter PMC.
 
+=begin PIR_FRAGMENT
+
   $P0 = newclass "MyNewClass"         # New type
-  $P1 = getclass "ResizablePMCArray"  # Built-in type
+  $P1 = get_class "ResizablePMCArray"  # Built-in type
   $P2 = getinterp
   $P2.'hll_map'($P1, $P0)
 
+=end PIR_FRAGMENT
+
 With the mapping in place, anywhere that Parrot would have used a
 ResizablePMCArray it now uses a MyNewClass object instead. Here's one example
 of this:
 
+=begin PIR
+
   .sub 'MyTestSub'
       .param pmc arglist :slurpy   # A MyNewClass array of args
       .return(arglist)
   .end
 
+=end PIR
+
 =head2 Interoperability Guidelines
 
 =head3 Libraries and APIs


More information about the parrot-commits mailing list