Skip to content

Commit

Permalink
add initial freeze/thaw prototype code for NumMatrix2D. This requires…
Browse files Browse the repository at this point in the history
… pmc_freeze_with_pmcs branch, which isn't merged into Parrot trunk yet. Will have to set a minimum parrot version once that merges
  • Loading branch information
Whiteknight committed Feb 2, 2010
1 parent e7d84d6 commit 4d57990
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/pmc/complexmatrix2d.pmc
Expand Up @@ -7,7 +7,7 @@
are initialized to 0.0. Parameters x and y are the indices that are trying
to be accessed, so we must resize the matrix to be able to accomodate those
indices. Notice that the matrix type is zero-indexed, so the size is one
plus the highest index that we need to access.
plus the highest index that we need to access.

This function will not shrink the matrix, only grow it. After the call,
the matrix will be at least large enough to hold an item at the given
Expand Down Expand Up @@ -78,7 +78,7 @@ get_complex_pmc_at_xy(PARROT_INTERP, PMC *self, INTVAL rows, INTVAL cols)
const INTVAL flags = attrs->flags;
FLOATVAL real, imag;
FLOATVAL * const s = attrs->storage;

if (rows >= rows_size || cols >= cols_size)
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_OUT_OF_BOUNDS,
"ComplexMatrix2d: indices out of bounds");
Expand Down Expand Up @@ -234,7 +234,7 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix {
GET_KEY_INDICES_ROWMAJOR(INTERP, key, rows, cols);
set_complex_pmc_at_xy(INTERP, SELF, value, rows, cols);
}

VTABLE void set_string_keyed(PMC * key, STRING * value) {
PMC * const item = pmc_new(INTERP, enum_class_Complex);
VTABLE_set_string_native(INTERP, item, value);
Expand Down
42 changes: 42 additions & 0 deletions src/pmc/nummatrix2d.pmc
Expand Up @@ -555,6 +555,48 @@ pmclass NumMatrix2D dynpmc auto_attrs provides matrix {
return 0;
}

VTABLE void freeze(PMC *info) {
Parrot_NumMatrix2D_attributes * const attrs = PARROT_NUMMATRIX2D(SELF);
INTVAL const rows = attrs->rows;
INTVAL const cols = attrs->cols;
INTVAL const flags = attrs->flags;
INTVAL i, j;
FLOATVAL * const s = attrs->storage;
VTABLE_push_integer(INTERP, info, rows);
VTABLE_push_integer(INTERP, info, cols);
VTABLE_push_integer(INTERP, info, flags);
for (i = 0; i < cols; i++) {
for (j = 0; j < rows; j++) {
const FLOATVAL f = ITEM_XY(s, flags, rows, cols, j, i);
VTABLE_push_float(INTERP, info, f);
}
}
}

VTABLE void thaw(PMC *info) {
Parrot_NumMatrix2D_attributes * const attrs = PARROT_NUMMATRIX2D(SELF);
INTVAL const rows = VTABLE_shift_integer(INTERP, info);
INTVAL const cols = VTABLE_shift_integer(INTERP, info);
INTVAL const flags = VTABLE_shift_integer(INTERP, info);
INTVAL i, j;
FLOATVAL * s;
attrs->rows = 0;
attrs->cols = 0;
attrs->storage = NULL;
attrs->flags = 0;
resize_matrix(INTERP, SELF, rows - 1, cols - 1);
s = attrs->storage;
attrs->flags = flags;
for (i = 0; i < cols; i++) {
for (j = 0; j < rows; j++) {
const FLOATVAL f = VTABLE_shift_float(INTERP, info);
ITEM_XY(s, flags, rows, cols, j, i) = f;
}
}
}




/*

Expand Down

0 comments on commit 4d57990

Please sign in to comment.