Author: bernhard
Date: Thu Nov  3 14:30:08 2005
New Revision: 9765

Added:
   trunk/examples/pasm/stack.pasm
      - copied, changed from r9764, trunk/examples/assembly/stack.pasm
   trunk/examples/pni/ls.pir
Removed:
   trunk/examples/assembly/stack.pasm
Modified:
   trunk/MANIFEST
   trunk/t/examples/pasm.t
Log:
Add a directory lister example. 
See 'Segfault with structs and CSTR' on p6i.
THX to Leo and Joshua Isom.

Move the example 'stack.pasm' to 'examples/pasm'
and add a test for it in pasm.t


Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST      (original)
+++ trunk/MANIFEST      Thu Nov  3 14:30:08 2005
@@ -456,7 +456,6 @@ examples/assembly/ncurses_life.imc      
 examples/assembly/pmcmops.pasm                    [main]doc
 examples/assembly/queens.pasm                     [main]doc
 examples/assembly/queens_r.imc                    [main]doc
-examples/assembly/stack.pasm                      [main]doc
 examples/assembly/thr-primes.imc                  [main]doc
 examples/assembly/trace.pasm                      [main]doc
 examples/assembly/uniq.pasm                       [main]doc
@@ -590,6 +589,7 @@ examples/pasm/fact.pasm                 
 examples/pasm/hello.pasm                          [main]doc
 examples/pasm/lexical.pasm                        [main]doc
 examples/pasm/small.xml                           [main]doc
+examples/pasm/stack.pasm                          [main]doc
 examples/pasm/xml_parser.pasm                     [main]doc
 examples/pge/README                               [main]doc
 examples/pge/all.pir                              [main]doc
@@ -608,6 +608,7 @@ examples/pir/substr.pir                 
 examples/pir/sudoku.pir                           [main]doc
 examples/pni/PQt.C                                [main]doc
 examples/pni/QtHelloWorld.pasm                    [main]doc
+examples/pni/ls.pir                               [main]doc
 examples/pni/sdl_blue_rectangle.imc               [main]doc
 examples/pni/win32api.imc                         [main]doc
 examples/sdl/anim_image.imc                       [devel]

Copied: trunk/examples/pasm/stack.pasm (from r9764, 
trunk/examples/assembly/stack.pasm)
==============================================================================
--- trunk/examples/assembly/stack.pasm  (original)
+++ trunk/examples/pasm/stack.pasm      Thu Nov  3 14:30:08 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
@@ -190,5 +190,5 @@ Shows you how to C<set>, C<save>, C<rest
        print I1
        restore I1
        print I1
-    end
-
+       print "\n"
+       end

Added: trunk/examples/pni/ls.pir
==============================================================================
--- (empty file)
+++ trunk/examples/pni/ls.pir   Thu Nov  3 14:30:08 2005
@@ -0,0 +1,63 @@
+# Copyright: 2005 The Perl Foundation.  All Rights Reserved.
+# $Id$
+
+=head1 NAME
+
+examples/pni/ls.pir - a directory lister
+
+=head1 DESCRIPTION
+
+List the content of the directory 'charset'.
+
+=cut
+
+.sub _main @MAIN
+     .local pmc libc
+     .local pmc opendir
+     .local pmc readdir
+     .local pmc closedir
+     null libc
+     dlfunc opendir, libc, 'opendir', 'pt'
+     dlfunc readdir, libc, 'readdir', 'pp'
+     dlfunc closedir, libc, 'closedir', 'ip'
+     store_global 'libc::opendir', opendir
+     store_global 'libc::readdir', readdir
+     store_global 'libc::closedir', closedir
+     .local pmc curdir
+     curdir = libc::opendir("charset")
+     .local OrderedHash entry
+
+     .include "datatypes.pasm"
+     new $P2, .OrderedHash
+     set $P2["d_fileno"], .DATATYPE_INT64
+     push $P2, 0
+     push $P2, 0
+     set $P2["d_reclen"], .DATATYPE_SHORT
+     push $P2, 0
+     push $P2, 0
+     set $P2["d_type"], .DATATYPE_CHAR
+     push $P2, 0
+     push $P2, 0
+     set $P2["d_name"], .DATATYPE_CHAR
+     push $P2, 256
+     push $P2, 0           # 11
+lp_dir:
+     entry = libc::readdir(curdir)
+     $I0 = get_addr entry
+     unless $I0 goto done
+     assign entry, $P2
+
+    $I1 = 0
+loop:
+     $I0 = entry["d_name";$I1]
+     unless $I0 goto ex
+     chr $S0, $I0
+     print $S0
+     inc $I1
+     goto loop
+ ex:
+     print "\n"
+     goto lp_dir
+done:
+     libc::closedir(curdir)
+.end

Modified: trunk/t/examples/pasm.t
==============================================================================
--- trunk/t/examples/pasm.t     (original)
+++ trunk/t/examples/pasm.t     Thu Nov  3 14:30:08 2005
@@ -27,7 +27,7 @@ F<t/examples/japh.t>
 =cut
 
 use strict;
-use Parrot::Test tests => 4;
+use Parrot::Test tests => 5;
 use Test::More;
 
 # Set up expected output for examples
@@ -76,6 +76,10 @@ The lexical 'a' has in the current scope
 The lexical 'b' has in the current scope the value 3.
 END_EXPECTED
 
+    'stack.pasm'        =>  << 'END_EXPECTED',
+87654321098765432100123456789012345678998765432109876543210
+END_EXPECTED
+
     'xml_parser.pasm'        =>  << 'END_EXPECTED',
 Start xml version=1.0
 Start top

Reply via email to