cvs -q diff -u
Index: classes/iterator.pmc
===================================================================
RCS file: /cvs/public/parrot/classes/iterator.pmc,v
retrieving revision 1.18
diff -u -u -r1.18 iterator.pmc
--- classes/iterator.pmc	22 Feb 2004 17:48:41 -0000	1.18
+++ classes/iterator.pmc	16 Mar 2004 22:17:57 -0000
@@ -88,12 +88,32 @@
 
 =item C<INTVAL get_integer()>
 
+Get number of remaining elements. Does not work for hashes yet.
+TODO: keep track of current position and direction
+
 =cut
 
 */
 
     INTVAL get_integer () {
-        return VTABLE_get_integer(INTERP, (PMC *)PMC_pmc_val(SELF));
+        PMC *agg = PMC_pmc_val(SELF);
+        return VTABLE_get_integer(INTERP, agg );
+    }
+
+/*
+
+=item C<STRING *get_string()>
+
+Returns the number of remaining elements as a Parrot string.
+TODO: keep track of current position and direction
+
+=cut
+
+*/
+
+    STRING* get_string () {
+        PMC *agg = PMC_pmc_val(SELF);
+        return string_from_int(INTERP, VTABLE_get_integer(INTERP, agg ) );
     }
 
 /*
@@ -110,15 +130,18 @@
 
 /*
 
-=item C<INTVAL get_integer_keyed_int(INTVAL key)>
+=item C<INTVAL get_integer_keyed_int(INTVAL index)>
+
+Get integer value of current position plus index.
 
 =cut
 
 */
 
-    INTVAL get_integer_keyed_int (INTVAL key) {
-        /* XXX adjust index */
-        return VTABLE_get_integer_keyed_int(INTERP, (PMC *)PMC_pmc_val(SELF), key);
+    INTVAL get_integer_keyed_int (INTVAL index) {
+        PMC *key = PMC_struct_val(SELF);
+        PMC *agg = PMC_pmc_val(SELF);
+        return VTABLE_get_integer_keyed_int(INTERP, agg, PMC_int_val(key) + index );
     }
 
 /*
@@ -130,20 +153,23 @@
 */
 
     FLOATVAL get_number_keyed (PMC* key) {
-        return VTABLE_get_number_keyed(INTERP, (PMC *)PMC_pmc_val(SELF), key);
+        return VTABLE_get_number_keyed(INTERP,(PMC *)PMC_pmc_val(SELF), key );
     }
 
 /*
 
-=item C<FLOATVAL get_number_keyed_int(INTVAL key)>
+=item C<FLOATVAL get_number_keyed_int(INTVAL index)>
+
+Get number value of current position plus index.
 
 =cut
 
 */
 
-    FLOATVAL get_number_keyed_int (INTVAL key) {
-        /* XXX adjust index */
-        return VTABLE_get_number_keyed_int(INTERP, (PMC *)PMC_pmc_val(SELF), key);
+    FLOATVAL get_number_keyed_int (INTVAL index) {
+        PMC *key = PMC_struct_val(SELF);
+        PMC *agg = PMC_pmc_val(SELF);
+        return VTABLE_get_number_keyed_int(INTERP, agg, PMC_int_val(key) + index );
     }
 
 /*
@@ -160,16 +186,18 @@
 
 /*
 
-=item C<BIGNUM *get_bignum_keyed_int(INTVAL key)>
+=item C<BIGNUM *get_bignum_keyed_int(INTVAL index)>
 
-Returns the current index.
+Get bignum value of current position plus index.
 
 =cut
 
 */
 
-    BIGNUM* get_bignum_keyed_int (INTVAL key) {
-        return VTABLE_get_bignum_keyed_int(INTERP, (PMC *)PMC_pmc_val(SELF), key);
+    BIGNUM* get_bignum_keyed_int (INTVAL index) {
+        PMC *key = PMC_struct_val(SELF);
+        PMC *agg = PMC_pmc_val(SELF);
+        return VTABLE_get_bignum_keyed_int(INTERP, agg, PMC_int_val(key) + index );
     }
 
 /*
@@ -186,16 +214,18 @@
 
 /*
 
-=item C<STRING *get_string_keyed_int(INTVAL key)>
+=item C<STRING *get_string_keyed_int(INTVAL index)>
 
-Returns the current key.
+Get string value of current position plus index.
 
 =cut
 
 */
 
-    STRING* get_string_keyed_int (INTVAL key) {
-        return VTABLE_get_string_keyed_int(INTERP, (PMC *)PMC_pmc_val(SELF), key);
+    STRING* get_string_keyed_int (INTVAL index) {
+        PMC *key = PMC_struct_val(SELF);
+        PMC *agg = PMC_pmc_val(SELF);
+        return VTABLE_get_string_keyed_int(INTERP, agg, PMC_int_val(key) + index );
     }
 
 /*
@@ -251,8 +281,10 @@
 
 */
 
-    PMC* get_pmc_keyed_int (INTVAL key) {
-        return VTABLE_get_pmc_keyed_int(INTERP, (PMC *)PMC_pmc_val(SELF), key);
+    PMC* get_pmc_keyed_int (INTVAL index) {
+        PMC *key = PMC_struct_val(SELF);
+        PMC *agg = PMC_pmc_val(SELF);
+        return VTABLE_get_pmc_keyed_int(INTERP, agg, PMC_int_val(key) + index );
     }
 
 /*
@@ -474,16 +506,18 @@
 
 /*
 
-=item C<INTVAL exists_keyed_int(INTVAL key)>
+=item C<INTVAL exists_keyed_int(INTVAL index)>
 
-Returns whether an element for C<key> exists in the aggregate.
+Returns whether an element for C<index> exists in the aggregate.
 
 =cut
 
 */
 
-    INTVAL exists_keyed_int (INTVAL key) {
-        return VTABLE_exists_keyed_int(INTERP, (PMC *)PMC_pmc_val(SELF), key);
+    INTVAL exists_keyed_int (INTVAL index) {
+        PMC *key = PMC_struct_val(SELF);
+        PMC *agg = PMC_pmc_val(SELF);
+        return VTABLE_exists_keyed_int(INTERP, agg, PMC_int_val(key) + index );
     }
 
 /*
@@ -522,8 +556,10 @@
 
 */
 
-    INTVAL defined_keyed_int (INTVAL key) {
-        return VTABLE_defined_keyed_int(INTERP, (PMC *)PMC_pmc_val(SELF), key);
+    INTVAL defined_keyed_int (INTVAL index) {
+        PMC *key = PMC_struct_val(SELF);
+        PMC *agg = PMC_pmc_val(SELF);
+        return VTABLE_defined_keyed_int(INTERP, agg, PMC_int_val(key) + index );
     }
 
 /*
@@ -538,6 +574,21 @@
 
     INTVAL type_keyed (PMC* key) {
         return VTABLE_type_keyed(INTERP, (PMC *)PMC_pmc_val(SELF), key);
+    }
+
+
+=item C<INTVAL type_keyed_int(PMC *index)>
+
+Returns the result of calling C<type_keyed(key)> on the aggregate.
+
+=cut
+
+*/
+
+    INTVAL type_keyed_int (INTVAL index) {
+        PMC *key = PMC_struct_val(SELF);
+        PMC *agg = PMC_pmc_val(SELF);
+        return VTABLE_type_keyed_int(INTERP, agg, PMC_int_val(key) + index );
     }
 }
 
Index: docs/.cvsignore
===================================================================
RCS file: /cvs/public/parrot/docs/.cvsignore,v
retrieving revision 1.7
diff -u -u -r1.7 .cvsignore
--- docs/.cvsignore	16 Mar 2004 15:24:28 -0000	1.7
+++ docs/.cvsignore	16 Mar 2004 22:17:59 -0000
@@ -1,3 +1,4 @@
+html
 Makefile
 packfile-c.pod
 packfile-perl.pod
Index: t/pmc/iter.t
===================================================================
RCS file: /cvs/public/parrot/t/pmc/iter.t,v
retrieving revision 1.12
diff -u -u -r1.12 iter.t
--- t/pmc/iter.t	8 Mar 2004 00:20:09 -0000	1.12
+++ t/pmc/iter.t	16 Mar 2004 22:18:14 -0000
@@ -16,8 +16,9 @@
 
 =cut
 
-use Parrot::Test tests => 10;
+use Parrot::Test tests => 12;
 use Test::More qw(skip);
+
 output_is(<<'CODE', <<'OUTPUT', "new iter");
 	new P2, .PerlArray
 	new P1, .Iterator, P2
@@ -325,12 +326,191 @@
 reached end
 OUTPUT
 
+output_is(<<'CODE', <<'OUTPUT', "Index access for Iterator on PerlString");
+##PIR##
+.include "iterator.pasm"
+.sub _main
+    .local pmc string_1
+    string_1 = new PerlString
+    string_1 = "abcd\x65\x66\x67"
+    print 'PerlString new: '
+    print string_1
+    print "\n"
+
+    .local pmc iter_1
+    iter_1 = new Iterator, string_1
+    iter_1 = .ITERATE_FROM_START
+
+    .local int    code_point_1
+    .local float  code_point_2
+    .local string code_point_3
+    .local pmc    code_point_4
+
+    print 'Iterator shift_integer: '
+    shift code_point_1, iter_1
+    print code_point_1
+    print "\n"
+
+    print 'Iterator get_integer_keyed_int 2: '
+    code_point_1 = iter_1[2] 
+    print code_point_1 
+    print "\n"
+
+    print 'Iterator get_integer_keyed_int 0: '
+    code_point_1 = iter_1[0] 
+    print code_point_1 
+    print "\n"
+
+    print 'Iterator get_integer_keyed_int -1: '
+    code_point_1 = iter_1[-1] 
+    print code_point_1 
+    print "\n"
+
+    end
+.end
+CODE
+PerlString new: abcdefg
+Iterator shift_integer: 97
+Iterator get_integer_keyed_int 2: 100
+Iterator get_integer_keyed_int 0: 98
+Iterator get_integer_keyed_int -1: 97
+OUTPUT
+
+output_is(<< 'CODE', << 'OUTPUT', "Index access for Iterator on PerlArray");
+##PIR##
+.include "iterator.pasm"
+.sub _main
+    .local pmc array_1
+    array_1 = new PerlArray
+    push array_1, 'a' 
+    push array_1, 'b' 
+    push array_1, 'c' 
+    push array_1, 'd' 
+    push array_1, 'e' 
+    push array_1, 'f'
+    push array_1, '7'
+    push array_1, '-8.8'
+
+    print 'PerlArray get_string: '
+    print array_1
+    print "\n"
+
+    .local pmc iter_1
+    iter_1 = new Iterator, array_1
+    iter_1 = .ITERATE_FROM_START
+
+    print 'Iterator get_string: '
+    print iter_1
+    print "\n"
+
+    .local string elem_1
+    
+    print 'Iterator shift_string: '
+    shift elem_1, iter_1
+    print elem_1
+    print "\n"
+
+    print 'Iterator get_string_keyed_int 2: '
+    elem_1 = iter_1[2] 
+    print elem_1 
+    print "\n"
+
+    print 'Iterator get_string_keyed_int -1: '
+    elem_1 = iter_1[-1] 
+    print elem_1 
+    print "\n"
+
+    print 'Iterator get_string_keyed_int 0: '
+    elem_1 = iter_1[0] 
+    print elem_1 
+    print "\n"
+
+    print 'Iterator get_pmc_keyed_int 3: '
+    .local pmc elem_2
+    elem_2 = iter_1[3] 
+    print elem_2 
+    print "\n"
+
+    .local int flag
+
+    print 'Iterator exists_keyed_int 3: '
+    flag = exists iter_1[3]
+    print flag 
+    print "\n"
+    
+    print 'Iterator exists_keyed_int 28: '
+    flag = exists iter_1[28]
+    print flag 
+    print "\n"
+    
+
+    print 'Iterator defined_keyed_int 3: '
+    flag = defined iter_1[3]
+    print flag 
+    print "\n"
+    
+    print 'Iterator defined_keyed_int -1278: '
+    flag = defined iter_1[-1278]
+    print flag 
+    print "\n"
+    
+    print 'Iterator type: '
+    .local int type_id
+    .local string type_string
+    typeof type_id, iter_1
+    typeof type_string, iter_1
+    print type_id 
+    print ' '
+    print type_string 
+    print "\n"
+    
+    .local pmc iter_2
+    iter_2 = new Iterator, array_1
+    iter_2 = .ITERATE_FROM_END
+
+    print 'Iterator get_string: '
+    print iter_1
+    print "\n"
+
+    print 'Iterator shift_float: '
+    .local float elem_2
+    shift elem_2, iter_2
+    print elem_2
+    print "\n"
+
+    print 'Iterator get_integer: '
+    .local int elem_3
+    elem_3 = iter_2[-1]
+    print elem_3
+    print "\n"
+
+    end
+.end
+CODE
+PerlArray get_string: 8
+Iterator get_string: 8
+Iterator shift_string: a
+Iterator get_string_keyed_int 2: d
+Iterator get_string_keyed_int -1: a
+Iterator get_string_keyed_int 0: b
+Iterator get_pmc_keyed_int 3: e
+Iterator exists_keyed_int 3: 1
+Iterator exists_keyed_int 28: 0
+Iterator defined_keyed_int 3: 1
+Iterator defined_keyed_int -1278: 0
+Iterator type: 16 Iterator
+Iterator get_string: 8
+Iterator shift_float: -8.800000
+Iterator get_integer: 7
+OUTPUT
+
+
 SKIP: {
-skip("N/Y: get_keyed_int gets rest of array", 1);
+skip("N/Y: length of rest of array ", 1);
 output_is(<<'CODE', <<'OUTPUT', "shift + index access");
     .include "iterator.pasm"
 
-	new P2, .PerlArray	# array with 2 elements
+	new P2, .PerlArray	# array with 4 elements
 	push P2, 10
 	push P2, 20
 	push P2, 30
@@ -349,22 +529,24 @@
 	print "not "
 ok2:	print "ok 2\n"
 
-        set I0, P1[0]		# first element of iter = next
+	shift I0, P1		# get one
 	eq I0, 20, ok3
-	print I0
-	print " not "
+	print "not "
 ok3:	print "ok 3\n"
 
 	set I0, P1		# arr.length of rest
-	eq I0, 3, ok4
+	eq I0, 2, ok6
 	print I0
 	print " not "
-ok4:	print "ok 4\n"
+ok6:	print "ok 6\n"
+
+        print P1
 	end
 CODE
 ok 1
 ok 2
 ok 3
-ok 4
+ok 6
+2
 OUTPUT
 }
