Author: bernhard
Date: Sun Oct 23 11:13:35 2005
New Revision: 9537

Added:
   trunk/examples/pasm/lexical.pasm
      - copied, changed from r9536, trunk/examples/assembly/lexical.pasm
Removed:
   trunk/examples/assembly/lexical.pasm
   trunk/examples/assembly/lexical2.pasm
   trunk/examples/assembly/lexical3.pasm
Modified:
   trunk/MANIFEST
   trunk/t/examples/pasm.t
Log:
Merge lexical.pasm, lexical2.pasm, lexical3.pasm in 'examples/assembly'
into 'examples/pasm/lexical.pasm.
Make the output more verbose and add a test.


Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST      (original)
+++ trunk/MANIFEST      Sun Oct 23 11:13:35 2005
@@ -445,9 +445,6 @@ encodings/utf8.h                        
 examples/README                                   [main]doc
 examples/assembly/acorn.l                         [main]doc
 examples/assembly/hello-dwim.imc                  [main]doc
-examples/assembly/lexical.pasm                    [main]doc
-examples/assembly/lexical2.pasm                   [main]doc
-examples/assembly/lexical3.pasm                   [main]doc
 examples/assembly/life.pasm                       [main]doc
 examples/assembly/local_label.pasm                [main]doc
 examples/assembly/mandel.pasm                     [main]doc
@@ -595,6 +592,7 @@ examples/pasm/99beer.pasm               
 examples/pasm/cat.pasm                            [main]doc
 examples/pasm/fact.pasm                           [main]doc
 examples/pasm/hello.pasm                          [main]doc
+examples/pasm/lexical.pasm                        [main]doc
 examples/pir/circle.pir                           [main]doc
 examples/pir/euclid.pir                           [main]doc
 examples/pir/hanoi.pir                            [main]doc

Copied: trunk/examples/pasm/lexical.pasm (from r9536, 
trunk/examples/assembly/lexical.pasm)
==============================================================================
--- trunk/examples/assembly/lexical.pasm        (original)
+++ trunk/examples/pasm/lexical.pasm    Sun Oct 23 11:13:35 2005
@@ -1,4 +1,4 @@
-# Copyright (C) 2001-2003 The Perl Foundation.  All rights reserved.
+# Copyright (C) 2001-2005 The Perl Foundation.  All rights reserved.
 # $Id$
 
 =head1 NAME
@@ -16,46 +16,113 @@ C<find_lex>).
 
 =cut
 
-new P0, .Integer
+# Initialize some Integer PMCs, 
+# which will be stored in lexical pads
 new P1, .Integer
+set P1, 99
 new P2, .Integer
+set P2, 2
 new P3, .Integer
-set P0, 0
-set P1, 1
+set P3, 3
+new P4, .Integer
+set P4, 4
+new P5, .Integer
+set P5, 5
 
-# outer most lexical scope
+# clear the lexical scope stack
 new_pad 0
-store_lex 0, "a", P0
-find_lex P3, "a"
-print P3 # prints 0
-print "\n"
+# 0: 
 
-new_pad 1
-store_lex 1, "b", P1
-store_lex 1, "a", P1
+print "Storing 'a' in top lexical pad\n"
+store_lex 0, "a", P1
+# 0: "a" -> P1 
+# Assigning after store_lex 
+set P1, 1
+set S1, "a"
+bsr PRINT_LEX_S1_IN_CURRENT_SCOPE
 
-find_lex P3, "a"
-print P3 # prints 1
+# bottom is incidently is also the top
 print "\n"
+print "Storing 'c' in bottom lexical pad\n"
+store_lex -1, "b", P3
+# 0: "a" -> P1,  "b" -> P3 
+set S1, "a"
+bsr PRINT_LEX_S1_IN_CURRENT_SCOPE
+set S1, "b"
+bsr PRINT_LEX_S1_IN_CURRENT_SCOPE
 
-find_lex P3, "b"
-print P3 # prints 1
+# Overwriting
 print "\n"
+print "Overwriting 'c' in bottom lexical pad\n"
+store_lex -1, "a", P2
+# 0: "a" -> P2,  "b" -> P3 
+set S1, "a"
+bsr PRINT_LEX_S1_IN_CURRENT_SCOPE
+set S1, "b"
+bsr PRINT_LEX_S1_IN_CURRENT_SCOPE
 
-# get outer a
-find_lex P3, 0, "a"
-print P3 # prints 0
 print "\n"
+print "Adding another stack level at bottom\n"
+new_pad 1
+# 0: "a" -> P2,  "b" -> P3 
+# 1:
+set S1, "a"
+bsr PRINT_LEX_S1_IN_CURRENT_SCOPE
+set S1, "b"
+bsr PRINT_LEX_S1_IN_CURRENT_SCOPE
 
-pop_pad
-
-find_lex P3, "a"
-print P3 # prints 0
 print "\n"
-end
+print "Override lexicals\n"
+store_lex -1, "b", P4
+store_lex 1, "a", P5
+# 0: "a" -> P2,  "b" -> P3 
+# 1: "a" -> P4,  "b" -> P5
+set S1, "a"
+bsr PRINT_LEX_S1_IN_CURRENT_SCOPE
+set S1, "b"
+bsr PRINT_LEX_S1_IN_CURRENT_SCOPE
+set I1, 1
+set S1, "a"
+bsr PRINT_LEX_S1_IN_I1_SCOPE
+set S1, "b"
+bsr PRINT_LEX_S1_IN_I1_SCOPE
+
+# get outer a, b
+set I1, 0
+set S1, "a"
+bsr PRINT_LEX_S1_IN_I1_SCOPE
+set S1, "b"
+bsr PRINT_LEX_S1_IN_I1_SCOPE
 
-=head1 SEE ALSO
+print "\n"
+print "Getting rid of bottom stack\n"
+pop_pad
+# 0: "a" -> P2,  "b" -> P3 
+set S1, "a"
+bsr PRINT_LEX_S1_IN_CURRENT_SCOPE
+set S1, "b"
+bsr PRINT_LEX_S1_IN_CURRENT_SCOPE
 
-F<examples/assembly/lexical2.pasm>, F<examples/assembly/lexical3.pasm>.
+end
 
-=cut
+PRINT_LEX_S1_IN_CURRENT_SCOPE:
+    null P10
+    find_lex P10, S1
+    print "The lexical '"
+    print S1
+    print "' has in the current scope the value "
+    print P10 
+    print ".\n"
+ret
+
+PRINT_LEX_S1_IN_I1_SCOPE:
+    null P10
+    find_lex P10, I1, S1
+    print "The lexical '"
+    print S1
+    print "' has in scope "
+    print I1
+    print " the value "
+    print P10 
+    print ".\n"
+ret

Modified: trunk/t/examples/pasm.t
==============================================================================
--- trunk/t/examples/pasm.t     (original)
+++ trunk/t/examples/pasm.t     Sun Oct 23 11:13:35 2005
@@ -28,7 +28,7 @@ F<t/examples/japh.t>
 =cut
 
 use strict;
-use Parrot::Test tests => 2;
+use Parrot::Test tests => 3;
 use Test::More;
 
 # Set up expected output for examples
@@ -47,6 +47,35 @@ END_EXPECTED
     'hello.pasm'        =>  << 'END_EXPECTED',
 Hello World
 END_EXPECTED
+
+    'lexical.pasm'      =>  << 'END_EXPECTED',
+Storing 'a' in top lexical pad
+The lexical 'a' has in the current scope the value 1.
+
+Storing 'c' in bottom lexical pad
+The lexical 'a' has in the current scope the value 1.
+The lexical 'b' has in the current scope the value 3.
+
+Overwriting 'c' in bottom lexical pad
+The lexical 'a' has in the current scope the value 2.
+The lexical 'b' has in the current scope the value 3.
+
+Adding another stack level at bottom
+The lexical 'a' has in the current scope the value 2.
+The lexical 'b' has in the current scope the value 3.
+
+Override lexicals
+The lexical 'a' has in the current scope the value 5.
+The lexical 'b' has in the current scope the value 4.
+The lexical 'a' has in scope 1 the value 5.
+The lexical 'b' has in scope 1 the value 4.
+The lexical 'a' has in scope 0 the value 2.
+The lexical 'b' has in scope 0 the value 3.
+
+Getting rid of bottom stack
+The lexical 'a' has in the current scope the value 2.
+The lexical 'b' has in the current scope the value 3.
+END_EXPECTED
                           );
 
 # Do the testing
@@ -54,8 +83,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/pasm/$example";
     my $code = Parrot::Test::slurp_file($code_fn);
 

Reply via email to