[svn:parrot] r37267 - trunk/src/pmc

cotto at svn.parrot.org cotto at svn.parrot.org
Tue Mar 10 10:01:15 UTC 2009


Author: cotto
Date: Tue Mar 10 10:01:14 2009
New Revision: 37267
URL: https://trac.parrot.org/parrot/changeset/37267

Log:
[PMC] switch Fixed- and ResizablePMCArray to ATTRs and remove a long-neglected Pod section

Modified:
   trunk/src/pmc/fixedpmcarray.pmc
   trunk/src/pmc/resizablepmcarray.pmc

Modified: trunk/src/pmc/fixedpmcarray.pmc
==============================================================================
--- trunk/src/pmc/fixedpmcarray.pmc	Tue Mar 10 09:33:28 2009	(r37266)
+++ trunk/src/pmc/fixedpmcarray.pmc	Tue Mar 10 10:01:14 2009	(r37267)
@@ -26,7 +26,12 @@
 
 #include "parrot/parrot.h"
 
+#define PMC_size(x)  ((Parrot_FixedPMCArray_attributes *)PMC_data(x))->size
+#define PMC_array(x) ((Parrot_FixedPMCArray_attributes *)PMC_data(x))->pmc_array
+
 pmclass FixedPMCArray need_ext provides array {
+    ATTR INTVAL   size;      /* number of elements in the array */
+    ATTR PMC    **pmc_array; /* pointer to PMC array */
 
 /*
 
@@ -39,10 +44,10 @@
 */
 
     METHOD sort(PMC *cmp_func :optional) {
-        const UINTVAL n = (UINTVAL) PMC_int_val(SELF);
+        const UINTVAL n = (UINTVAL) PMC_size(SELF);
 
         if (n > 1)
-           Parrot_quicksort(interp, PMC_data_typed(SELF, void **), n, cmp_func);
+           Parrot_quicksort(interp, (void **)PMC_array(SELF), n, cmp_func);
     }
 
 /*
@@ -62,10 +67,11 @@
 */
 
     VTABLE void init() {
-        PMC_int_val(SELF) = 0;
-        PMC_data(SELF)    = NULL;
-        PObj_active_destroy_SET(SELF);
-        PObj_custom_mark_SET(SELF);
+        Parrot_FixedPMCArray_attributes *attrs =
+            mem_allocate_zeroed_typed(Parrot_FixedPMCArray_attributes);
+
+        PMC_data(SELF) = attrs;
+        PObj_custom_mark_destroy_SETALL(SELF);
     }
 
 /*
@@ -79,11 +85,10 @@
 */
 
     VTABLE void destroy() {
-        if (PMC_data(SELF)) {
-            mem_sys_free(PMC_data(SELF));
-            PMC_data(SELF) = NULL;
+        if (PMC_array(SELF)) {
+            mem_sys_free(PMC_array(SELF));
         }
-        PMC_int_val(SELF) = 0;
+        mem_sys_free(PMC_data(SELF));
     }
 
 /*
@@ -98,13 +103,13 @@
 
     VTABLE PMC *clone() {
         PMC * const dest  = pmc_new(INTERP, SELF->vtable->base_type);
-        const INTVAL size = PMC_int_val(SELF);
+        const INTVAL size = PMC_size(SELF);
 
         if (size) {
-            PMC_int_val(dest) = size;
-            PMC_data(dest)    = mem_allocate_n_typed(size, PMC *);
-            mem_copy_n_typed(PMC_data(dest), PMC_data(SELF), size, PMC *);
-            PObj_custom_mark_SET(dest);
+            PMC_size(dest) = size;
+            PMC_array(dest)    = mem_allocate_n_typed(size, PMC *);
+            mem_copy_n_typed(PMC_array(dest), PMC_array(SELF), size, PMC *);
+            PObj_custom_mark_destroy_SETALL(dest);
         }
 
         return dest;
@@ -134,7 +139,7 @@
 */
 
     VTABLE INTVAL elements() {
-        return PMC_int_val(SELF);
+        return PMC_size(SELF);
     }
 
 /*
@@ -314,11 +319,11 @@
     VTABLE PMC *get_pmc_keyed_int(INTVAL key) {
         PMC **data;
 
-        if (key < 0 || key >= PMC_int_val(SELF))
+        if (key < 0 || key >= PMC_size(SELF))
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
                 _("FixedPMCArray: index out of bounds!"));
 
-        data = (PMC **)PMC_data(SELF);
+        data = PMC_array(SELF);
         return data[key];
     }
 
@@ -363,19 +368,19 @@
         int i;
         PMC **data;
 
-        if (PMC_int_val(SELF) && size)
+        if (PMC_size(SELF) && size)
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
                     _("FixedPMCArray: Can't resize!"));
         if (!size)
             return;
 
-        PMC_int_val(SELF) = size;
-        data              = mem_allocate_n_zeroed_typed(size, PMC *);
+        PMC_size(SELF) = size;
+        data           = mem_allocate_n_zeroed_typed(size, PMC *);
 
         for (i = 0; i < size; i++)
             data[i] = PMCNULL;
 
-        PMC_data(SELF) = data;
+        PMC_array(SELF) = data;
     }
 
     VTABLE void set_pmc(PMC *value) {
@@ -389,16 +394,16 @@
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
                     _("Can't set self from this type"));
 
-        if (PMC_data(SELF))
-            mem_sys_free(PMC_data(SELF));
+        if (PMC_array(SELF))
+            mem_sys_free(PMC_array(SELF));
 
-        size           = PMC_int_val(SELF) = VTABLE_elements(INTERP, value);
-        PMC_data(SELF) = mem_allocate_n_zeroed_typed(size, PMC *);
+        size            = PMC_size(SELF) = VTABLE_elements(INTERP, value);
+        PMC_array(SELF) = mem_allocate_n_zeroed_typed(size, PMC *);
 
         for (i = 0; i < size; i++)
-            ((PMC**)PMC_data(SELF))[i] = VTABLE_get_pmc_keyed_int(INTERP, value, i);
+            (PMC_array(SELF))[i] = VTABLE_get_pmc_keyed_int(INTERP, value, i);
 
-        PObj_custom_mark_SET(SELF);
+        PObj_custom_mark_destroy_SETALL(SELF);
     }
 /*
 
@@ -538,11 +543,11 @@
     VTABLE void set_pmc_keyed_int(INTVAL key, PMC *src) {
         PMC **data;
 
-        if (key < 0 || key >= PMC_int_val(SELF))
+        if (key < 0 || key >= PMC_size(SELF))
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
                 _("FixedPMCArray: index out of bounds!"));
 
-        data      = (PMC**)PMC_data(SELF);
+        data      = PMC_array(SELF);
         GC_WRITE_BARRIER(INTERP, SELF, data[key], src);
         data[key] = src;
     }
@@ -650,7 +655,7 @@
         Parrot_PCCINVOKE(interp, iter, name, "P->", key);
         PObj_get_FLAGS(key) |= KEY_integer_FLAG;
 
-        if (PMC_int_val(SELF) == 0)
+        if (PMC_size(SELF) == 0)
             VTABLE_set_integer_native(INTERP, key, -1);
         else
             VTABLE_set_integer_native(INTERP, key, 0);
@@ -671,11 +676,11 @@
 */
     VTABLE INTVAL exists_keyed_int(INTVAL key) {
         PMC **data;
-        if (key < 0 || key >= PMC_int_val(SELF))
+        if (key < 0 || key >= PMC_size(SELF))
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
                 _("FixedPMCArray: index out of bounds!"));
 
-        data = (PMC**)PMC_data(SELF);
+        data = PMC_array(SELF);
         return !PMC_IS_NULL(data[key]);
     }
 
@@ -701,7 +706,7 @@
 */
 
     void splice(PMC *value, INTVAL offset, INTVAL count) {
-        if (count + offset > PMC_int_val(SELF))
+        if (count + offset > PMC_size(SELF))
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
                 _("FixedPMCArray: index out of bounds!"));
 
@@ -734,7 +739,7 @@
     VTABLE void visit(visit_info *info) {
         INTVAL  i;
         const INTVAL n = VTABLE_elements(INTERP, SELF);
-        PMC   **pos    = (PMC **)PMC_data(SELF);
+        PMC   **pos    = PMC_array(SELF);
 
         for (i = 0; i < n; ++i, ++pos) {
             info->thaw_ptr = pos;
@@ -787,13 +792,13 @@
 */
 
     VTABLE void mark() {
-        PMC ** const data = PMC_data_typed(SELF, PMC **);
+        PMC ** const data = PMC_array(SELF);
         INTVAL i;
 
         if (!data)
             return;
 
-        for (i = PMC_int_val(SELF) - 1; i >= 0; --i)
+        for (i = PMC_size(SELF) - 1; i >= 0; --i)
             if (data[i])
                 pobject_lives(interp, (PObj *)data[i]);
     }

Modified: trunk/src/pmc/resizablepmcarray.pmc
==============================================================================
--- trunk/src/pmc/resizablepmcarray.pmc	Tue Mar 10 09:33:28 2009	(r37266)
+++ trunk/src/pmc/resizablepmcarray.pmc	Tue Mar 10 10:01:14 2009	(r37267)
@@ -21,8 +21,30 @@
 
 #include "parrot/parrot.h"
 
+#define PMC_size(x)      ((Parrot_ResizablePMCArray_attributes *)PMC_data(x))->size
+#define PMC_array(x)     ((Parrot_ResizablePMCArray_attributes *)PMC_data(x))->pmc_array
+#define PMC_threshold(x) ((Parrot_ResizablePMCArray_attributes *)PMC_data(x))->resize_threshold
 
 pmclass ResizablePMCArray extends FixedPMCArray need_ext provides array {
+    ATTR INTVAL resize_threshold; /* max size before array needs resizing */
+
+
+/*
+=item C<void init()>
+
+Initializes the array.
+
+=cut
+
+*/
+
+    VTABLE void init() {
+        Parrot_ResizablePMCArray_attributes *attrs =
+            mem_allocate_zeroed_typed(Parrot_ResizablePMCArray_attributes);
+
+        PMC_data(SELF) = attrs;
+        PObj_custom_mark_destroy_SETALL(SELF);
+    }
 
 /*
 
@@ -39,26 +61,31 @@
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
                     "ResizablePMCArray: Can't resize!");
 
-        if (!PMC_data(SELF)) {
+        if (!PMC_array(SELF)) {
             /* empty - used fixed routine */
             if (size < 8) {
+
                 SUPER(8);
-                PMC_int_val(SELF)  = size;
-                PMC_int_val2(SELF) = 8;
+                PMC_size(SELF)      = size;
+                PMC_threshold(SELF) = 8;
+
             }
             else {
+
                 SUPER(size);
-                PMC_int_val2(SELF) = size;
+                PMC_threshold(SELF) = size;
             }
         }
-        else if (size <= PMC_int_val2(SELF)) {
-            PMC_int_val(SELF) = size;
+        else if (size <= PMC_threshold(SELF)) {
+
+            PMC_size(SELF) = size;
             /* we could shrink here if necessary */
             return;
         }
         else {
+
             INTVAL i, cur, needed;
-            i = cur = PMC_int_val2(SELF);
+            i = cur = PMC_threshold(SELF);
             if (cur < 8192)
                 cur = size < 2 * cur ? 2 * cur : size;
             else {
@@ -67,14 +94,15 @@
                 cur   &= ~0xfff;
             }
 
-            PMC_data(SELF) = mem_sys_realloc(PMC_data(SELF),
+            PMC_array(SELF) = (PMC **)mem_sys_realloc(PMC_array(SELF),
                     cur * sizeof (PMC *));
 
-            for (; i < cur; i++)
-                ((PMC **)PMC_data(SELF))[i] = PMCNULL;
+            for (; i < cur; i++) {
+                (PMC_array(SELF))[i] = PMCNULL;
+            }
 
-            PMC_int_val2(SELF) = cur;
-            PMC_int_val(SELF)  = size;
+            PMC_threshold(SELF) = cur;
+            PMC_size(SELF)      = size;
         }
     }
 
@@ -98,7 +126,7 @@
 */
 
     VTABLE FLOATVAL shift_float() {
-        INTVAL    size = PMC_int_val(SELF);
+        INTVAL    size = PMC_size(SELF);
         PMC      *data;
         PMC     **item;
         FLOATVAL  value;
@@ -107,20 +135,20 @@
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
                     "ResizablePMCArray: Can't shift from an empty array!");
 
-        item              = (PMC  **)PMC_data(SELF);
-        data              = item[0];
-        value             = VTABLE_get_number(INTERP, data);
-        PMC_int_val(SELF) = --size;
+        item           = PMC_array(SELF);
+        data           = item[0];
+        value          = VTABLE_get_number(INTERP, data);
+        PMC_size(SELF) = --size;
 
         mem_sys_memmove(item, item + 1, size * sizeof (PMC *));
 
-        item[size]        = PMCNULL;
+        item[size] = PMCNULL;
 
         return value;
     }
 
     VTABLE INTVAL shift_integer() {
-        INTVAL    size = PMC_int_val(SELF);
+        INTVAL    size = PMC_size(SELF);
         PMC      *data;
         PMC     **item;
         INTVAL    value;
@@ -129,19 +157,19 @@
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
                     "ResizablePMCArray: Can't shift from an empty array!");
 
-        item              = (PMC **)PMC_data(SELF);
-        data              = item[0];
-        value             = VTABLE_get_integer(INTERP, data);
-        PMC_int_val(SELF) = --size;
+        item           = PMC_array(SELF);
+        data           = item[0];
+        value          = VTABLE_get_integer(INTERP, data);
+        PMC_size(SELF) = --size;
 
         mem_sys_memmove(item, item + 1, size * sizeof (PMC*));
-        item[size]        = PMCNULL;
+        item[size] = PMCNULL;
 
         return value;
     }
 
     VTABLE PMC *shift_pmc() {
-        INTVAL  size = PMC_int_val(SELF);
+        INTVAL  size = PMC_size(SELF);
         PMC    *data;
         PMC   **item;
 
@@ -149,18 +177,18 @@
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
                     "ResizablePMCArray: Can't shift from an empty array!");
 
-        item              = (PMC **)PMC_data(SELF);
-        data              = item[0];
-        PMC_int_val(SELF) = --size;
+        item           = PMC_array(SELF);
+        data           = item[0];
+        PMC_size(SELF) = --size;
 
         mem_sys_memmove(item, item + 1, size * sizeof (PMC *));
-        item[size]        = PMCNULL;
+        item[size] = PMCNULL;
 
         return data;
     }
 
     VTABLE STRING *shift_string() {
-        INTVAL   size = PMC_int_val(SELF);
+        INTVAL   size = PMC_size(SELF);
         PMC     *data;
         PMC    **item;
         STRING  *value;
@@ -169,14 +197,14 @@
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
                     "ResizablePMCArray: Can't shift from an empty array!");
 
-        item              = (PMC **)PMC_data(SELF);
-        data              = item[0];
-        value             = VTABLE_get_string(INTERP, data);
-        PMC_int_val(SELF) = --size;
+        item           = PMC_array(SELF);
+        data           = item[0];
+        value          = VTABLE_get_string(INTERP, data);
+        PMC_size(SELF) = --size;
 
         mem_sys_memmove(item, item + 1, size * sizeof (PMC *));
 
-        item[size]        = PMCNULL;
+        item[size] = PMCNULL;
 
         return value;
     }
@@ -196,16 +224,16 @@
         PMC **data;
 
         if (key < 0)
-            key += PMC_int_val(SELF);
+            key += PMC_size(SELF);
 
         if (key < 0)
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
                 "ResizablePMCArray: index out of bounds!");
 
-        if (key >= PMC_int_val(SELF))
+        if (key >= PMC_size(SELF))
             return PMCNULL;
 
-        data = PMC_data_typed(SELF, PMC **);
+        data = PMC_array(SELF);
 
         if (PMC_IS_NULL(data[key]))
             return PMCNULL;
@@ -231,16 +259,16 @@
         PMC **data;
 
         if (key < 0)
-            key += PMC_int_val(SELF);
+            key += PMC_size(SELF);
 
         if (key < 0)
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
                 "ResizablePMCArray: index out of bounds!");
 
-        if (key >= PMC_int_val(SELF))
+        if (key >= PMC_size(SELF))
             SELF.set_integer_native(key+1);
 
-        data      = (PMC **)PMC_data(SELF);
+        data      = PMC_array(SELF);
         GC_WRITE_BARRIER(INTERP, SELF, data[key], src);
         data[key] = src;
     }
@@ -252,13 +280,14 @@
     VTABLE void delete_keyed(PMC *key) {
         INTVAL  i;
         INTVAL  idx  = key_integer(INTERP, key);
-        INTVAL  n    = PMC_int_val(SELF);
-        PMC   **data = PMC_data_typed(SELF, PMC **);
+        INTVAL  n    = PMC_size(SELF);
+        PMC   **data = PMC_array(SELF);
 
-        for (i = idx; i < n - 1; ++i)
+        for (i = idx; i < n - 1; ++i) {
             data[i] = data[i + 1];
+        }
 
-        PMC_int_val(SELF)--;
+        PMC_size(SELF)--;
     }
 
 /*
@@ -276,12 +305,12 @@
         PMC **data;
 
         if (key < 0)
-            key += PMC_int_val(SELF);
+            key += PMC_size(SELF);
 
-        if (key < 0 || key >= PMC_int_val(SELF))
+        if (key < 0 || key >= PMC_size(SELF))
             return 0;
 
-        data = (PMC **)PMC_data(SELF);
+        data = PMC_array(SELF);
         return !PMC_IS_NULL(data[key]);
     }
 
@@ -304,9 +333,9 @@
         PMC *val;
 
         if (key < 0)
-            key += PMC_int_val(SELF);
+            key += PMC_size(SELF);
 
-        if (key < 0 || key >= PMC_int_val(SELF))
+        if (key < 0 || key >= PMC_size(SELF))
             return 0;
 
         val = SELF.get_pmc_keyed_int(key);
@@ -335,46 +364,42 @@
 */
 
     VTABLE void push_float(FLOATVAL value) {
-        INTVAL size = PMC_int_val(SELF);
+
+        INTVAL size = PMC_size(SELF);
         PMC   *val  = pmc_new(INTERP, enum_class_Float);
 
         VTABLE_set_number_native(INTERP, val, value);
-
-        /* let set_pmc_keyed_int() worry about memory allocation */
         SELF.set_pmc_keyed_int(size, val);
 
         return;
     }
 
     VTABLE void push_integer(INTVAL value) {
-        INTVAL size = PMC_int_val(SELF);
+
+        INTVAL size = PMC_size(SELF);
         PMC   *val  = pmc_new(INTERP, enum_class_Integer);
 
         VTABLE_set_integer_native(INTERP, val, value);
-
-        /* let set_pmc_keyed_int() worry about memory allocation */
         SELF.set_pmc_keyed_int(size, val);
 
         return;
     }
 
     void push_pmc(PMC *value) {
-        INTVAL size = PMC_int_val(SELF);
 
-        /* let set_integer_native() worry about memory allocation */
+        INTVAL size = PMC_size(SELF);
         SELF.set_integer_native(size + 1);
-        ((PMC **)PMC_data(SELF))[size] = value;
+        ((PMC **)PMC_array(SELF))[size] = value;
 
         return;
     }
 
     VTABLE void push_string(STRING *value) {
-        INTVAL size = PMC_int_val(SELF);
+
+        INTVAL size = PMC_size(SELF);
         PMC   *val  = pmc_new(INTERP, enum_class_String);
 
         VTABLE_assign_string_native(INTERP, val, value);
-
-        /* let set_pmc_keyed_int() worry about memory allocation */
         SELF.set_pmc_keyed_int(size, val);
 
         return;
@@ -397,57 +422,61 @@
 */
 
     VTABLE FLOATVAL pop_float() {
-        INTVAL   size = PMC_int_val(SELF);
+
+        INTVAL   size = PMC_size(SELF);
         PMC     *data;
 
         if (0 == size)
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
                     "ResizablePMCArray: Can't pop from an empty array!");
 
-        data              = ((PMC **)PMC_data(SELF))[--size];
-        PMC_int_val(SELF) = size;
+        data           = PMC_array(SELF)[--size];
+        PMC_size(SELF) = size;
 
         return VTABLE_get_number(INTERP, data);
     }
 
     VTABLE INTVAL pop_integer() {
-        INTVAL  size = PMC_int_val(SELF);
+
+        INTVAL  size = PMC_size(SELF);
         PMC    *data;
 
         if (0 == size)
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
                     "ResizablePMCArray: Can't pop from an empty array!");
 
-        data              = ((PMC **)PMC_data(SELF))[--size];
-        PMC_int_val(SELF) = size;
+        data           = PMC_array(SELF)[--size];
+        PMC_size(SELF) = size;
 
         return VTABLE_get_integer(INTERP, data);
     }
 
     VTABLE PMC *pop_pmc() {
-        INTVAL size = PMC_int_val(SELF);
+
+        INTVAL size = PMC_size(SELF);
         PMC   *data;
 
         if (0 == size)
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
                     "ResizablePMCArray: Can't pop from an empty array!");
 
-        data              = ((PMC **)PMC_data(SELF))[--size];
-        PMC_int_val(SELF) = size;
+        data           = PMC_array(SELF)[--size];
+        PMC_size(SELF) = size;
 
         return data;
     }
 
     VTABLE STRING *pop_string() {
-        INTVAL  size = PMC_int_val(SELF);
+
+        INTVAL  size = PMC_size(SELF);
         PMC    *data;
 
         if (0 == size)
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
                     "ResizablePMCArray: Can't pop from an empty array!");
 
-        data              = ((PMC **)PMC_data(SELF))[--size];
-        PMC_int_val(SELF) = size;
+        data           = PMC_array(SELF)[--size];
+        PMC_size(SELF) = size;
 
         return VTABLE_get_string(INTERP, data);
     }
@@ -470,18 +499,16 @@
 */
 
     VTABLE void unshift_float(FLOATVAL value) {
-        INTVAL  size = PMC_int_val(SELF);
+
+        INTVAL  size = PMC_size(SELF);
         PMC    *val  = pmc_new(INTERP, enum_class_Float);
         PMC   **data;
         INTVAL  i;
 
         VTABLE_set_number_native(INTERP, val, value);
-
-        /* let set_integer_native() worry about memory allocation */
         SELF.set_integer_native(size + 1);
 
-        /* make room */
-        data = (PMC **)PMC_data(SELF);
+        data = PMC_array(SELF);
 
         for (i = size; i; --i)
             data[i] = data[i - 1];
@@ -492,18 +519,16 @@
     }
 
     VTABLE void unshift_integer(INTVAL value) {
-        INTVAL  size = PMC_int_val(SELF);
+
+        INTVAL  size = PMC_size(SELF);
         PMC    *val  = pmc_new(INTERP, enum_class_Integer);
         PMC    **data;
         INTVAL   i;
 
         VTABLE_set_integer_native(INTERP, val, value);
-
-        /* let set_integer_native() worry about memory allocation */
         SELF.set_integer_native(size + 1);
 
-        /* make room */
-        data = (PMC **)PMC_data(SELF);
+        data = PMC_array(SELF);
 
         for (i = size; i; --i)
             data[i] = data[i - 1];
@@ -514,15 +539,14 @@
     }
 
     void unshift_pmc(PMC *value) {
-        INTVAL  size = PMC_int_val(SELF);
+
+        INTVAL  size = PMC_size(SELF);
         PMC   **data;
         INTVAL  i;
 
-        /* let set_integer_native() worry about memory allocation */
         SELF.set_integer_native(size + 1);
 
-        /* make room */
-        data = (PMC **)PMC_data(SELF);
+        data = PMC_array(SELF);
 
         for (i = size; i; --i)
             data[i] = data[i - 1];
@@ -533,18 +557,16 @@
     }
 
     VTABLE void unshift_string(STRING *value) {
-        INTVAL  size = PMC_int_val(SELF);
+
+        INTVAL  size = PMC_size(SELF);
         PMC    *val  = pmc_new(INTERP, enum_class_String);
         PMC   **data;
         INTVAL  i;
 
         VTABLE_set_string_native(INTERP, val, value);
-
-        /* let set_integer_native() worry about memory allocation */
         SELF.set_integer_native(size + 1);
 
-        /* make room */
-        data = (PMC **)PMC_data(SELF);
+        data = PMC_array(SELF);
 
         for (i = size; i; --i)
             data[i] = data[i - 1];
@@ -568,7 +590,7 @@
         PMC *copy = SUPER();
 
         /* copy trimmed extra space */
-        PMC_int_val2(copy) = PMC_int_val(SELF);
+        PMC_threshold(copy) = PMC_size(SELF);
 
         return copy;
     }
@@ -602,8 +624,9 @@
             if (item1 == item2)
                 continue;
 
-            Parrot_mmd_multi_dispatch_from_c_args(INTERP, "is_equal",
-                "PP->I", item1, item2, &result);
+            Parrot_mmd_multi_dispatch_from_c_args(INTERP,
+                    "is_equal", "PP->I", item1, item2, &result);
+
             if (!result)
                 return 0;
         }
@@ -622,6 +645,7 @@
 */
 
     METHOD append(PMC *other) {
+
         INTVAL i;
         INTVAL n = VTABLE_elements(INTERP, SELF);
         INTVAL m = VTABLE_elements(INTERP, other);
@@ -634,14 +658,14 @@
 
         if (other->vtable->base_type == SELF->vtable->base_type
         ||  other->vtable->base_type == enum_class_FixedPMCArray) {
-            PMC **other_data = PMC_data_typed(other, PMC **);
-            PMC **this_data  = PMC_data_typed(SELF, PMC **);
+            PMC **other_data = PMC_array(other);
+            PMC **this_data  = PMC_array(SELF);
 
             /* libc is faster at copying data than a manual loop here */
             memmove(this_data + n, other_data, m  * sizeof (PMC *));
         }
         else {
-            PMC **this_data = PMC_data_typed(SELF, PMC **);
+            PMC **this_data = PMC_array(SELF);
 
             for (i = 0; i < m; ++i)
                 this_data[n + i] = VTABLE_get_pmc_keyed_int(INTERP, other, i);
@@ -658,6 +682,7 @@
 */
 
     VTABLE STRING *get_repr() {
+
         INTVAL  j;
         INTVAL  n   = VTABLE_elements(INTERP, SELF);
         STRING *res = CONST_STRING(INTERP, "[ ");
@@ -690,6 +715,7 @@
 */
 
     void splice(PMC *value, INTVAL offset, INTVAL count) {
+
         const INTVAL length = VTABLE_elements(INTERP, SELF);
         const INTVAL elems  = VTABLE_elements(INTERP, value);
         INTVAL       shift  = elems - count;
@@ -778,15 +804,10 @@
 
 =back
 
-=head1 SEE ALSO
+=head1 See also
 
 F<docs/pdds/pdd17_basic_types.pod>.
 
-=head1 HISTORY
-
-Initial version                  - Matt Fowles 2004-06-11
-Changed allocator to double size - Matt Fowles 2004-06-15
-
 =cut
 
 */


More information about the parrot-commits mailing list