Skip to content

Commit

Permalink
pmc: convert Fixed*Array and Resizable*Array internal_exceptions to r…
Browse files Browse the repository at this point in the history
…eal_exceptions

git-svn-id: https://svn.parrot.org/parrot/trunk@11610 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
particle committed Feb 17, 2006
1 parent cb9c882 commit 7298186
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 92 deletions.
20 changes: 10 additions & 10 deletions src/pmc/fixedbooleanarray.pmc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ The C<FixedBooleanArray PMC> is extended by the C<ResizableBooleanArray PMC>.


static void static void
booleanarray_init(Interp *interpreter, PMC *self) { booleanarray_init(Interp *interpreter, PMC *self) {
PMC_int_val2(self) = 0; PMC_int_val2(self) = 0;
PMC_data(self) = NULL; PMC_data(self) = NULL;
} }


Expand All @@ -47,11 +47,11 @@ booleanarray_clone(Interp *interpreter, PMC *self, PMC *dest) {


static void static void
booleanarray_clear(Interp *interpreter, PMC *self) { booleanarray_clear(Interp *interpreter, PMC *self) {
PMC_int_val2(self) = 0; PMC_int_val2(self) = 0;
} }


pmclass FixedBooleanArray need_ext does array { pmclass FixedBooleanArray need_ext does array {

/* /*


=back =back
Expand Down Expand Up @@ -121,7 +121,7 @@ Creates and returns a copy of the array.
PMC* clone () { PMC* clone () {
PMC * dest = pmc_new(INTERP, SELF->vtable->base_type); PMC * dest = pmc_new(INTERP, SELF->vtable->base_type);
PMC_int_val(dest) = PMC_int_val(SELF); PMC_int_val(dest) = PMC_int_val(SELF);

booleanarray_clone(INTERP, SELF, dest); booleanarray_clone(INTERP, SELF, dest);
PObj_active_destroy_SET(dest); PObj_active_destroy_SET(dest);
return dest; return dest;
Expand Down Expand Up @@ -182,9 +182,9 @@ Returns the integer value of the element at index C<key>.
Parrot_UInt1 *sd = PMC_data(SELF); Parrot_UInt1 *sd = PMC_data(SELF);


if (key < 0 || key >= PMC_int_val(SELF)) if (key < 0 || key >= PMC_int_val(SELF))
internal_exception(OUT_OF_BOUNDS, real_exception(INTERP, NULL, E_IndexError,
"FixedBooleanArray: index out of bounds!"); "FixedBooleanArray: index out of bounds!");

return ( sd[key/BITS_PER_CHAR] & ( 1 << ( key % BITS_PER_CHAR ) )) ? 1 : 0; return ( sd[key/BITS_PER_CHAR] & ( 1 << ( key % BITS_PER_CHAR ) )) ? 1 : 0;
} }


Expand Down Expand Up @@ -309,7 +309,8 @@ Resizes the array to C<size> elements.


void set_integer_native (INTVAL size) { void set_integer_native (INTVAL size) {
if (PMC_int_val(SELF) || size < 1) if (PMC_int_val(SELF) || size < 1)
internal_exception(OUT_OF_BOUNDS, "FixedBooleanArray: Can't resize!"); real_exception(INTERP, NULL, E_IndexError,
"FixedBooleanArray: Can't resize!");


PMC_int_val(SELF) = size; PMC_int_val(SELF) = size;
PMC_int_val2(SELF) = (size / BITS_PER_CHAR + 1) * BITS_PER_CHAR; PMC_int_val2(SELF) = (size / BITS_PER_CHAR + 1) * BITS_PER_CHAR;
Expand All @@ -330,7 +331,7 @@ Sets the integer value of the element at index C<key> to C<value>.
Parrot_UInt1 *sd = PMC_data(SELF); Parrot_UInt1 *sd = PMC_data(SELF);


if (key < 0 || key >= PMC_int_val(SELF)) if (key < 0 || key >= PMC_int_val(SELF))
internal_exception(OUT_OF_BOUNDS, real_exception(INTERP, NULL, E_IndexError,
"FixedBooleanArray: index out of bounds!"); "FixedBooleanArray: index out of bounds!");


if ( value ) { if ( value ) {
Expand Down Expand Up @@ -385,7 +386,7 @@ C<value>.
INTVAL k = key_integer(INTERP, key); INTVAL k = key_integer(INTERP, key);
DYNSELF.set_number_keyed_int(k, value); DYNSELF.set_number_keyed_int(k, value);
} }

/* /*


=item C<void set_string_keyed_int(INTVAL key, STRING *value)> =item C<void set_string_keyed_int(INTVAL key, STRING *value)>
Expand Down Expand Up @@ -528,7 +529,6 @@ sets them all to false.


*/ */



METHOD void fill(INTVAL fill) { METHOD void fill(INTVAL fill) {
Parrot_UInt1 *sd = PMC_data(SELF); Parrot_UInt1 *sd = PMC_data(SELF);
INTVAL j; INTVAL j;
Expand Down
17 changes: 9 additions & 8 deletions src/pmc/fixedfloatarray.pmc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ it uses Float PMCs to do all necessary conversions
#include "parrot/parrot.h" #include "parrot/parrot.h"


pmclass FixedFloatArray need_ext does array { pmclass FixedFloatArray need_ext does array {

/* /*


=back =back
Expand Down Expand Up @@ -89,12 +89,12 @@ Creates and returns a copy of the array.
PMC* clone () { PMC* clone () {
INTVAL size; INTVAL size;
PMC * dest = pmc_new(INTERP, SELF->vtable->base_type); PMC * dest = pmc_new(INTERP, SELF->vtable->base_type);

if (!PMC_data(SELF)) if (!PMC_data(SELF))
return dest; return dest;
size = PMC_int_val(SELF); size = PMC_int_val(SELF);
PMC_int_val(dest) = size; PMC_int_val(dest) = size;

PMC_data(dest) = mem_sys_allocate(size * sizeof(FLOATVAL)); PMC_data(dest) = mem_sys_allocate(size * sizeof(FLOATVAL));
mem_sys_memcopy(PMC_data(dest), PMC_data(SELF), size*sizeof(FLOATVAL)); mem_sys_memcopy(PMC_data(dest), PMC_data(SELF), size*sizeof(FLOATVAL));
PObj_active_destroy_SET(dest); PObj_active_destroy_SET(dest);
Expand Down Expand Up @@ -187,9 +187,9 @@ Returns the floating-point value of the element at index C<key>.
FLOATVAL get_number_keyed_int (INTVAL key) { FLOATVAL get_number_keyed_int (INTVAL key) {
FLOATVAL *data; FLOATVAL *data;
if (key < 0 || key >= PMC_int_val(SELF)) if (key < 0 || key >= PMC_int_val(SELF))
internal_exception(OUT_OF_BOUNDS, real_exception(INTERP, NULL, E_IndexError,
"FixedFloatArray: index out of bounds!"); "FixedFloatArray: index out of bounds!");

data = (FLOATVAL *)PMC_data(SELF); data = (FLOATVAL *)PMC_data(SELF);
return data[key]; return data[key];
} }
Expand Down Expand Up @@ -288,7 +288,8 @@ Resizes the array to C<size> elements.


void set_integer_native (INTVAL size) { void set_integer_native (INTVAL size) {
if (PMC_int_val(SELF) || size < 1) if (PMC_int_val(SELF) || size < 1)
internal_exception(OUT_OF_BOUNDS, "FixedFloatArray: Can't resize!"); real_exception(INTERP, NULL, E_IndexError,
"FixedFloatArray: Can't resize!");
PMC_int_val(SELF) = size; PMC_int_val(SELF) = size;
PMC_data(SELF) = mem_sys_allocate(size * sizeof(FLOATVAL)); PMC_data(SELF) = mem_sys_allocate(size * sizeof(FLOATVAL));
PObj_active_destroy_SET(SELF); PObj_active_destroy_SET(SELF);
Expand Down Expand Up @@ -338,7 +339,7 @@ C<value>.
void set_number_keyed_int (INTVAL key, FLOATVAL value) { void set_number_keyed_int (INTVAL key, FLOATVAL value) {
FLOATVAL *data; FLOATVAL *data;
if (key < 0 || key >= PMC_int_val(SELF)) if (key < 0 || key >= PMC_int_val(SELF))
internal_exception(OUT_OF_BOUNDS, real_exception(INTERP, NULL, E_IndexError,
"FixedFloatArray: index out of bounds!"); "FixedFloatArray: index out of bounds!");


data = (FLOATVAL*)PMC_data(SELF); data = (FLOATVAL*)PMC_data(SELF);
Expand All @@ -361,7 +362,7 @@ C<value>.
k = key_integer(INTERP, key); k = key_integer(INTERP, key);
DYNSELF.set_number_keyed_int(k, value); DYNSELF.set_number_keyed_int(k, value);
} }

/* /*


=item C<void set_string_keyed_int(INTVAL key, STRING *value)> =item C<void set_string_keyed_int(INTVAL key, STRING *value)>
Expand Down
2 changes: 1 addition & 1 deletion src/pmc/fixedintegerarray.pmc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ Resizes the array to C<size> elements.


void set_integer_native (INTVAL size) { void set_integer_native (INTVAL size) {
if (PMC_int_val(SELF) || size < 1) if (PMC_int_val(SELF) || size < 1)
internal_exception(OUT_OF_BOUNDS, real_exception(INTERP, NULL, E_IndexError,
"FixedIntegerArray: Can't resize!"); "FixedIntegerArray: Can't resize!");
PMC_int_val(SELF) = size; PMC_int_val(SELF) = size;
PMC_data(SELF) = mem_sys_allocate_zeroed(size * sizeof(INTVAL)); PMC_data(SELF) = mem_sys_allocate_zeroed(size * sizeof(INTVAL));
Expand Down
7 changes: 4 additions & 3 deletions src/pmc/fixedstringarray.pmc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ Returns the Parrot string value of the element at index C<key>.
STRING* get_string_keyed_int (INTVAL key) { STRING* get_string_keyed_int (INTVAL key) {
STRING **data; STRING **data;
if (key < 0 || key >= PMC_int_val(SELF)) if (key < 0 || key >= PMC_int_val(SELF))
internal_exception(OUT_OF_BOUNDS, real_exception(INTERP, NULL, E_IndexError,
"FixedStringArray: index out of bounds!"); "FixedStringArray: index out of bounds!");


data = (STRING **)PMC_data(SELF); data = (STRING **)PMC_data(SELF);
Expand Down Expand Up @@ -318,7 +318,8 @@ cause an exception to be thrown.


void set_integer_native (INTVAL size) { void set_integer_native (INTVAL size) {
if (PMC_int_val(SELF) || size < 1) if (PMC_int_val(SELF) || size < 1)
internal_exception(OUT_OF_BOUNDS, "FixedStringArray: Can't resize!"); real_exception(INTERP, NULL, E_IndexError,
"FixedStringArray: Can't resize!");
PMC_int_val(SELF) = size; PMC_int_val(SELF) = size;
PMC_data(SELF) = mem_sys_allocate_zeroed(size * sizeof(STRING*)); PMC_data(SELF) = mem_sys_allocate_zeroed(size * sizeof(STRING*));
PObj_custom_mark_destroy_SETALL(SELF); PObj_custom_mark_destroy_SETALL(SELF);
Expand Down Expand Up @@ -411,7 +412,7 @@ Sets the Parrot string value of the element at index C<key> to C<value>.
void set_string_keyed_int (INTVAL key, STRING* value) { void set_string_keyed_int (INTVAL key, STRING* value) {
STRING **data; STRING **data;
if (key < 0 || key >= PMC_int_val(SELF)) if (key < 0 || key >= PMC_int_val(SELF))
internal_exception(OUT_OF_BOUNDS, real_exception(INTERP, NULL, E_IndexError,
"FixedStringArray: index out of bounds!"); "FixedStringArray: index out of bounds!");


data = (STRING**)PMC_data(SELF); data = (STRING**)PMC_data(SELF);
Expand Down
4 changes: 2 additions & 2 deletions src/pmc/resizablefloatarray.pmc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ which stores FLOATVALs. It uses Float PMCs to do all necessary conversions.
#include "parrot/parrot.h" #include "parrot/parrot.h"


pmclass ResizableFloatArray extends FixedFloatArray need_ext does array { pmclass ResizableFloatArray extends FixedFloatArray need_ext does array {



/* /*


Expand All @@ -42,7 +42,7 @@ Returns the floating-point value of the element at index C<key>.
"ResizableFloatArray: index out of bounds!"); "ResizableFloatArray: index out of bounds!");
if (key >= PMC_int_val(SELF)) if (key >= PMC_int_val(SELF))
DYNSELF.set_integer_native(key+1); DYNSELF.set_integer_native(key+1);

data = (FLOATVAL *)PMC_data(SELF); data = (FLOATVAL *)PMC_data(SELF);
return data[key]; return data[key];
} }
Expand Down
8 changes: 4 additions & 4 deletions src/pmc/resizableintegerarray.pmc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Returns the integer value of the element at index C<key>.
INTVAL get_integer_keyed_int (INTVAL key) { INTVAL get_integer_keyed_int (INTVAL key) {
INTVAL *data; INTVAL *data;
if (key < 0) if (key < 0)
internal_exception(OUT_OF_BOUNDS, real_exception(INTERP, NULL, E_IndexError,
"ResizableIntegerArray: index out of bounds!"); "ResizableIntegerArray: index out of bounds!");
if(key >= PMC_int_val(SELF)) if(key >= PMC_int_val(SELF))
DYNSELF.set_integer_native(key+1); DYNSELF.set_integer_native(key+1);
Expand All @@ -59,7 +59,7 @@ Sets the integer value of the element at index C<key> to C<value>.
void set_integer_keyed_int (INTVAL key, INTVAL value) { void set_integer_keyed_int (INTVAL key, INTVAL value) {
INTVAL *data; INTVAL *data;
if (key < 0) if (key < 0)
internal_exception(OUT_OF_BOUNDS, real_exception(INTERP, NULL, E_IndexError,
"ResizableIntegerArray: index out of bounds!"); "ResizableIntegerArray: index out of bounds!");
if(key >= PMC_int_val(SELF)) if(key >= PMC_int_val(SELF))
DYNSELF.set_integer_native(key+1); DYNSELF.set_integer_native(key+1);
Expand All @@ -80,7 +80,7 @@ Resizes the array to C<size> elements.


void set_integer_native (INTVAL size) { void set_integer_native (INTVAL size) {
if (size < 0) if (size < 0)
internal_exception(OUT_OF_BOUNDS, real_exception(INTERP, NULL, E_IndexError,
"ResizableStringArray: Can't resize!"); "ResizableStringArray: Can't resize!");


if(!PMC_data(SELF)) { if(!PMC_data(SELF)) {
Expand Down Expand Up @@ -149,7 +149,7 @@ Removes and returns the last element in the array.


size = PMC_int_val(SELF); size = PMC_int_val(SELF);
if (size == 0) { if (size == 0) {
internal_exception(OUT_OF_BOUNDS, real_exception(INTERP, NULL, E_IndexError,
"ResizableIntegerArray: Can't pop from an empty array!"); "ResizableIntegerArray: Can't pop from an empty array!");
} }
value = DYNSELF.get_integer_keyed_int(size-1); value = DYNSELF.get_integer_keyed_int(size-1);
Expand Down
26 changes: 13 additions & 13 deletions src/pmc/resizablepmcarray.pmc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Resizes the array to C<size> elements.
void set_integer_native (INTVAL size) { void set_integer_native (INTVAL size) {


if (size < 0) if (size < 0)
internal_exception(OUT_OF_BOUNDS, real_exception(INTERP, NULL, E_IndexError,
"ResizablePMCArray: Can't resize!"); "ResizablePMCArray: Can't resize!");


if (!PMC_data(SELF)) { if (!PMC_data(SELF)) {
Expand Down Expand Up @@ -104,7 +104,7 @@ TODO: Check whether there is already an element that can be shifted
FLOATVAL value; FLOATVAL value;


if (0 == size) { if (0 == size) {
internal_exception(OUT_OF_BOUNDS, real_exception(INTERP, NULL, E_IndexError,
"ResizablePMCArray: Can't shift from an empty array!"); "ResizablePMCArray: Can't shift from an empty array!");
} }


Expand All @@ -126,7 +126,7 @@ TODO: Check whether there is already an element that can be shifted
INTVAL value; INTVAL value;


if (0 == size) { if (0 == size) {
internal_exception(OUT_OF_BOUNDS, real_exception(INTERP, NULL, E_IndexError,
"ResizablePMCArray: Can't shift from an empty array!"); "ResizablePMCArray: Can't shift from an empty array!");
} }


Expand All @@ -147,13 +147,13 @@ TODO: Check whether there is already an element that can be shifted
PMC** item; PMC** item;


if (0 == size) { if (0 == size) {
internal_exception(OUT_OF_BOUNDS, real_exception(INTERP, NULL, E_IndexError,
"ResizablePMCArray: Can't shift from an empty array!"); "ResizablePMCArray: Can't shift from an empty array!");
} }


data= ((PMC**)PMC_data(SELF))[0]; data= ((PMC**)PMC_data(SELF))[0];
PMC_int_val(SELF)= --size; PMC_int_val(SELF)= --size;

item= (PMC**)PMC_data(SELF); item= (PMC**)PMC_data(SELF);
mem_sys_memmove(item, item + 1, size * sizeof(PMC*)); mem_sys_memmove(item, item + 1, size * sizeof(PMC*));
item[size]= PMCNULL; item[size]= PMCNULL;
Expand All @@ -168,7 +168,7 @@ TODO: Check whether there is already an element that can be shifted
STRING* value; STRING* value;


if (0 == size) { if (0 == size) {
internal_exception(OUT_OF_BOUNDS, real_exception(INTERP, NULL, E_IndexError,
"ResizablePMCArray: Can't shift from an empty array!"); "ResizablePMCArray: Can't shift from an empty array!");
} }


Expand Down Expand Up @@ -200,7 +200,7 @@ Returns the PMC value of the element at index C<key>.
if (key < 0) if (key < 0)
key += PMC_int_val(SELF); key += PMC_int_val(SELF);
if (key < 0) if (key < 0)
internal_exception(OUT_OF_BOUNDS, real_exception(INTERP, NULL, E_IndexError,
"ResizablePMCArray: index out of bounds!"); "ResizablePMCArray: index out of bounds!");
if (key >= PMC_int_val(SELF)) if (key >= PMC_int_val(SELF))
DYNSELF.set_integer_native(key+1); DYNSELF.set_integer_native(key+1);
Expand Down Expand Up @@ -233,7 +233,7 @@ If key is a slice, do a splice as set that item.
if (key < 0) if (key < 0)
key += PMC_int_val(SELF); key += PMC_int_val(SELF);
if (key < 0) if (key < 0)
internal_exception(OUT_OF_BOUNDS, real_exception(INTERP, NULL, E_IndexError,
"ResizablePMCArray: index out of bounds!"); "ResizablePMCArray: index out of bounds!");
if (key >= PMC_int_val(SELF)) if (key >= PMC_int_val(SELF))
DYNSELF.set_integer_native(key+1); DYNSELF.set_integer_native(key+1);
Expand Down Expand Up @@ -342,7 +342,7 @@ Removes and returns the last element in the array.
FLOATVAL value; FLOATVAL value;


if (0 == size) { if (0 == size) {
internal_exception(OUT_OF_BOUNDS, real_exception(INTERP, NULL, E_IndexError,
"ResizablePMCArray: Can't pop from an empty array!"); "ResizablePMCArray: Can't pop from an empty array!");
} }


Expand All @@ -359,7 +359,7 @@ Removes and returns the last element in the array.
INTVAL value; INTVAL value;


if (0 == size) { if (0 == size) {
internal_exception(OUT_OF_BOUNDS, real_exception(INTERP, NULL, E_IndexError,
"ResizablePMCArray: Can't pop from an empty array!"); "ResizablePMCArray: Can't pop from an empty array!");
} }


Expand All @@ -375,10 +375,10 @@ Removes and returns the last element in the array.
PMC* data; PMC* data;


if (0 == size) { if (0 == size) {
internal_exception(OUT_OF_BOUNDS, real_exception(INTERP, NULL, E_IndexError,
"ResizablePMCArray: Can't pop from an empty array!"); "ResizablePMCArray: Can't pop from an empty array!");
} }

data= ((PMC**)PMC_data(SELF))[--size]; data= ((PMC**)PMC_data(SELF))[--size];
PMC_int_val(SELF)= size; PMC_int_val(SELF)= size;
return data; return data;
Expand All @@ -390,7 +390,7 @@ Removes and returns the last element in the array.
STRING* value; STRING* value;


if (0 == size) { if (0 == size) {
internal_exception(OUT_OF_BOUNDS, real_exception(INTERP, NULL, E_IndexError,
"ResizablePMCArray: Can't pop from an empty array!"); "ResizablePMCArray: Can't pop from an empty array!");
} }


Expand Down
Loading

0 comments on commit 7298186

Please sign in to comment.