cvsuser 04/06/18 06:07:07
Modified: classes iterator.pmc key.pmc slice.pmc
imcc symreg.h
include/parrot packfile.h
src packfile.c
Log:
slices 8 - docu and cleanup
Revision Changes Path
1.21 +5 -5 parrot/classes/iterator.pmc
Index: iterator.pmc
===================================================================
RCS file: /cvs/public/parrot/classes/iterator.pmc,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -w -r1.20 -r1.21
--- iterator.pmc 16 Jun 2004 12:58:17 -0000 1.20
+++ iterator.pmc 18 Jun 2004 13:06:54 -0000 1.21
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: iterator.pmc,v 1.20 2004/06/16 12:58:17 leo Exp $
+$Id: iterator.pmc,v 1.21 2004/06/18 13:06:54 leo Exp $
=head1 NAME
@@ -291,11 +291,11 @@
=item C<void set_integer_native(INTVAL value)>
-Sets the current idx to C<value>.
+Reset the Iterator. C<value> must be one of
-C<value> must be in the range:
-
- (ITERATE_FROM_START + 1) .. (ITERATE_FROM_END - 1)
+ ITERATE_FROM_START ... Iterate from start
+ ITERATE_FROM_START_KEYS ... OrderedHash by keys
+ ITERATE_FROM_END ... Arrays and PerlString only
=cut
1.23 +10 -2 parrot/classes/key.pmc
Index: key.pmc
===================================================================
RCS file: /cvs/public/parrot/classes/key.pmc,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -w -r1.22 -r1.23
--- key.pmc 18 Jun 2004 12:05:59 -0000 1.22
+++ key.pmc 18 Jun 2004 13:06:54 -0000 1.23
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: key.pmc,v 1.22 2004/06/18 12:05:59 leo Exp $
+$Id: key.pmc,v 1.23 2004/06/18 13:06:54 leo Exp $
=head1 NAME
@@ -274,6 +274,7 @@
=item C<PMC *nextkey_keyed(PMC *key, INTVAL what)>
Returns the next key relative to the location specified in C<what>.
+PMC_int_val(-1) means end of iteration.
=cut
@@ -291,11 +292,18 @@
PMC_int_val(ret) = 0;
if (!n)
PMC_int_val(ret) = -1;
+ /*
+ * iterating over a hash needs additionally the
+ * Bucket index
+ */
if (is_hash_iter(agg))
PMC_data(ret) = (void *)INITBucketIndex;
break;
case ITERATE_GET_NEXT:
- /* src/hash.c:hash_get_idx() advances to next */
+ /*
+ * src/hash.c:hash_get_idx() advances to next
+ * so, if we are iterating over a hash do nothing
+ * */
if (!is_hash_iter(agg)) {
if (PMC_int_val(ret) < n - 1)
++PMC_int_val(ret);
1.4 +116 -8 parrot/classes/slice.pmc
Index: slice.pmc
===================================================================
RCS file: /cvs/public/parrot/classes/slice.pmc,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -r1.3 -r1.4
--- slice.pmc 18 Jun 2004 12:05:59 -0000 1.3
+++ slice.pmc 18 Jun 2004 13:06:54 -0000 1.4
@@ -1,6 +1,6 @@
/*
Copyright: 2004 The Perl Foundation. All Rights Reserved.
-$Id: slice.pmc,v 1.3 2004/06/18 12:05:59 leo Exp $
+$Id: slice.pmc,v 1.4 2004/06/18 13:06:54 leo Exp $
=head1 NAME
@@ -10,6 +10,22 @@
These are the vtable functions for the slice PMC class.
+A Slice PMC isa Key PMC, holding a chain of start and/or end values
+for slice ranges. Private flags define the meaning of the values:
+
+ [ s .. e ] s .. KEY_start_slice_FLAG; e .. KEY_end_slice_FLAG
+ [ x, ] KEY_start_slice_FLAG | KEY_end_slice_FLAG
+ [ .. e ] KEY_inf_slice_FLAG | KEY_end_slice_FLAG
+ [ s .. ] KEY_start_slice_FLAG | KEY_inf_slice_FLAG
+
+Ranges are currently implemented for Array and PerlString only.
+
+Run
+
+ $ parrot -d2000 slice.pasm
+
+to see slice constant flags.
+
=head2 Methods
=over 4
@@ -20,29 +36,50 @@
#include "parrot/parrot.h"
+/*
+ * set the Slice iter state to initial, first position
+ * no backwards iterations for now
+ */
static void
set_slice_start(Interp *interpreter, PMC *self)
{
PMC* range = PMC_pmc_val(self);
/*
- * and start value in struct_val
+ * set start value in struct_val
+ * Please nt that the range PMC can hold variables too
+ * so that key_integer/key_string must be used to get the
+ * values
*/
if (key_type(interpreter, range) & KEY_integer_FLAG) {
/* integer key */
if (PObj_get_FLAGS(range) & KEY_inf_slice_FLAG) {
- /* first range is ".. end" */
+ /*
+ * first range is ".. end"
+ * start at index 0
+ * */
PMC_struct_val(self) = (void *)0;
}
else {
+ /*
+ * else start at range value
+ */
PMC_struct_val(self) = (void *)key_integer(interpreter, range);
}
}
else {
+ /*
+ * string assumed
+ * - no ranges yet, start at value
+ */
PMC_struct_val(self) = key_string(interpreter, range);
}
}
+/*
+ * increment Slice value according to range and/or advance to
+ * next range PMC in Key chain
+ */
static void
set_slice_next(Interp *interpreter, PMC *self, PMC *agg)
{
@@ -84,6 +121,10 @@
goto next_range;
}
if (PObj_get_FLAGS(range) & KEY_start_slice_FLAG) {
+ /*
+ * start ... end range
+ * end is in the next range in the Key chain
+ */
PMC *end_range = PMC_data(range);
if (!end_range)
internal_exception(1, "No end range found");
@@ -102,16 +143,29 @@
next_range:
range = PMC_pmc_val(self) = PMC_data(range);
- if (!PMC_pmc_val(self))
+ if (!PMC_pmc_val(self)) {
+ /*
+ * this denotes the end of iteration
+ */
PMC_int_val(self) = -1;
- else
+ }
+ else {
+ /*
+ * set start value
+ */
PMC_struct_val(self) = (void *)key_integer(interpreter, range);
}
+ }
else {
+ /*
+ * string assumed
+ */
if ((PObj_get_FLAGS(range) &
(KEY_start_slice_FLAG|KEY_end_slice_FLAG)) ==
(KEY_start_slice_FLAG|KEY_end_slice_FLAG)) {
-
+ /*
+ * only single values for now - no ranges
+ */
range = PMC_pmc_val(self) = PMC_data(range);
if (!PMC_pmc_val(self))
PMC_int_val(self) = -1;
@@ -126,6 +180,39 @@
pmclass Slice need_ext extends Key {
+ void init () {
+ PMC_pmc_val(SELF) = NULL;
+ SUPER();
+ }
+
+ void mark () {
+ if (PMC_pmc_val(SELF))
+ pobject_lives(INTERP, (PObj*)PMC_pmc_val(SELF));
+ SUPER();
+ }
+
+ PMC* clone() {
+ internal_exception(1, "Unimplemented");
+ /*
+ * TODO - Key_Clone does all - except for the slice flags
+ */
+ return NULL;
+ }
+
+/*
+
+=item C<INTVAL get_integer()>
+
+Get the next integer key from the current slice range.
+
+=item C<STRING* get_string()>
+
+Get the next string key from the current slice range.
+
+=cut
+
+*/
+
INTVAL get_integer() {
INTVAL v = (INTVAL)PMC_struct_val(SELF);
/* printf("Slice_get_integer %d\n", (int)v); */
@@ -137,9 +224,18 @@
return s;
}
+/*
+
+=item C<PMC* nextkey_keyed (PMC* agg, INTVAL what)>
+
+Prepate slice PMC SELF for iteration over the passed aggregate or
+advance to next position in the range, dpending on what.
+
+=cut
+
+*/
PMC* nextkey_keyed (PMC* agg, INTVAL what) {
PMC *ret = SELF;
- PMC *current_key;
switch (what) {
case ITERATE_FROM_START:
@@ -147,8 +243,11 @@
/*
* need a new Slice PMC that hold's the state
* especially PMC_data() must be zero
+ *
+ * aggregate call get_integer/get_string on this
+ * PMC, because it's marked being a Key PMC
*/
- ret = pmc_new_noinit(INTERP, enum_class_Slice);
+ ret = pmc_new(INTERP, enum_class_Slice);
PObj_get_FLAGS(ret) &= ~KEY_type_FLAGS;
PObj_get_FLAGS(ret) |= KEY_pmc_FLAG;
@@ -157,11 +256,20 @@
* remember slice chain in PMC_pmc_val
*/
PMC_pmc_val(ret) = SELF;
+ /*
+ * and set start value
+ */
set_slice_start(INTERP, ret);
break;
+ /*
+ * we are passed now the new PMC, we had created above
+ */
case ITERATE_GET_NEXT:
set_slice_next(INTERP, ret, agg);
break;
+ default:
+ internal_exception(1, "No backward iteration on slices yet");
+ break;
}
return ret;
}
1.51 +6 -6 parrot/imcc/symreg.h
Index: symreg.h
===================================================================
RCS file: /cvs/public/parrot/imcc/symreg.h,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -w -r1.50 -r1.51
--- symreg.h 17 Jun 2004 12:04:42 -0000 1.50
+++ symreg.h 18 Jun 2004 13:06:58 -0000 1.51
@@ -19,12 +19,12 @@
VT_CONSTP = 1 << 7, /* pointer to constant value */
VT_PCC_SUB = 1 << 8, /* PCC subroutine call */
VT_FLATTEN = 1 << 9, /* .flatten_arg IDENT | VTIDENT ... */
- /* XXX s. src/packfile.c */
- VT_START_SLICE = 1 << 10, /* x .. y slice range */
- VT_END_SLICE = 1 << 11,
- VT_START_ZERO = 1 << 12, /* .. y 0..start */
- VT_END_INF = 1 << 13, /* x.. start..inf */
- VT_SLICE_BITS = VT_START_SLICE | VT_END_SLICE | VT_START_ZERO | VT_END_INF
+ /* include/parrot/packfile.h */
+ VT_START_SLICE = PF_VT_START_SLICE , /* x .. y slice range */
+ VT_END_SLICE = PF_VT_END_SLICE ,
+ VT_START_ZERO = PF_VT_START_ZERO , /* .. y 0..start */
+ VT_END_INF = PF_VT_END_INF , /* x.. start..inf */
+ VT_SLICE_BITS = PF_VT_SLICE_BITS
};
/* this VARTYPE needs register allocation and such */
1.63 +10 -1 parrot/include/parrot/packfile.h
Index: packfile.h
===================================================================
RCS file: /cvs/public/parrot/include/parrot/packfile.h,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -w -r1.62 -r1.63
--- packfile.h 26 May 2004 19:14:28 -0000 1.62
+++ packfile.h 18 Jun 2004 13:07:01 -0000 1.63
@@ -1,6 +1,6 @@
/* packfile.h
*
-* $Id: packfile.h,v 1.62 2004/05/26 19:14:28 jrieks Exp $
+* $Id: packfile.h,v 1.63 2004/06/18 13:07:01 leo Exp $
*
* History:
* Rework by Melvin; new bytecode format, make bytecode portable.
@@ -141,6 +141,15 @@
#define PFC_KEY '\153'
#define PFC_PMC '\160'
+enum PF_VARTYPE { /* s. also imcc/symreg.h */
+ PF_VT_START_SLICE = 1 << 10, /* x .. y slice range */
+ PF_VT_END_SLICE = 1 << 11,
+ PF_VT_START_ZERO = 1 << 12, /* .. y 0..start */
+ PF_VT_END_INF = 1 << 13, /* x.. start..inf */
+ PF_VT_SLICE_BITS = PF_VT_START_SLICE | PF_VT_END_SLICE |
+ PF_VT_START_ZERO | PF_VT_END_INF
+};
+
struct PackFile_Constant {
opcode_t type;
union {
1.166 +6 -17 parrot/src/packfile.c
Index: packfile.c
===================================================================
RCS file: /cvs/public/parrot/src/packfile.c,v
retrieving revision 1.165
retrieving revision 1.166
diff -u -w -r1.165 -r1.166
--- packfile.c 17 Jun 2004 16:30:25 -0000 1.165
+++ packfile.c 18 Jun 2004 13:07:06 -0000 1.166
@@ -2,7 +2,7 @@
Copyright (C) 2001-2002 Gregor N. Purdy. All rights reserved.
This program is free software. It is subject to the same license as
Parrot itself.
-$Id: packfile.c,v 1.165 2004/06/17 16:30:25 leo Exp $
+$Id: packfile.c,v 1.166 2004/06/18 13:07:06 leo Exp $
=head1 NAME
@@ -28,17 +28,6 @@
#include "parrot/embed.h"
#include "parrot/packfile.h"
-/*
- * XXX copy from imcc/symreg.h
- */
-enum VARTYPE { /* variable type can be */
- VT_START_SLICE = 1 << 10, /* x .. y slice range */
- VT_END_SLICE = 1 << 11,
- VT_START_ZERO = 1 << 12, /* .. y 0..start */
- VT_END_INF = 1 << 13, /* x.. start..inf */
- VT_SLICE_BITS = VT_START_SLICE | VT_END_SLICE | VT_START_ZERO | VT_END_INF
-};
-
#include <assert.h>
#define TRACE_PACKFILE 0
@@ -2989,8 +2978,8 @@
while (components-- > 0) {
type = PF_fetch_opcode(pf, &cursor);
- slice_bits = type & VT_SLICE_BITS;
- type &= ~VT_SLICE_BITS;
+ slice_bits = type & PF_VT_SLICE_BITS;
+ type &= ~PF_VT_SLICE_BITS;
if (!head && slice_bits) {
pmc_enum = enum_class_Slice;
}
@@ -3032,11 +3021,11 @@
return 0;
}
if (slice_bits) {
- if (slice_bits & VT_START_SLICE)
+ if (slice_bits & PF_VT_START_SLICE)
PObj_get_FLAGS(tail) |= KEY_start_slice_FLAG;
- if (slice_bits & VT_END_SLICE)
+ if (slice_bits & PF_VT_END_SLICE)
PObj_get_FLAGS(tail) |= KEY_end_slice_FLAG;
- if (slice_bits & (VT_START_ZERO | VT_END_INF))
+ if (slice_bits & (PF_VT_START_ZERO | PF_VT_END_INF))
PObj_get_FLAGS(tail) |= KEY_inf_slice_FLAG;
}
}