Author: bernhard
Date: Mon Oct 17 12:48:05 2005
New Revision: 9502

Added:
   trunk/examples/pasm/99beer.pasm
      - copied unchanged from r9501, trunk/examples/assembly/99beer.pasm
   trunk/examples/pasm/cat.pasm
      - copied unchanged from r9501, trunk/examples/assembly/cat.pasm
   trunk/examples/pir/euclid.pir
      - copied, changed from r9501, trunk/examples/assembly/euclid.pasm
   trunk/examples/subs/bsr_ret.pasm
      - copied unchanged from r9501, trunk/examples/assembly/bsr.pasm
   trunk/examples/subs/coroutine.pasm
      - copied, changed from r9501, trunk/examples/assembly/coroutine.pasm
Removed:
   trunk/examples/assembly/99beer.pasm
   trunk/examples/assembly/bsr.pasm
   trunk/examples/assembly/cat.pasm
   trunk/examples/assembly/coroutine.pasm
   trunk/examples/assembly/euclid.pasm
Modified:
   trunk/MANIFEST
   trunk/t/examples/pir.t
   trunk/t/examples/subs.t
Log:
Move some examples from 'assembly' to 'pir', 'pasm' and 'subs'.
Convert example euclid.pasm to PIR.
Fix example coroutine.pasm.
Add tests for euclid.pir, bsr_ret.pasm and coroutine.pasm


Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST      (original)
+++ trunk/MANIFEST      Mon Oct 17 12:48:05 2005
@@ -443,13 +443,8 @@ encodings/fixed_8.h                     
 encodings/utf8.c                                  []
 encodings/utf8.h                                  []
 examples/README                                   [main]doc
-examples/assembly/99beer.pasm                     [main]doc
 examples/assembly/Makefile                        [main]doc
 examples/assembly/acorn.l                         [main]doc
-examples/assembly/bsr.pasm                        [main]doc
-examples/assembly/cat.pasm                        [main]doc
-examples/assembly/coroutine.pasm                  [main]doc
-examples/assembly/euclid.pasm                     [main]doc
 examples/assembly/hanoi.pasm                      [main]doc
 examples/assembly/hello.pasm                      [main]doc
 examples/assembly/hello-dwim.imc                  [main]doc
@@ -602,7 +597,10 @@ examples/mops/mops.ps                   
 examples/mops/mops.py                             [main]doc
 examples/mops/mops.rb                             [main]doc
 examples/mops/mops.scheme                         [main]doc
+examples/pasm/99beer.pasm                         [main]doc
+examples/pasm/cat.pasm                            [main]doc
 examples/pasm/fact.pasm                           [main]doc
+examples/pir/euclid.pir                           [main]doc
 examples/pir/mandel.pir                           [main]doc
 examples/pir/sudoku.pir                           [main]doc
 examples/pni/PQt.C                                [main]doc
@@ -634,6 +632,8 @@ examples/sdl/tetris/boarddata.imc       
 examples/sdl/tetris/board.imc                     [main]doc
 examples/sdl/tetris/eventhandler.imc              [main]doc
 examples/sdl/tetris/tetris.imc                    [main]doc
+examples/subs/bsr_ret.pasm                        [main]doc
+examples/subs/coroutine.pasm                      [main]doc
 examples/subs/pasm_sub1.pasm                      [main]doc
 examples/subs/sub1.imc                            [main]doc
 examples/subs/sub2.imc                            [main]doc

Copied: trunk/examples/pir/euclid.pir (from r9501, 
trunk/examples/assembly/euclid.pasm)
==============================================================================
--- trunk/examples/assembly/euclid.pasm (original)
+++ trunk/examples/pir/euclid.pir       Mon Oct 17 12:48:05 2005
@@ -5,11 +5,11 @@
 
 =head1 NAME
 
-examples/assembly/euclid.pasm - Euclid's algorithm
+examples/pir/euclid.pir - Euclid's algorithm
 
 =head1 SYNOPSIS
 
-    % ./parrot examples/assembly/euclid.pasm
+    % ./parrot examples/pir/euclid.pir
 
 =head1 DESCRIPTION
 
@@ -31,14 +31,16 @@ Page 2:
 
 =cut
 
-main:   set    I1, 96
-        set    I2, 64
+.sub 'example' :main
+        I1 = 96
+        I2 = 64
         print  "Algorithm E (Euclid's algorithm)\n"
-e1:     mod    I4, I1, I2
-e2:     eq     I4, 0, done
-e3:     set    I1, I2
-        set    I2, I4
+e1:     I4 = mod I1, I2
+e2:     unless I4 goto done
+e3:     I1 = I2
+        I2 = I4
         branch e1
-done:   print  I2
-        print  "\n"
-        end
+done:   print "The greatest common denominator of 96 and 64 is "
+        print  I2
+        print  ".\n"
+.end

Copied: trunk/examples/subs/coroutine.pasm (from r9501, 
trunk/examples/assembly/coroutine.pasm)
==============================================================================
--- trunk/examples/assembly/coroutine.pasm      (original)
+++ trunk/examples/subs/coroutine.pasm  Mon Oct 17 12:48:05 2005
@@ -15,30 +15,31 @@ This shows you how to create two corouti
 
 =cut
 
-set_addr I0, MYCOROUTINE
-new P0, .Coroutine
-set P0, I0
-save P0
-new P0, .Coroutine
-set P0, I0
+# create a coro and save it on the user stack
+newsub P0, .Coroutine, MYCOROUTINE
+
+# create a second coro
+newsub P1, .Coroutine, MYCOROUTINE
+
 # Calling convention says P0 will contain the sub so..
 print "Calling 1st co-routine\n"
-invoke
-invoke
-invoke
-restore P0
+invokecc P0
+invokecc P0
+invokecc P0
+
 print "Calling 2nd co-routine\n"
-invoke
-invoke
-invoke
+invokecc P1
+invokecc P1
+invokecc P1
+
 end
 
 # A coroutine
 MYCOROUTINE:
-print "Entry\n"
-invoke
-print "Resumed\n"
-invoke
-print "Done\n"
-invoke
+    print "Entry\n"
+    yield
+    print "Resumed\n"
+    yield
+    print "Done\n"
+    yield
 

Modified: trunk/t/examples/pir.t
==============================================================================
--- trunk/t/examples/pir.t      (original)
+++ trunk/t/examples/pir.t      Mon Oct 17 12:48:05 2005
@@ -32,7 +32,7 @@ Bernhard Schmalhofer - <Bernhard.Schmalh
 =cut
 
 use strict;
-use Parrot::Test tests => 2;
+use Parrot::Test tests => 3;
 use Test::More;
 use Parrot::Config;
 
@@ -40,6 +40,11 @@ my $PARROT = ".$PConfig{slash}$PConfig{t
 
 # Set up expected output for examples
 my %expected = (
+    'euclid.pir'        =>  << 'END_EXPECTED',
+Algorithm E (Euclid's algorithm)
+The greatest common denominator of 96 and 64 is 32.
+END_EXPECTED
+
     'mandel.pir'        =>  << 'END_EXPECTED',
 ................::::::::::::::::::::::::::::::::::::::::::::...............
 ...........::::::::::::::::::::::::::::::::::::::::::::::::::::::..........

Modified: trunk/t/examples/subs.t
==============================================================================
--- trunk/t/examples/subs.t     (original)
+++ trunk/t/examples/subs.t     Mon Oct 17 12:48:05 2005
@@ -19,16 +19,35 @@ Test the examples in F<examples/subs>.
 =head1 SEE ALSO
 
 F<t/examples/japh.t>
-F<t/examples/assembly.t>
+F<t/examples/pasm.t>
 
 =cut
 
 use strict;
-use Parrot::Test tests => 4;
+use Parrot::Test tests => 6;
 use Test::More;
 
 # Set up expected output for examples
 my %expected = (
+    'bsr_ret.pasm'        =>  << 'END_EXPECTED',
+Main
+TestSub
+NestSub
+TestSub: Ret from NestSub
+Main: Return from TestSub
+END_EXPECTED
+
+    'coroutine.pasm'        =>  << 'END_EXPECTED',
+Calling 1st co-routine
+Entry
+Resumed
+Done
+Calling 2nd co-routine
+Entry
+Resumed
+Done
+END_EXPECTED
+
     'pasm_sub1.pasm'        =>  << 'END_EXPECTED',
 Hello from subroutine
 Hello from main
@@ -53,8 +72,7 @@ my %test_func = ( pasm => \&pasm_output_
                   pir  => \&pir_output_is,
                   imc  => \&pir_output_is );
 
-while ( my ( $example, $expected ) = each %expected )
-{
+while ( my ( $example, $expected ) = each %expected ) {
     my $code_fn   = "examples/subs/$example";
     my $code = Parrot::Test::slurp_file($code_fn);
 

Reply via email to