NAME ^

src/pmc/APLVector.pmc - APLVector

DESCRIPTION ^

These are the vtable functions for the APL Vector class.

Helper functions ^

INTVAL size_of_shape(INTERP, PMC)

*/

#include "parrot/parrot.h"

static INTVAL size_of_shape(Interp *interp, PMC* self, PMC* shape) { INTVAL retval; INTVAL dimension; INTVAL length; INTVAL pos;

    if (!shape || PMC_IS_NULL(shape)) {
        /* not set, so a simple 1D */
        return VTABLE_get_integer(interp, self);
    }

    retval = 1;
    dimension = VTABLE_get_integer(interp, shape);
    for (pos = 0; pos < dimension; pos++)
    {
        length = VTABLE_get_integer_keyed_int(interp, shape, pos);
        retval *= length;
    }
    return retval;
}
/*

Methods ^

void class_init()

initialize the pmc class. Store some constants, etc.

PMC *init()

initialize the instance.

PMC *get_shape()

Returns a vector-like PMC containing the shape of this PMC.

PMC *set_shape()

Reshape the existing APLvector by passing in an existing vector.

If the new shape is larger than our old shape, pad the end of the APLv with elements from the beginning.

If the new shape is shorter than our old shape, truncate elements from the end of the APLv.


parrot