Skip to content

Commit

Permalink
add a clone VTABLE. Also, fix the iterate_function_inplace method
Browse files Browse the repository at this point in the history
  • Loading branch information
Whiteknight committed Oct 28, 2009
1 parent 779e591 commit c22fac9
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/pmc/nummatrix2d.pmc
Expand Up @@ -255,6 +255,30 @@ pmclass NumMatrix2D dynpmc auto_attrs {
return PMCNULL;
}

VTABLE PMC * clone() {
PMC * const c = pmc_new(INTERP, SELF->vtable->base_type);
Parrot_NumMatrix2D_attributes * const old_atts =
(Parrot_NumMatrix2D_attributes *)PARROT_NUMMATRIX2D(SELF);
Parrot_NumMatrix2D_attributes * const new_atts =
(Parrot_NumMatrix2D_attributes *)PARROT_NUMMATRIX2D(c);
INTVAL x, y;
INTVAL const x_size = old_attrs->x;
INTVAL const y_size = old_attrs->y;
INTVAL const newsize = x_size * y_size;
FLOATVAL * old_s = old_attrs->storage;
FLOATVAL * new_s = (FLOATVAL *)mem_sys_allocate_zeroed(newsize * sizeof (FLOATVAL));
for (x = 0; x < x_size; ++x) {
for (y = 0; y < y_size; ++y) {
ITEM_XY_ROWMAJOR(new_s, x_size, y_size, x, y) =
ITEM_XY_ROWMAJOR(old_s, x_size, y_size, x, y);
}
}
new_attrs->storage = new_s;
new_attrs->x = x_size;
new_attrs->y = y_size;
return c;
}

METHOD fill(FLOATVAL value) {
Parrot_NumMatrix2D_attributes * const attrs
= (Parrot_NumMatrix2D_attributes *) PARROT_NUMMATRIX2D(SELF);
Expand Down Expand Up @@ -315,7 +339,7 @@ pmclass NumMatrix2D dynpmc auto_attrs {
for (j = 0; j < min_y; j++) {
FLOATVAL value = ITEM_XY_ROWMAJOR(old_s, x, y, i, j);
FLOATVAL result = 0.0;
Parrot_ext_call(INTERP, func, "PiNPf->N", SELF, value, args, &result);
Parrot_ext_call(INTERP, func, "PNPf->N", SELF, value, args, &result);
ITEM_XY_ROWMAJOR(new_s, x, y, i, j) = result;
}
}
Expand Down

0 comments on commit c22fac9

Please sign in to comment.