Author: bernhard
Date: Mon Oct 24 15:36:35 2005
New Revision: 9549

Added:
   trunk/examples/pir/life.pir
      - copied, changed from r9548, trunk/examples/assembly/life.pasm
Removed:
   trunk/examples/assembly/life.pasm
Modified:
   trunk/MANIFEST
   trunk/t/examples/pir.t
Log:
Make the example 'assembly/life.pasm' work again,
after pushi and popi are gone.
Move it to pir/life.pir, convert it to PIR baby talk
and add a test in pir.t 


Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST      (original)
+++ trunk/MANIFEST      Mon Oct 24 15:36:35 2005
@@ -447,7 +447,6 @@ encodings/utf8.h                        
 examples/README                                   [main]doc
 examples/assembly/acorn.l                         [main]doc
 examples/assembly/hello-dwim.imc                  [main]doc
-examples/assembly/life.pasm                       [main]doc
 examples/assembly/local_label.pasm                [main]doc
 examples/assembly/mandel.pasm                     [main]doc
 examples/assembly/mops.pasm                       [main]doc
@@ -599,6 +598,7 @@ examples/pir/circle.pir                 
 examples/pir/euclid.pir                           [main]doc
 examples/pir/hanoi.pir                            [main]doc
 examples/pir/io.pir                               [main]doc
+examples/pir/life.pir                             [main]doc
 examples/pir/mandel.pir                           [main]doc
 examples/pir/sudoku.pir                           [main]doc
 examples/pni/PQt.C                                [main]doc

Copied: trunk/examples/pir/life.pir (from r9548, 
trunk/examples/assembly/life.pasm)
==============================================================================
--- trunk/examples/assembly/life.pasm   (original)
+++ trunk/examples/pir/life.pir Mon Oct 24 15:36:35 2005
@@ -1,23 +1,48 @@
-# Copyright (C) 2001-2003 The Perl Foundation.  All rights reserved.
+# Copyright (C) 2001-2005 The Perl Foundation.  All rights reserved.
 # $Id$
 
 =head1 NAME
 
-examples/assembly/life.pasm - Conway's Life
+examples/pir/life.pir - Conway's Life
 
 =head1 SYNOPSIS
 
-    % ./parrot examples/assembly/life.pasm
+    % ./parrot examples/pir/life.pir
 
 =head1 DESCRIPTION
 
 Runs Conway's Life cellular automata
 
(L<http://ddi.cs.uni-potsdam.de/HyFISCH/Produzieren/lis_projekt/proj_gamelife/ConwayScientificAmerican.htm>).
 
+=head1 TODO
+
+Convert this into proper PIR.
+
+=head1 SEE ALSO
+
+F<examples/assembly/ncurses_life.imc>.
+
 =cut
 
+.sub 'life' :main
+        .param pmc argv
+        .local int max_generations
+
        # First the generation count
+        I15 = argv
+        if I15 < 2 goto USE_DEFAULT_MAX_GENERATIONS
+        S5 = argv[1]
+        I2 = S5
+        print "Running "
+        print I2
+        print " generations.\n"
+        goto MAX_GENERATIONS_IS_NOW_KNOWN
+USE_DEFAULT_MAX_GENERATIONS:
+        print "Running 5000 generations by default.\n"
        set I2, 5000
+MAX_GENERATIONS_IS_NOW_KNOWN:
+        print "\n"
+
        # Note the time
        time N5
        # If true, we don't print
@@ -118,7 +143,10 @@ getout:    time N6
 # I2 is the count for that cell
 # I3 is the offset to the neighbor
 generate:
-       pushi
+       save I0
+       save I1
+       save I2
+       save I3
        length I0, S15
        set S1, ""
        set I1, 0
@@ -213,36 +241,31 @@ iter_done:
        lt I1, I0, genloop
 done:
        set S15, S1
-       popi
+       restore I3
+       restore I2
+       restore I1
+       restore I0
        ret
 
 # S15 has the incoming string, S0 is scratch
 dump:
        if I12, dumpend
        print "\f"
-       save I0
-       save I1
        print "\n\n\n\n\n\n\n\n\n\n\n"
        print "------------- generation "
        print I0
        print " -------------\n"
-       set I0, 0
-       set I1, 14
+       set I10, 0
+       set I11, 14
 printloop:
-       substr_r S0, S15, I0, 15
+       substr_r S0, S15, I10, 15
        print S0
        print "\n"
-       add I0, I0, 15
-       dec I1
-       ge I1, 0, printloop
-       restore I1
-       restore I0
+       add I10, I10, 15
+       dec I11
+       ge I11, 0, printloop
        sleep 1
 dumpend:
        ret
 
-=head1 SEE ALSO
-
-F<examples/assembly/ncurses_life.imc>.
-
-=cut
+.end

Modified: trunk/t/examples/pir.t
==============================================================================
--- trunk/t/examples/pir.t      (original)
+++ trunk/t/examples/pir.t      Mon Oct 24 15:36:35 2005
@@ -32,7 +32,7 @@ Bernhard Schmalhofer - <Bernhard.Schmalh
 =cut
 
 use strict;
-use Parrot::Test tests => 6;
+use Parrot::Test tests => 7;
 use Test::More;
 use Parrot::Config;
 
@@ -174,3 +174,12 @@ while ( my ( $example, $expected ) = eac
       ok( defined $extension, "no extension recognized for $code_fn" );
     }
 }
+
+# For testing life.pir, the number of generations should be small,
+# because users should not get bored.
+{
+    my $life_fn = "examples$PConfig{slash}pir$PConfig{slash}life.pir";
+    my $sum = `$PARROT $life_fn 4`;
+    like( $sum, qr/4 generations in/, 'life ran for 4 generations' );
+}
+

Reply via email to