Permalink
Browse files

First implementation of VMIter REPR.

  • Loading branch information...
1 parent cc2b6ef commit 28c4f1ef583a51d5cbf8478aeb70c7bce8033ca1 @arnsholt arnsholt committed Mar 17, 2013
Showing with 34 additions and 1 deletion.
  1. +22 −0 src/6model/reprs/VMIter.c
  2. +12 −1 src/6model/reprs/VMIter.h
View
@@ -69,6 +69,26 @@ static storage_spec get_storage_spec(PARROT_INTERP, STable *st) {
return spec;
}
+static PMC *shift_boxed(PARROT_INTERP, STable *st, void *data) {
+ VMIterBody *body = (VMIterBody *) data;
+ PMC *target = body->target;
+
+ switch (body->mode) {
+ case VMITER_MODE_ARRAY:
+ body->idx++;
+ if (body->idx >= body->limit)
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_OUT_OF_BOUNDS,
+ "VMIter: Iteration past end of array");
+ return REPR(target)->pos_funcs->at_pos_boxed(interp, STABLE(target), OBJECT_BODY(target), body->idx);
+ case VMITER_MODE_HASH:
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
+ "VMIter: Hash iteration not implemented yet.");
+ default:
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
+ "VMIter: Unknow iteration mode %d", body->mode);
+ }
+}
+
/* Initializes the VMIter representation. */
REPROps * VMIter_initialize(PARROT_INTERP) {
/* Allocate and populate the representation function table. */
@@ -80,5 +100,7 @@ REPROps * VMIter_initialize(PARROT_INTERP) {
this_repr->copy_to = copy_to;
this_repr->gc_free = gc_free;
this_repr->get_storage_spec = get_storage_spec;
+ this_repr->pos_funcs = mem_allocate_zeroed_typed(REPROps_Positional);
+ this_repr->pos_funcs->shift_boxed = shift_boxed;
return this_repr;
}
View
@@ -1,9 +1,20 @@
#ifndef VMITER_H_GUARD
#define VMITER_H_GUARD
+#define VMITER_MODE_ARRAY 1
+#define VMITER_MODE_HASH 2
+
/* Body of a VMIter. */
typedef struct {
- INTVAL dummy; /* Todo... */
+ PMC *target;
+
+ /* Array iteration state. */
+ INTVAL idx;
+ INTVAL limit;
+
+ /*TODO: Hash iteration mode.*/
+
+ INTVAL mode;
} VMIterBody;
/* This is how an instance with the VMIter representation looks. */

0 comments on commit 28c4f1e

Please sign in to comment.