Skip to content

Commit

Permalink
fixes and additions to pmcmatrix2d that I thought I added earlier, an…
Browse files Browse the repository at this point in the history
…d some new tests
  • Loading branch information
Whiteknight committed Dec 9, 2009
1 parent 538247b commit 7a821da
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
16 changes: 10 additions & 6 deletions src/pmc/pmcmatrix2d.pmc
Expand Up @@ -7,7 +7,7 @@ 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. */
static void
resize_matrix(PARROT_INTERP, PMC * self, INTVAL col, INTVAL row)
resize_matrix(PARROT_INTERP, PMC * self, INTVAL row, INTVAL col)
{
Parrot_PMCMatrix2D_attributes * const attrs = PARROT_PMCMATRIX2D(self);
const INTVAL old_cols = attrs->cols;
Expand Down Expand Up @@ -63,7 +63,7 @@ pmclass PMCMatrix2D dynpmc auto_attrs provides matrix {
Parrot_gc_mark_PMC_alive(INTERP, item);
}
}

VTABLE PMC * get_pmc_keyed(PMC * key) {
INTVAL cols, rows, cols_size, rows_size;
Parrot_PMCMatrix2D_attributes * const attrs = PARROT_PMCMATRIX2D(SELF);
Expand Down Expand Up @@ -108,7 +108,7 @@ pmclass PMCMatrix2D dynpmc auto_attrs provides matrix {
rows_size = attrs->rows;
GET_KEY_INDICES_ROWMAJOR(INTERP, key, rows, cols);
if (cols >= cols_size || rows >= rows_size) {
resize_matrix(INTERP, SELF, cols, rows);
resize_matrix(INTERP, SELF, rows, cols);
cols_size = attrs->cols;
rows_size = attrs->rows;
}
Expand Down Expand Up @@ -142,8 +142,8 @@ pmclass PMCMatrix2D dynpmc auto_attrs provides matrix {
PMC ** const s = attrs->storage;
const INTVAL rows_size = attrs->rows;
const INTVAL cols_size = attrs->cols;
for (cols = 0; cols < cols_size; ++cols) {
for (rows = 0; rows < rows_size; ++rows) {
for (rows = 0; rows < rows_size; ++rows) {
for (cols = 0; cols < cols_size; ++cols) {
PMC * const item = ITEM_XY_ROWMAJOR(s, rows_size, cols_size, rows, cols);
STRING * const str = VTABLE_get_string(INTERP, item);
STRING * const index = Parrot_sprintf_c(INTERP, "\t[%d,%d] = ", rows, cols);
Expand All @@ -156,7 +156,7 @@ pmclass PMCMatrix2D dynpmc auto_attrs provides matrix {
pstr = Parrot_str_append(INTERP, pstr, newline);
return pstr;
}

VTABLE PMC * get_attr_str(STRING * idx) {
Parrot_PMCMatrix2D_attributes * const attrs = PARROT_PMCMATRIX2D(SELF);
if (Parrot_str_equal(INTERP, idx, CONST_STRING(INTERP, "rows"))) {
Expand Down Expand Up @@ -198,5 +198,9 @@ pmclass PMCMatrix2D dynpmc auto_attrs provides matrix {
}
}
}

METHOD resize(INTVAL rows, INTVAL cols) {
resize_matrix(INTERP, SELF, rows - 1, cols - 1);
}
}

21 changes: 19 additions & 2 deletions t/pmc/pmcmatrix2d.t
Expand Up @@ -18,7 +18,7 @@ sub MAIN () {
pla_library_loaded:
};

plan(11);
plan(15);
create_pmcmatrix2d();
op_does_matrix();
vtable_set_pmc_keyed();
Expand All @@ -30,6 +30,8 @@ sub MAIN () {
vtable_set_number_keyed();
vtable_set_string_keyed();
vtable_get_string();
method_initialize_from_array();
method_resize();
}

sub create_pmcmatrix2d() {
Expand Down Expand Up @@ -135,7 +137,7 @@ sub vtable_set_number_keyed() {
$P0[0;0] = $N0
$N1 = $P0[0;0]
is($N1, 3.1415, "set_number_keyed works")
}
}
}

sub vtable_set_string_keyed() {
Expand All @@ -160,4 +162,19 @@ sub vtable_get_string() {
}
}

sub method_initialize_from_array() {}
sub method_resize() {
Q:PIR {
$P0 = new ['PMCMatrix2D']
$P1 = getattribute $P0, "rows"
is($P1, 0)
$P1 = getattribute $P0, "cols"
is($P1, 0)
$P0.'resize'(5, 3)
$P1 = getattribute $P0, "rows"
is($P1, 5)
$P1 = getattribute $P0, "cols"
is($P1, 3)
}
}

0 comments on commit 7a821da

Please sign in to comment.