cvsuser     03/07/06 08:22:39

  Modified:    .        MANIFEST
               classes  iterator.pmc
               docs/pmc subs.pod
               t/pmc    iter.t
  Added:       docs/pmc iterator.pod
  Log:
  iterator cleanup; new iterator.pod
  
  Revision  Changes    Path
  1.366     +1 -0      parrot/MANIFEST
  
  Index: MANIFEST
  ===================================================================
  RCS file: /cvs/public/parrot/MANIFEST,v
  retrieving revision 1.365
  retrieving revision 1.366
  diff -u -w -r1.365 -r1.366
  --- MANIFEST  6 Jul 2003 09:25:12 -0000       1.365
  +++ MANIFEST  6 Jul 2003 15:22:33 -0000       1.366
  @@ -174,6 +174,7 @@
   docs/pdds/pdd15_objects.pod                       [main]doc
   docs/pdds/pdd_template.pod                        [main]doc
   docs/pmc/array.pod                                [main]doc
  +docs/pmc/iterator.pod                             [main]doc
   docs/pmc/perlarray.pod                            [main]doc
   docs/pmc/perlhash.pod                             [main]doc
   docs/pmc/perlstring.pod                           [main]doc
  
  
  
  1.7       +57 -253   parrot/classes/iterator.pmc
  
  Index: iterator.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/classes/iterator.pmc,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -w -r1.6 -r1.7
  --- iterator.pmc      6 Jul 2003 08:00:26 -0000       1.6
  +++ iterator.pmc      6 Jul 2003 15:22:36 -0000       1.7
  @@ -1,7 +1,7 @@
   /* Iterator.pmc
    *  Copyright: (When this is determined...it will go here)
    *  CVS Info
  - *     $Id: iterator.pmc,v 1.6 2003/07/06 08:00:26 leo Exp $
  + *     $Id: iterator.pmc,v 1.7 2003/07/06 15:22:36 leo Exp $
    *  Overview:
    *     These are the vtable functions for the Iterator base class
    *  Data Structure and Algorithms:
  @@ -32,136 +32,67 @@
             pobject_lives(INTERP, (PObj *) PMC_data(SELF));
       }
   
  -    PMC* getprop (STRING* key) {
  -     return VTABLE_getprop(INTERP, (PMC*) PMC_data(SELF), key);
  -    }
  -
  -    void setprop (STRING* key, PMC* value) {
  -        VTABLE_setprop(INTERP, (PMC *)PMC_data(SELF), key, value);
  -    }
  -
  -    void delprop (STRING* key) {
  -        VTABLE_delprop(INTERP, (PMC *)PMC_data(SELF), key);
  -    }
  -
  -    PMC* getprops () {
  -        return VTABLE_getprops(INTERP, (PMC *)PMC_data(SELF));
  -    }
  -
       STRING* name () {
           return whoami;
       }
   
  -
       void clone (PMC* dest) {
        /* XXX TODO */
       }
   
       INTVAL get_integer () {
  -        return VTABLE_get_integer(INTERP,
  -             (PMC *)PMC_data(SELF));
  +        return VTABLE_get_integer(INTERP, (PMC *)PMC_data(SELF));
       }
   
       INTVAL get_integer_keyed (PMC* key) {
  -     /* XXX adjust index */
  -        return VTABLE_get_integer_keyed(INTERP,
  -             (PMC *)PMC_data(SELF), key);
  +        return VTABLE_get_integer_keyed(INTERP, (PMC *)PMC_data(SELF), key);
       }
   
       INTVAL get_integer_keyed_int (INTVAL* key) {
        /* XXX adjust index */
  -        return VTABLE_get_integer_keyed_int(INTERP,
  -             (PMC *)PMC_data(SELF), key);
  -    }
  -
  -    FLOATVAL get_number () {
  -        return (FLOATVAL)0;
  +        return VTABLE_get_integer_keyed_int(INTERP, (PMC *)PMC_data(SELF), key);
       }
   
       FLOATVAL get_number_keyed (PMC* key) {
  -        return (FLOATVAL)0;
  +        return VTABLE_get_number_keyed(INTERP, (PMC *)PMC_data(SELF), key);
       }
   
       FLOATVAL get_number_keyed_int (INTVAL* key) {
  -        return (FLOATVAL)0;
  -    }
  -
  -    BIGNUM* get_bignum () {
  -        return (BIGNUM*)0;
  +     /* XXX adjust index */
  +        return VTABLE_get_number_keyed_int(INTERP, (PMC *)PMC_data(SELF), key);
       }
   
       BIGNUM* get_bignum_keyed (PMC* key) {
  -        return (BIGNUM*)0;
  +        return VTABLE_get_bignum_keyed(INTERP, (PMC *)PMC_data(SELF), key);
       }
   
       BIGNUM* get_bignum_keyed_int (INTVAL* key) {
  -        return (BIGNUM*)0;
  -    }
  -
  -    STRING* get_string () {
  -        return (STRING*)0;
  +        return VTABLE_get_bignum_keyed_int(INTERP, (PMC *)PMC_data(SELF), key);
       }
   
       STRING* get_string_keyed (PMC* key) {
  -        return VTABLE_get_string_keyed(INTERP,
  -             (PMC *)PMC_data(SELF), key);
  +        return VTABLE_get_string_keyed(INTERP, (PMC *)PMC_data(SELF), key);
       }
   
       STRING* get_string_keyed_int (INTVAL* key) {
  -        return (STRING*)0;
  +        return VTABLE_get_string_keyed_int(INTERP, (PMC *)PMC_data(SELF), key);
       }
   
       INTVAL get_bool () {
        PMC *key = SELF->cache.struct_val;
  -     PMC *agg = PMC_data(SELF);
           return key && key->cache.int_val >= 0;
       }
   
  -    INTVAL get_bool_keyed (PMC* key) {
  -        return (INTVAL)0;
  -    }
  -
  -    INTVAL get_bool_keyed_int (INTVAL* key) {
  -        return (INTVAL)0;
  -    }
  -
       INTVAL elements () {
  -        return (INTVAL)0;
  -    }
  -
  -    INTVAL elements_keyed (PMC* key) {
  -        return (INTVAL)0;
  -    }
  -
  -    INTVAL elements_keyed_int (INTVAL* key) {
  -        return (INTVAL)0;
  -    }
  -
  -    PMC* get_pmc () {
  -        return (PMC*)0;
  +        return VTABLE_elements(INTERP, (PMC *)PMC_data(SELF));
       }
   
       PMC* get_pmc_keyed (PMC* key) {
  -        return (PMC*)0;
  +        return VTABLE_get_pmc_keyed(INTERP, (PMC *)PMC_data(SELF), key);
       }
   
       PMC* get_pmc_keyed_int (INTVAL* key) {
  -        return (PMC*)0;
  -    }
  -
  -    INTVAL is_same (PMC* value) {
  -        return (INTVAL)0;
  -    }
  -
  -    INTVAL is_same_keyed (PMC* key, PMC* value, PMC* value_key) {
  -        return (INTVAL)0;
  -    }
  -
  -    INTVAL is_same_keyed_int (INTVAL* key, PMC* value, INTVAL* value_key) {
  -        return (INTVAL)0;
  -    }
  -
  -    void set_integer (PMC* value) {
  +        return VTABLE_get_pmc_keyed_int(INTERP, (PMC *)PMC_data(SELF), key);
       }
   
       void set_integer_native (INTVAL value) {
  @@ -177,78 +108,6 @@
            VTABLE_nextkey_keyed(INTERP, (PMC*) PMC_data(SELF), key, value);
       }
   
  -    void set_integer_same (PMC* value) {
  -    }
  -
  -    void set_integer_keyed (PMC* key, INTVAL value) {
  -    }
  -
  -    void set_integer_keyed_int (INTVAL* key, INTVAL value) {
  -    }
  -
  -    void set_number (PMC* value) {
  -    }
  -
  -    void set_number_native (FLOATVAL value) {
  -    }
  -
  -    void set_number_same (PMC* value) {
  -    }
  -
  -    void set_number_keyed (PMC* key, FLOATVAL value) {
  -    }
  -
  -    void set_number_keyed_int (INTVAL* key, FLOATVAL value) {
  -    }
  -
  -    void set_bignum (PMC* value) {
  -    }
  -
  -    void set_bignum_native (BIGNUM* value) {
  -    }
  -
  -    void set_bignum_same (PMC* value) {
  -    }
  -
  -    void set_bignum_keyed (PMC* key, BIGNUM* value) {
  -    }
  -
  -    void set_bignum_keyed_int (INTVAL* key, BIGNUM* value) {
  -    }
  -
  -    void set_string (PMC* value) {
  -    }
  -
  -    void set_string_native (STRING* value) {
  -    }
  -
  -    void set_string_same (PMC* value) {
  -    }
  -
  -    void set_string_keyed (PMC* key, STRING* value) {
  -    }
  -
  -    void set_string_keyed_int (INTVAL* key, STRING* value) {
  -    }
  -
  -    void set_pmc (PMC* value) {
  -    }
  -
  -    void set_pmc_keyed (PMC* key, PMC* value, PMC* value_key) {
  -    }
  -
  -    void set_pmc_keyed_int (INTVAL* key, PMC* value, INTVAL* value_key) {
  -    }
  -
  -    void set_same (PMC* value) {
  -    }
  -
  -    void set_same_keyed (PMC* key, PMC* value, PMC* value_key) {
  -    }
  -
  -    void set_same_keyed_int (INTVAL* key, PMC* value, INTVAL* value_key) {
  -    }
  -
       INTVAL pop_integer () {
        PMC *key = SELF->cache.struct_val;
        PMC *agg = PMC_data(SELF);
  @@ -258,60 +117,40 @@
           return ret;
       }
   
  -    INTVAL pop_integer_keyed (PMC* key) {
  -        return (INTVAL)0;
  -    }
  -
  -    INTVAL pop_integer_keyed_int (INTVAL* key) {
  -        return (INTVAL)0;
  -    }
  -
       FLOATVAL pop_float () {
  -        return (FLOATVAL)0;
  -    }
  -
  -    FLOATVAL pop_float_keyed (PMC* key) {
  -        return (FLOATVAL)0;
  -    }
  -
  -    FLOATVAL pop_float_keyed_int (INTVAL* key) {
  -        return (FLOATVAL)0;
  +     PMC *key = SELF->cache.struct_val;
  +     PMC *agg = PMC_data(SELF);
  +     FLOATVAL ret = VTABLE_get_number_keyed(INTERP, agg, key);
  +     SELF->cache.struct_val =
  +         VTABLE_nextkey_keyed(INTERP, agg, key, 2);
  +        return ret;
       }
   
       BIGNUM* pop_bignum () {
  -        return (BIGNUM*)0;
  -    }
  -
  -    BIGNUM* pop_bignum_keyed (PMC* key) {
  -        return (BIGNUM*)0;
  -    }
  -
  -    BIGNUM* pop_bignum_keyed_int (INTVAL* key) {
  -        return (BIGNUM*)0;
  +     PMC *key = SELF->cache.struct_val;
  +     PMC *agg = PMC_data(SELF);
  +     BIGNUM *ret = VTABLE_get_bignum_keyed(INTERP, agg, key);
  +     SELF->cache.struct_val =
  +         VTABLE_nextkey_keyed(INTERP, agg, key, 2);
  +        return ret;
       }
   
       STRING* pop_string () {
  -        return (STRING*)0;
  -    }
  -
  -    STRING* pop_string_keyed (PMC* key) {
  -        return (STRING*)0;
  -    }
  -
  -    STRING* pop_string_keyed_int (INTVAL* key) {
  -        return (STRING*)0;
  +     PMC *key = SELF->cache.struct_val;
  +     PMC *agg = PMC_data(SELF);
  +     STRING *ret = VTABLE_get_string_keyed(INTERP, agg, key);
  +     SELF->cache.struct_val =
  +         VTABLE_nextkey_keyed(INTERP, agg, key, 2);
  +        return ret;
       }
   
       PMC* pop_pmc () {
  -        return (PMC*)0;
  -    }
  -
  -    PMC* pop_pmc_keyed (PMC* key) {
  -        return (PMC*)0;
  -    }
  -
  -    PMC* pop_pmc_keyed_int (INTVAL* key) {
  -        return (PMC*)0;
  +     PMC *key = SELF->cache.struct_val;
  +     PMC *agg = PMC_data(SELF);
  +     PMC *ret = VTABLE_get_pmc_keyed(INTERP, agg, key);
  +     SELF->cache.struct_val =
  +         VTABLE_nextkey_keyed(INTERP, agg, key, 2);
  +        return ret;
       }
   
       INTVAL shift_integer () {
  @@ -323,36 +162,23 @@
           return ret;
       }
   
  -    INTVAL shift_integer_keyed (PMC* key) {
  -        return (INTVAL)0;
  -    }
  -
  -    INTVAL shift_integer_keyed_int (INTVAL* key) {
  -        return (INTVAL)0;
  -    }
   
       FLOATVAL shift_float () {
  -        return (FLOATVAL)0;
  -    }
  -
  -    FLOATVAL shift_float_keyed (PMC* key) {
  -        return (FLOATVAL)0;
  -    }
  -
  -    FLOATVAL shift_float_keyed_int (INTVAL* key) {
  -        return (FLOATVAL)0;
  +     PMC *key = SELF->cache.struct_val;
  +     PMC *agg = PMC_data(SELF);
  +     FLOATVAL ret = VTABLE_get_number_keyed(INTERP, agg, key);
  +     SELF->cache.struct_val =
  +         VTABLE_nextkey_keyed(INTERP, agg, key, 1);
  +        return ret;
       }
   
       BIGNUM* shift_bignum () {
  -        return (BIGNUM*)0;
  -    }
  -
  -    BIGNUM* shift_bignum_keyed (PMC* key) {
  -        return (BIGNUM*)0;
  -    }
  -
  -    BIGNUM* shift_bignum_keyed_int (INTVAL* key) {
  -        return (BIGNUM*)0;
  +     PMC *key = SELF->cache.struct_val;
  +     PMC *agg = PMC_data(SELF);
  +     BIGNUM *ret = VTABLE_get_bignum_keyed(INTERP, agg, key);
  +     SELF->cache.struct_val =
  +         VTABLE_nextkey_keyed(INTERP, agg, key, 1);
  +        return ret;
       }
   
       STRING* shift_string () {
  @@ -364,14 +190,6 @@
           return ret;
       }
   
  -    STRING* shift_string_keyed (PMC* key) {
  -        return (STRING*)0;
  -    }
  -
  -    STRING* shift_string_keyed_int (INTVAL* key) {
  -        return (STRING*)0;
  -    }
  -
       PMC* shift_pmc () {
        PMC *key = SELF->cache.struct_val;
        PMC *agg = PMC_data(SELF);
  @@ -381,41 +199,27 @@
           return ret;
       }
   
  -    PMC* shift_pmc_keyed (PMC* key) {
  -        return (PMC*)0;
  -    }
  -
  -    PMC* shift_pmc_keyed_int (INTVAL* key) {
  -        return (PMC*)0;
  -    }
  -
       INTVAL exists_keyed (PMC* key) {
  -        return (INTVAL)0;
  +     return VTABLE_exists_keyed(INTERP, (PMC *)PMC_data(SELF), key);
       }
   
       INTVAL exists_keyed_int (INTVAL* key) {
  -        return (INTVAL)0;
  +     return VTABLE_exists_keyed_int(INTERP, (PMC *)PMC_data(SELF), key);
       }
   
       INTVAL defined () {
  -        return (INTVAL)0;
  +        return (INTVAL) (PMC_data(SELF) != 0);
       }
   
       INTVAL defined_keyed (PMC* key) {
  -        return (INTVAL)0;
  +     return VTABLE_defined_keyed(INTERP, (PMC *)PMC_data(SELF), key);
       }
   
       INTVAL defined_keyed_int (INTVAL* key) {
  -        return (INTVAL)0;
  +     return VTABLE_defined_keyed_int(INTERP, (PMC *)PMC_data(SELF), key);
       }
   
  -
  -    PMC* nextkey_keyed (PMC* key, INTVAL what) {
  -        return (PMC*)0;
  -    }
  -
  -    PMC* nextkey_keyed_int (INTVAL* key, INTVAL what) {
  -        return (PMC*)0;
  +    INTVAL type_keyed (PMC* key) {
  +     return VTABLE_type_keyed(INTERP, (PMC *)PMC_data(SELF), key);
       }
  -
   }
  
  
  
  1.3       +4 -2      parrot/docs/pmc/subs.pod
  
  Index: subs.pod
  ===================================================================
  RCS file: /cvs/public/parrot/docs/pmc/subs.pod,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -w -r1.2 -r1.3
  --- subs.pod  2 Jul 2003 21:36:42 -0000       1.2
  +++ subs.pod  6 Jul 2003 15:22:38 -0000       1.3
  @@ -99,6 +99,8 @@
   
   =head1 FILES
   
  +F<classes/sub.pmc>, F<classes/closure.pmc>, F<classes/continuation.pmc>,
  +F<classes/coroutine.pmc>,
   F<docs/pdds/pdd03_calling_conventions.pod>, F<t/pmc/sub.t>
   
   =head1 AUTHOR
  
  
  
  1.1                  parrot/docs/pmc/iterator.pod
  
  Index: iterator.pod
  ===================================================================
  =head1 NAME
  
  Iterator - Parrot Iterator Class
  
  =head1 DESCRIPTION
  
  Iterators are used in combination with other classes (mainly
  aggregates) to visit all entries in that aggregate.
  
  =head1 SYNOPSIS
  
  Iterate from the beginning of the aggregate:
  
      new P0, .Iterator, P1     # setup iterator for aggregate P1
      set P0, 0                 # reset iterator, begin at start
    iter_loop:
      unless P0, iter_end               # while (entries) ...
        shift P2, P0            # get entry
        ...
        branch iter_loop
  
  Iterate from the end of the aggregate (Array like classes only):
  
      new P0, .Iterator, P1     # setup iterator for aggregate P1
      set P0, 3                 # reset iterator, begin at end
    iter_loop:
      unless P0, iter_end               # while (entries) ...
        pop P2, P0              # get entry
        ...
        branch iter_loop
  
  =head2 Iterating over hashes
  
      .include "datatypes.pasm" # type constants
      new P0, .Iterator, P1     # setup iterator for hash P1
      set P0, 0                 # reset iterator, begin at start
    iter_loop:
      unless P0, iter_end               # while (entries) ...
        shift S2, P0            # get key for next entry
        typeof I0, P0[S2]               # get type of entry at key S2
        ne I0, .DATATYPE_INTVAL, no_int
        set I1, P0[S2]            # extract integer
      no_int:
  
        ...
        branch iter_loop
  
  =head1 FILES
  
  F<classes/iterator.pmc>, F<t/pmc/iter.t>
  
  =head1 AUTHOR
  
  Leopold Toetsch <[EMAIL PROTECTED]>
  
  
  
  1.5       +90 -2     parrot/t/pmc/iter.t
  
  Index: iter.t
  ===================================================================
  RCS file: /cvs/public/parrot/t/pmc/iter.t,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -w -r1.4 -r1.5
  --- iter.t    6 Jul 2003 09:24:40 -0000       1.4
  +++ iter.t    6 Jul 2003 15:22:39 -0000       1.5
  @@ -1,7 +1,7 @@
   #! perl -w
   
  -use Parrot::Test tests => 4;
  -use Test::More;
  +use Parrot::Test tests => 6;
  +use Test::More qw(skip);
   output_is(<<'CODE', <<'OUTPUT', "new iter");
        new P2, .PerlArray
        new P1, .Iterator, P2
  @@ -184,3 +184,91 @@
   ok 1
   ok 2
   OUTPUT
  +
  +output_is(<<'CODE', <<'OUTPUT', "hash iter - various types");
  +    .include "datatypes.pasm"        # type constants
  +    new P1, .PerlHash
  +    set P1["int"], 10
  +    set P1["num"], 2.5
  +    set P1["str"], "string"
  +    new P2, .PerlString
  +    set P2, "string"
  +    set P1["pmc"], P2
  +
  +    set I10, 0                       # count items
  +    new P0, .Iterator, P1    # setup iterator for hash P1
  +    set P0, 0                        # reset iterator, begin at start
  +iter_loop:
  +    unless P0, iter_end              # while (entries) ...
  +      inc I10
  +      shift S2, P0           # get key for entry
  +      typeof I0, P0[S2]              # get type of entry for key S2
  +      ne I0, .DATATYPE_INTVAL, no_int
  +      set I1, P0[S2]
  +      eq I1, 10, iter_loop
  +      print "not ok int\n"
  +    no_int:
  +      ne I0, .DATATYPE_FLOATVAL, no_num
  +      set N1, P0[S2]
  +      eq N1, 2.5, iter_loop
  +      print "not ok num\n"
  +    no_num:
  +      ne I0, .DATATYPE_STRING, no_str
  +      set S1, P0[S2]
  +      eq S1, "string", iter_loop
  +      print "not ok str\n"
  +    no_str:
  +      set P4, P0[S2]
  +      eq P4, P2, iter_loop
  +      print "not ok pmc\n"
  +      branch iter_loop
  +iter_end:
  +    print I10
  +    print "\n"
  +    end
  +CODE
  +4
  +OUTPUT
  +
  +SKIP: {
  +skip("N/Y: get_keyed_int gets rest of array", 1);
  +output_is(<<'CODE', <<'OUTPUT', "shift + index access");
  +
  +     new P2, .PerlArray      # array with 2 elements
  +     push P2, 10
  +     push P2, 20
  +     push P2, 30
  +     push P2, 40
  +     new P1, .Iterator, P2
  +     set P1, 0
  +
  +     set I0, P1              # arr.length
  +     eq I0, 4, ok1
  +     print I0
  +     print " not "
  +ok1: print "ok 1\n"
  +
  +     shift I0, P1            # get one
  +     eq I0, 10, ok2
  +     print "not "
  +ok2: print "ok 2\n"
  +
  +        set I0, P1[0]                # first element of iter = next
  +     eq I0, 20, ok3
  +     print I0
  +     print " not "
  +ok3: print "ok 3\n"
  +
  +     set I0, P1              # arr.length of rest
  +     eq I0, 3, ok4
  +     print I0
  +     print " not "
  +ok4: print "ok 4\n"
  +     end
  +CODE
  +ok 1
  +ok 2
  +ok 3
  +ok 4
  +OUTPUT
  +}
  
  
  

Reply via email to