Skip to content

Commit

Permalink
boxing primitive types respects HLL mappings. Untested
Browse files Browse the repository at this point in the history
  • Loading branch information
Whiteknight committed Sep 3, 2010
1 parent 8b3241e commit cfcbcb1
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 32 deletions.
1 change: 1 addition & 0 deletions src/include/pla_matrix_library.h
Expand Up @@ -8,5 +8,6 @@ void get_complex_value_from_pmc(PARROT_INTERP, PMC * value, FLOATVAL * real,
void intkey_to_coords(PARROT_INTERP, const INTVAL rows, const INTVAL cols,
const INTVAL key, INTVAL * row, INTVAL * col);

PMC * get_external_pmc(PARROT_INTERP, const INTVAL type);

#endif /* _PLA_MATRIX_LIBRARY_H */
9 changes: 9 additions & 0 deletions src/lib/matrix_common.c
Expand Up @@ -18,3 +18,12 @@ intkey_to_coords(PARROT_INTERP, const INTVAL rows, const INTVAL cols,
*col = c;
}
}

/* Get an instance of an externally-defined (non-PLA) PMC type. Account for
subtypes */
PMC *
get_external_pmc(PARROT_INTERP, const INTVAL type)
{
INTVAL realtype = Parrot_get_ctx_HLL_type(interp, type);
return Parrot_pmc_new(interp, realtype);
}
14 changes: 7 additions & 7 deletions src/pmc/complexmatrix2d.pmc
Expand Up @@ -144,7 +144,7 @@ get_complex_pmc_at_xy(PARROT_INTERP, PMC *self, INTVAL rows, INTVAL cols)
PLATYPENAME ": indices out of bounds");
real = R_ITEM_XY(s, flags, rows_size, cols_size, rows, cols);
imag = I_ITEM_XY(s, flags, rows_size, cols_size, rows, cols);
newcomplex = Parrot_pmc_new(interp, enum_class_Complex);
newcomplex = get_external_pmc(interp, enum_class_Complex);
VTABLE_set_number_keyed_int(interp, newcomplex, 0, real);
VTABLE_set_number_keyed_int(interp, newcomplex, 1, imag);
return newcomplex;
Expand Down Expand Up @@ -601,7 +601,7 @@ integer, and 0 for the complex value.
}

VTABLE void set_string_keyed(PMC * key, STRING * value) {
PMC * const item = Parrot_pmc_new(INTERP, enum_class_Complex);
PMC * const item = get_external_pmc(INTERP, enum_class_Complex);
VTABLE_set_string_native(INTERP, item, value);
VTABLE_set_pmc_keyed(INTERP, SELF, key, item);
}
Expand Down Expand Up @@ -670,7 +670,7 @@ Convert the string to a Complex PMC, and set that at the specified location.
VTABLE void set_string_keyed_int(INTVAL key, STRING * value) {
DECLATTRS_ComplexMatrix2D(SELF, attrs);
INTVAL row, col;
PMC * const item = Parrot_pmc_new(INTERP, enum_class_Complex);
PMC * const item = get_external_pmc(INTERP, enum_class_Complex);
VTABLE_set_string_native(INTERP, item, value);
VTABLE_set_pmc_keyed_int(INTERP, SELF, key, item);
}
Expand Down Expand Up @@ -706,7 +706,7 @@ Determine if two matrices are equal in size and composition.
VTABLE STRING *get_string() {
DECLATTRS_ComplexMatrix2D(SELF, attrs);
INTVAL rows, cols;
PMC * const builder = Parrot_pmc_new(INTERP, enum_class_StringBuilder);
PMC * const builder = get_external_pmc(INTERP, enum_class_StringBuilder);
STRING * const newline = Parrot_str_new(INTERP, "\n", 1);
FLOATVAL * const s = attrs->storage;
const INTVAL rows_size = attrs->rows;
Expand Down Expand Up @@ -740,17 +740,17 @@ Determine if two matrices are equal in size and composition.
VTABLE PMC * get_attr_str(STRING * idx) {
DECLATTRS_ComplexMatrix2D(SELF, attrs);
if (Parrot_str_equal(INTERP, idx, CONST_STRING(INTERP, "rows"))) {
PMC * const rows = Parrot_pmc_new(INTERP, enum_class_Integer);
PMC * const rows = get_external_pmc(INTERP, enum_class_Integer);
VTABLE_set_integer_native(INTERP, rows, attrs->rows);
return rows;
}
else if (Parrot_str_equal(INTERP, idx, CONST_STRING(INTERP, "cols"))) {
PMC * const cols = Parrot_pmc_new(INTERP, enum_class_Integer);
PMC * const cols = get_external_pmc(INTERP, enum_class_Integer);
VTABLE_set_integer_native(INTERP, cols, attrs->cols);
return cols;
}
else if (Parrot_str_equal(INTERP, idx, CONST_STRING(INTERP, "size"))) {
PMC * const size = Parrot_pmc_new(INTERP, enum_class_Integer);
PMC * const size = get_external_pmc(INTERP, enum_class_Integer);
VTABLE_set_integer_native(INTERP, size, attrs->cols * attrs->rows);
return size;
}
Expand Down
12 changes: 6 additions & 6 deletions src/pmc/nummatrix2d.pmc
Expand Up @@ -326,7 +326,7 @@ elements.

VTABLE PMC * get_pmc_keyed(PMC * key) {
const FLOATVAL f = VTABLE_get_number_keyed(INTERP, SELF, key);
PMC * const item = Parrot_pmc_new(INTERP, enum_class_Float);
PMC * const item = get_external_pmc(INTERP, enum_class_Float);
VTABLE_set_number_native(INTERP, item, f);
return item;
}
Expand Down Expand Up @@ -391,7 +391,7 @@ Nth number. The array is arranged in memory row by row.

VTABLE PMC * get_pmc_keyed_int(INTVAL key) {
const FLOATVAL f = VTABLE_get_number_keyed_int(INTERP, SELF, key);
PMC * const item = Parrot_pmc_new(INTERP, enum_class_Float);
PMC * const item = get_external_pmc(INTERP, enum_class_Float);
VTABLE_set_number_native(INTERP, item, f);
return item;
}
Expand Down Expand Up @@ -545,7 +545,7 @@ Determine if two matrices are equal in size and composition.
VTABLE STRING *get_string() {
DECLATTRS_NumMatrix2D(SELF, attrs);
INTVAL i, j;
PMC * const builder = Parrot_pmc_new(INTERP, enum_class_StringBuilder);
PMC * const builder = get_external_pmc(INTERP, enum_class_StringBuilder);
STRING * const newline = Parrot_str_new(INTERP, "\n", 1);
STRING * const tab = Parrot_str_new(INTERP, "\t", 1);
FLOATVAL * const s = attrs->storage;
Expand All @@ -569,17 +569,17 @@ Determine if two matrices are equal in size and composition.
VTABLE PMC * get_attr_str(STRING * idx) {
DECLATTRS_NumMatrix2D(SELF, attrs);
if (Parrot_str_equal(INTERP, idx, CONST_STRING(INTERP, "rows"))) {
PMC * const rows = Parrot_pmc_new(INTERP, enum_class_Integer);
PMC * const rows = get_external_pmc(INTERP, enum_class_Integer);
VTABLE_set_integer_native(INTERP, rows, attrs->rows);
return rows;
}
else if (Parrot_str_equal(INTERP, idx, CONST_STRING(INTERP, "cols"))) {
PMC * const cols = Parrot_pmc_new(INTERP, enum_class_Integer);
PMC * const cols = get_external_pmc(INTERP, enum_class_Integer);
VTABLE_set_integer_native(INTERP, cols, attrs->cols);
return cols;
}
else if (Parrot_str_equal(INTERP, idx, CONST_STRING(INTERP, "size"))) {
PMC * const size = Parrot_pmc_new(INTERP, enum_class_Integer);
PMC * const size = get_external_pmc(INTERP, enum_class_Integer);
VTABLE_set_integer_native(INTERP, size, attrs->cols * attrs->rows);
return size;
}
Expand Down
18 changes: 9 additions & 9 deletions src/pmc/pmcmatrix2d.pmc
Expand Up @@ -359,19 +359,19 @@ location
}

VTABLE void set_integer_keyed(PMC * key, INTVAL value) {
PMC * const item = Parrot_pmc_new(INTERP, enum_class_Integer);
PMC * const item = get_external_pmc(INTERP, enum_class_Integer);
VTABLE_set_integer_native(INTERP, item, value);
VTABLE_set_pmc_keyed(INTERP, SELF, key, item);
}

VTABLE void set_number_keyed(PMC * key, FLOATVAL value) {
PMC * const item = Parrot_pmc_new(INTERP, enum_class_Float);
PMC * const item = get_external_pmc(INTERP, enum_class_Float);
VTABLE_set_number_native(INTERP, item, value);
VTABLE_set_pmc_keyed(INTERP, SELF, key, item);
}

VTABLE void set_string_keyed(PMC * key, STRING * value) {
PMC * const item = Parrot_pmc_new(INTERP, enum_class_String);
PMC * const item = get_external_pmc(INTERP, enum_class_String);
VTABLE_set_string_native(INTERP, item, value);
VTABLE_set_pmc_keyed(INTERP, SELF, key, item);
}
Expand Down Expand Up @@ -426,13 +426,13 @@ location
}

VTABLE void set_string_keyed_int(INTVAL key, STRING * value) {
PMC * const item = Parrot_pmc_new(INTERP, enum_class_String);
PMC * const item = get_external_pmc(INTERP, enum_class_String);
VTABLE_set_string_native(INTERP, item, value);
VTABLE_set_pmc_keyed_int(INTERP, SELF, key, item);
}

VTABLE void set_number_keyed_int(INTVAL key, FLOATVAL value) {
PMC * const item = Parrot_pmc_new(INTERP, enum_class_Float);
PMC * const item = get_external_pmc(INTERP, enum_class_Float);
VTABLE_set_number_native(INTERP, item, value);
VTABLE_set_pmc_keyed_int(INTERP, SELF, key, item);
}
Expand Down Expand Up @@ -468,7 +468,7 @@ Determine if two matrices are equal in size and composition.
VTABLE STRING *get_string() {
DECLATTRS_PMCMatrix2D(SELF, attrs);
INTVAL rows, cols;
PMC * builder = Parrot_pmc_new(INTERP, enum_class_StringBuilder);
PMC * builder = get_external_pmc(INTERP, enum_class_StringBuilder);
STRING * const strend = Parrot_str_new(INTERP, "}", 1);
STRING * const newline = Parrot_str_new(INTERP, "\n", 1);
PMC ** const s = attrs->storage;
Expand Down Expand Up @@ -500,17 +500,17 @@ Determine if two matrices are equal in size and composition.
VTABLE PMC * get_attr_str(STRING * idx) {
DECLATTRS_PMCMatrix2D(SELF, attrs);
if (Parrot_str_equal(INTERP, idx, CONST_STRING(INTERP, "rows"))) {
PMC * const rows = Parrot_pmc_new(INTERP, enum_class_Integer);
PMC * const rows = get_external_pmc(INTERP, enum_class_Integer);
VTABLE_set_integer_native(INTERP, rows, attrs->rows);
return rows;
}
else if (Parrot_str_equal(INTERP, idx, CONST_STRING(INTERP, "cols"))) {
PMC * const cols = Parrot_pmc_new(INTERP, enum_class_Integer);
PMC * const cols = get_external_pmc(INTERP, enum_class_Integer);
VTABLE_set_integer_native(INTERP, cols, attrs->cols);
return cols;
}
else if (Parrot_str_equal(INTERP, idx, CONST_STRING(INTERP, "size"))) {
PMC * const size = Parrot_pmc_new(INTERP, enum_class_Integer);
PMC * const size = get_external_pmc(INTERP, enum_class_Integer);
VTABLE_set_integer_native(INTERP, size, attrs->cols * attrs->rows);
return size;
}
Expand Down
48 changes: 38 additions & 10 deletions t/harness
Expand Up @@ -19,10 +19,14 @@ sub MAIN () {
my $failed_files := 0;
our $max_length;
$max_length := 30;
my @files := get_all_tests("t", "t/pmc",
"t/methods/nummatrix2d",
"t/methods/complexmatrix2d",
"t/methods/pmcmatrix2d");
my @files := get_all_tests(
't',
't/pmc',
't/methods/nummatrix2d',
't/methods/complexmatrix2d',
't/methods/pmcmatrix2d',
#'t/pir-subclass'
);
my %failures := {};

for @files {
Expand All @@ -32,7 +36,7 @@ sub MAIN () {
%failures{$filename} := [];

my $test_output := run_test($filename);
my $plan := $test_output[0];
my $plan := $test_output[0];
my @plan_parts := $plan.split('..');
my $num_tests := @plan_parts[1];
my $curr_test := 0;
Expand All @@ -43,9 +47,7 @@ sub MAIN () {

for $test_output {
my $line := $_;

if ( $line ) {

my $line_parts := $line.split("ok ");
my $right_side := $line_parts[1];
my $right_side_parts := $right_side.split(' ');
Expand Down Expand Up @@ -143,13 +145,31 @@ sub print_filename($filename, $max_length) {
}

sub run_test($filename) {
my $sub := Nqp::compile_file($filename);
my $sub;
my $pirfile := is_pir_test($filename);
if $pirfile == 0 {
$sub := Nqp::compile_file($filename);
$sub := $sub[0];
} else {
Q:PIR {
$P1 = find_lex "$filename"
$P0 = new ['FileHandle']
$P0.'open'($P1)
$P2 = $P0.'readall'()
$P0.'close'()
$P3 = compreg 'PIR'
$P4 = $P3($P2)
$P4 = $P4[0]
store_lex '$sub', $P4
};
}
my $stdout := Parrot::new("StringHandle");
$stdout.open("blah", "rw");
my %save_handles := Program::swap_handles(:stdout($stdout), :stderr($stdout));
$sub[0]();
$sub();
Program::swap_handles(|%save_handles);
return ($stdout.readall().split("\n"));
my $result := $stdout.readall();
return ($result.split("\n"));
}

sub reset_test_environment() {
Expand All @@ -161,3 +181,11 @@ sub reset_test_environment() {
set_hll_global [ 'Test'; 'Builder'; '_singleton' ], 'singleton', $P0
};
}

sub is_pir_test($filename) {
my $idx := pir::index__ISS($filename, 't/pir');
if $idx == 0 {
return 1;
}
return 0;
}

0 comments on commit cfcbcb1

Please sign in to comment.