Permalink
Browse files

Refactor elems.

  • Loading branch information...
jnthn committed Feb 9, 2013
1 parent bf54542 commit 08684cde09158c2e8c422b51d41d84eceb6e646f
Showing with 26 additions and 24 deletions.
  1. +6 −4 src/6model/repr_registry.c
  2. +8 −8 src/6model/reprs/CArray.c
  3. +8 −8 src/6model/reprs/P6opaque.c
  4. +3 −3 src/6model/sixmodelobject.h
  5. +1 −1 src/ops/nqp.ops
View
@@ -93,9 +93,6 @@ static void default_bind_pos_native(PARROT_INTERP, STable *st, void *data, INTVA
static void default_bind_pos_boxed(PARROT_INTERP, STable *st, void *data, INTVAL index, PMC *obj) {
die_no_pos(interp, st->REPR->name);
}
-static INTVAL default_elems(PARROT_INTERP, STable *st, void *data) {
- die_no_pos(interp, st->REPR->name);
-}
static void default_push_boxed(PARROT_INTERP, STable *st, void *data, PMC *obj) {
die_no_pos(interp, st->REPR->name);
}
@@ -128,6 +125,10 @@ static INTVAL default_exists_key(PARROT_INTERP, STable *st, void *data, STRING *
static void default_delete_key(PARROT_INTERP, STable *st, void *data, STRING *key) {
die_no_ass(interp, st->REPR->name);
}
+static INTVAL default_elems(PARROT_INTERP, STable *st, void *data) {
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
+ "%Ss representation does not support elems", st->REPR->name);
+}
/* Set default attribute functions on a REPR that lacks them. */
static void add_default_attr_funcs(PARROT_INTERP, REPROps *repr) {
@@ -159,7 +160,6 @@ static void add_default_pos_funcs(PARROT_INTERP, REPROps *repr) {
repr->pos_funcs->at_pos_boxed = default_at_pos_boxed;
repr->pos_funcs->bind_pos_native = default_bind_pos_native;
repr->pos_funcs->bind_pos_boxed = default_bind_pos_boxed;
- repr->pos_funcs->elems = default_elems;
repr->pos_funcs->push_boxed = default_push_boxed;
repr->pos_funcs->pop_boxed = default_pop_boxed;
repr->pos_funcs->unshift_boxed = default_unshift_boxed;
@@ -197,6 +197,8 @@ static void register_repr(PARROT_INTERP, STRING *name, REPROps *repr) {
add_default_pos_funcs(interp, repr);
if (!repr->ass_funcs)
add_default_ass_funcs(interp, repr);
+ if (!repr->elems)
+ repr->elems = default_elems;
}
/* Dynamically registers a representation (that is, one defined outside of
View
@@ -442,13 +442,6 @@ static void bind_pos_boxed(PARROT_INTERP, STable *st, void *data, INTVAL index,
body->child_objs[index] = obj;
storage[index] = cptr;
}
-static INTVAL elems(PARROT_INTERP, STable *st, void *data) {
- CArrayBody *body = (CArrayBody *)data;
- if (body->managed)
- return body->elems;
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
- "Don't know how many elements a C array returned from a library has");
-}
static STable * get_elem_stable(PARROT_INTERP, STable *st) {
CArrayREPRData *repr_data = (CArrayREPRData *)st->REPR_data;
return STABLE(repr_data->elem_type);
@@ -465,6 +458,13 @@ static void unshift_boxed(PARROT_INTERP, STable *st, void *data, PMC *obj) {
static PMC * shift_boxed(PARROT_INTERP, STable *st, void *data) {
die_pos_nyi(interp);
}
+static INTVAL elems(PARROT_INTERP, STable *st, void *data) {
+ CArrayBody *body = (CArrayBody *)data;
+ if (body->managed)
+ return body->elems;
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
+ "Don't know how many elements a C array returned from a library has");
+}
/* Serializes the REPR data. */
static void serialize_repr_data(PARROT_INTERP, STable *st, SerializationWriter *writer) {
@@ -507,12 +507,12 @@ REPROps * CArray_initialize(PARROT_INTERP,
this_repr->pos_funcs->at_pos_boxed = at_pos_boxed;
this_repr->pos_funcs->bind_pos_native = bind_pos_native;
this_repr->pos_funcs->bind_pos_boxed = bind_pos_boxed;
- this_repr->pos_funcs->elems = elems;
this_repr->pos_funcs->push_boxed = push_boxed;
this_repr->pos_funcs->pop_boxed = pop_boxed;
this_repr->pos_funcs->unshift_boxed = unshift_boxed;
this_repr->pos_funcs->shift_boxed = shift_boxed;
this_repr->pos_funcs->get_elem_stable = get_elem_stable;
+ this_repr->elems = elems;
this_repr->serialize_repr_data = serialize_repr_data;
this_repr->deserialize_repr_data = deserialize_repr_data;
@@ -772,13 +772,6 @@ static void bind_pos_boxed(PARROT_INTERP, STable *st, void *data, INTVAL index,
get_pmc_at_offset(data, repr_data->attribute_offsets[repr_data->pos_del_slot]),
index, obj);
}
-static INTVAL elems(PARROT_INTERP, STable *st, void *data) {
- P6opaqueREPRData *repr_data = (P6opaqueREPRData *)st->REPR_data;
- if (repr_data->pos_del_slot == -1)
- die_no_pos_del(interp);
- return VTABLE_elements(interp,
- get_pmc_at_offset(data, repr_data->attribute_offsets[repr_data->pos_del_slot]));
-}
static void push_boxed(PARROT_INTERP, STable *st, void *data, PMC *obj) {
P6opaqueREPRData *repr_data = (P6opaqueREPRData *)st->REPR_data;
if (repr_data->pos_del_slot == -1)
@@ -816,6 +809,13 @@ static STable * get_elem_stable(PARROT_INTERP, STable *st) {
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"This type does not support get_elem_stable");
}
+static INTVAL elems(PARROT_INTERP, STable *st, void *data) {
+ P6opaqueREPRData *repr_data = (P6opaqueREPRData *)st->REPR_data;
+ if (repr_data->pos_del_slot == -1)
+ die_no_pos_del(interp);
+ return VTABLE_elements(interp,
+ get_pmc_at_offset(data, repr_data->attribute_offsets[repr_data->pos_del_slot]));
+}
/* This Parrot-specific addition to the API is used to mark an object. */
static void gc_mark(PARROT_INTERP, STable *st, void *data) {
@@ -1220,12 +1220,12 @@ REPROps * P6opaque_initialize(PARROT_INTERP) {
this_repr->pos_funcs->at_pos_boxed = at_pos_boxed;
this_repr->pos_funcs->bind_pos_native = bind_pos_native;
this_repr->pos_funcs->bind_pos_boxed = bind_pos_boxed;
- this_repr->pos_funcs->elems = elems;
this_repr->pos_funcs->push_boxed = push_boxed;
this_repr->pos_funcs->pop_boxed = pop_boxed;
this_repr->pos_funcs->unshift_boxed = unshift_boxed;
this_repr->pos_funcs->shift_boxed = shift_boxed;
this_repr->pos_funcs->get_elem_stable = get_elem_stable;
+ this_repr->elems = elems;
this_repr->gc_mark = gc_mark;
this_repr->gc_free = gc_free;
this_repr->gc_mark_repr_data = gc_mark_repr_data;
@@ -255,9 +255,6 @@ typedef struct SixModel_REPROps_Positional {
/* Binds the object at the specified address into the array at the specified index.
* For arrays of non-reference types, expects a compatible type. */
void (*bind_pos_boxed) (PARROT_INTERP, STable *st, void *data, INTVAL index, PMC *obj);
-
- /* Gets the number of elements. */
- INTVAL (*elems) (PARROT_INTERP, STable *st, void *data);
/* Pushes an object. */
void (*push_boxed) (PARROT_INTERP, STable *st, void *data, PMC *obj);
@@ -327,6 +324,9 @@ struct SixModel_REPROps {
/* Associative REPR function table. */
struct SixModel_REPROps_Associative *ass_funcs;
+ /* Gets the number of elements, if it's relevant. */
+ INTVAL (*elems) (PARROT_INTERP, STable *st, void *data);
+
/* Gets the storage specification for this representation. */
storage_spec (*get_storage_spec) (PARROT_INTERP, STable *st);
View
@@ -1299,7 +1299,7 @@ inline op repr_elems(out INT, invar PMC) :base_core {
PMC *obj = decontainerize(interp, $2);
if (obj->vtable->base_type == smo_id) {
if (IS_CONCRETE(obj))
- $1 = REPR(obj)->pos_funcs->elems(interp, STABLE(obj), OBJECT_BODY(obj));
+ $1 = REPR(obj)->elems(interp, STABLE(obj), OBJECT_BODY(obj));
else
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Cannot do repr_elems on a type object");

0 comments on commit 08684cd

Please sign in to comment.