Author: cotto
Date: Tue Jan 27 04:25:07 2009
New Revision: 36053

Modified:
   trunk/compilers/imcc/pbc.c
   trunk/include/parrot/inter_call.h
   trunk/languages/perl6/src/pmc/perl6multisub.pmc
   trunk/src/inter_call.c
   trunk/src/multidispatch.c
   trunk/src/ops/core.ops
   trunk/src/pbc_merge.c
   trunk/src/pmc/fixedintegerarray.pmc
   trunk/src/pmc/resizableintegerarray.pmc
   trunk/src/pmc/string.pmc
   trunk/src/pmc/sub.pmc

Log:
[pmc] update *IntegerArray to use ATTRs


Modified: trunk/compilers/imcc/pbc.c
==============================================================================
--- trunk/compilers/imcc/pbc.c  (original)
+++ trunk/compilers/imcc/pbc.c  Tue Jan 27 04:25:07 2009
@@ -1388,7 +1388,7 @@
                 break;
             case PFC_STRING:
                 ns_pmc = constant_pmc_new(interp, enum_class_String);
-                PMC_str_val(ns_pmc) = ct->constants[ns_const]->u.string;
+                VTABLE_set_string_native(interp, ns_pmc, 
ct->constants[ns_const]->u.string);
                 break;
             default:
                 break;

Modified: trunk/include/parrot/inter_call.h
==============================================================================
--- trunk/include/parrot/inter_call.h   (original)
+++ trunk/include/parrot/inter_call.h   Tue Jan 27 04:25:07 2009
@@ -363,7 +363,7 @@
             *(pc) == PARROT_OP_get_params_pc || \
             *(pc) == PARROT_OP_set_returns_pc) { \
         PMC * const sig = (seg)->const_table->constants[(pc)[1]]->u.key; \
-        (n) += SIG_ELEMS(sig); \
+        (n) += VTABLE_elements((interp), sig); \
     } \
 } while (0)
 

Modified: trunk/languages/perl6/src/pmc/perl6multisub.pmc
==============================================================================
--- trunk/languages/perl6/src/pmc/perl6multisub.pmc     (original)
+++ trunk/languages/perl6/src/pmc/perl6multisub.pmc     Tue Jan 27 04:25:07 2009
@@ -131,7 +131,7 @@
     ++args_op;
     sig = constants[*args_op]->u.key;
     ASSERT_SIG_PMC(sig);
-    sig_len = SIG_ELEMS(sig);
+    sig_len = VTABLE_elements(interp, sig);
 
     /* If we have a zero-length signature, we're done. */
     if (sig_len == 0)
@@ -140,7 +140,7 @@
     /* Otherwise, we have arguments. */
     ++args_op;
     for (i = 0; i < sig_len; ++i, ++args_op) {
-        const INTVAL type = SIG_ITEM(sig, i);
+        const INTVAL type = VTABLE_get_integer_keyed_int(interp, sig, i);
         const int idx     = *args_op;
 
         /* If we find a named argument, then we know there's no more positional

Modified: trunk/src/inter_call.c
==============================================================================
--- trunk/src/inter_call.c      (original)
+++ trunk/src/inter_call.c      Tue Jan 27 04:25:07 2009
@@ -22,13 +22,14 @@
 #include "parrot/parrot.h"
 #include "parrot/oplib/ops.h"
 #include "inter_call.str"
+#include "pmc/pmc_fixedintegerarray.h"
 
 /* HEADERIZER HFILE: include/parrot/inter_call.h */
 
 /* HEADERIZER BEGIN: static */
 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will 
be lost. */
 
-static void check_for_opt_flag(ARGMOD(call_state *st), int has_arg)
+static void check_for_opt_flag(PARROT_INTERP, ARGMOD(call_state *st), int 
has_arg)
         __attribute__nonnull__(1)
         FUNC_MODIFIES(*st);
 
@@ -138,7 +139,7 @@
         __attribute__nonnull__(2)
         FUNC_MODIFIES(*st);
 
-static void next_arg_sig(ARGMOD(call_state_item *sti))
+static void next_arg_sig(PARROT_INTERP, ARGMOD(call_state_item *sti))
         __attribute__nonnull__(1)
         FUNC_MODIFIES(*sti);
 
@@ -429,7 +430,7 @@
 
 PARROT_EXPORT
 int
-Parrot_init_arg_indexes_and_sig_pmc(SHIM_INTERP, ARGIN(Parrot_Context *ctx),
+Parrot_init_arg_indexes_and_sig_pmc(PARROT_INTERP, ARGIN(Parrot_Context *ctx),
         ARGIN_NULLOK(opcode_t *indexes), ARGIN_NULLOK(PMC *sig_pmc),
         ARGMOD(call_state_item *sti))
 {
@@ -453,11 +454,11 @@
         ASSERT_SIG_PMC(sig_pmc);
         sti->u.op.signature = sig_pmc;
         sti->u.op.pc        = indexes;
-        sti->n              = SIG_ELEMS(sig_pmc);
+        sti->n              = VTABLE_elements(interp, sig_pmc);
 
         /* initialize sti->sig */
         if (sti->n)
-            next_arg_sig(sti);
+            next_arg_sig(interp, sti);
     }
 
     return sti->n > 0;
@@ -507,7 +508,7 @@
 
 PARROT_EXPORT
 int
-Parrot_init_arg_sig(SHIM_INTERP, ARGIN(Parrot_Context *ctx),
+Parrot_init_arg_sig(PARROT_INTERP, ARGIN(Parrot_Context *ctx),
     ARGIN(const char *sig), ARGIN_NULLOK(void *ap),
     ARGMOD(call_state_item *sti))
 {
@@ -526,7 +527,7 @@
 
         /* initialize st->sig */
         if (sti->n)
-            next_arg_sig(sti);
+            next_arg_sig(interp, sti);
     }
 
     return sti->n > 0;
@@ -589,12 +590,13 @@
 */
 
 static void
-next_arg_sig(ARGMOD(call_state_item *sti))
+next_arg_sig(PARROT_INTERP, ARGMOD(call_state_item *sti))
 {
     ASSERT_ARGS(next_arg_sig)
     switch (sti->mode & CALL_S_D_MASK) {
         case CALL_STATE_OP:
-            sti->sig = SIG_ITEM(sti->u.op.signature, sti->i);
+            sti->sig = VTABLE_get_integer_keyed_int(interp,
+                    sti->u.op.signature, sti->i);
             break;
         case CALL_STATE_SIG:
             switch (sti->u.sig.sig[sti->i]) {
@@ -770,7 +772,7 @@
 
     st->src.used = 0;
 
-    next_arg_sig(&st->src);
+    next_arg_sig(interp, &st->src);
 
     /* check if we're supposed to continue a :flat argument */
     if (st->src.mode & CALL_STATE_FLATTEN) {
@@ -807,7 +809,7 @@
     && !(st->src.sig & PARROT_ARG_FLATTEN)) {
         fetch_arg_op(interp, st);
         st->name = UVal_str(st->val);
-        next_arg_sig(&st->src);
+        next_arg_sig(interp, &st->src);
     }
 
     switch (st->src.mode & CALL_S_D_MASK) {
@@ -839,7 +841,7 @@
 Parrot_fetch_arg_nci(PARROT_INTERP, ARGMOD(call_state *st))
 {
     ASSERT_ARGS(Parrot_fetch_arg_nci)
-    next_arg_sig(&st->dest);
+    next_arg_sig(interp, &st->dest);
 
     if (st->dest.sig & PARROT_ARG_SLURPY_ARRAY) {
         PMC *slurped = pmc_new(interp,
@@ -1013,7 +1015,7 @@
 */
 
 static void
-check_for_opt_flag(ARGMOD(call_state *st), int has_arg)
+check_for_opt_flag(PARROT_INTERP, ARGMOD(call_state *st), int has_arg)
 {
     ASSERT_ARGS(check_for_opt_flag)
     INTVAL idx;
@@ -1026,7 +1028,7 @@
     if (dest->i >= dest->n)
         return;
 
-    next_arg_sig(dest);
+    next_arg_sig(interp, dest);
 
     /* if this isn't an :opt_flag argument, we need to reset things
      * and go to the next argument */
@@ -1113,7 +1115,8 @@
     /* 1) count named args, make sure there is less than 32/64
      * 2) create slurpy hash if needed */
     for (i = st->dest.i; i < st->dest.n; ++i) {
-        const INTVAL sig = SIG_ITEM(st->dest.u.op.signature, i);
+        const INTVAL sig = VTABLE_get_integer_keyed_int(interp,
+                st->dest.u.op.signature, i);
 
         /* skip the arg name, only count the actual args of the named args */
         if (!(sig & PARROT_ARG_NAME))
@@ -1168,7 +1171,8 @@
         int idx;
         STRING *param;
 
-        st->dest.sig = SIG_ITEM(st->dest.u.op.signature, i);
+        st->dest.sig = VTABLE_get_integer_keyed_int(interp,
+                st->dest.u.op.signature, i);
         if (!(st->dest.sig & PARROT_ARG_NAME))
             continue;
 
@@ -1183,7 +1187,8 @@
 
         if (st->name == param || string_equal(interp, st->name, param) == 0) {
             ++i;
-            st->dest.sig = SIG_ITEM(st->dest.u.op.signature, i);
+            st->dest.sig = VTABLE_get_integer_keyed_int(interp,
+                    st->dest.u.op.signature, i);
             st->dest.i   = i;
 
             /* if bit is set we have a duplicate */
@@ -1371,7 +1376,8 @@
 
     for (i = st->first_named; i < st->dest.n; ++i) {
         /* verify that a name exists */
-        const INTVAL sig = st->dest.sig = SIG_ITEM(st->dest.u.op.signature, i);
+        const INTVAL sig = st->dest.sig =
+            VTABLE_get_integer_keyed_int(interp, st->dest.u.op.signature, i);
         if (sig & PARROT_ARG_NAME) {
             INTVAL arg_sig;
             int last_name_pos;
@@ -1387,12 +1393,17 @@
             i++;
 
             /* verify that an actual arg exists */
-            arg_sig = st->dest.sig = SIG_ITEM(st->dest.u.op.signature, i);
+            arg_sig = st->dest.sig = VTABLE_get_integer_keyed_int(interp,
+                    st->dest.u.op.signature, i);
             PARROT_ASSERT(!(arg_sig & PARROT_ARG_NAME));
 
             /* if this named arg is already filled, continue */
             if (st->named_done & (1 << n_named)) {
-                arg_sig = st->dest.sig = SIG_ITEM(st->dest.u.op.signature, 
i+1);
+                /* XXX: This reads past the end of the array. TT #233*/
+                INTVAL* int_array;
+                GETATTR_FixedIntegerArray_int_array(interp,
+                        st->dest.u.op.signature, int_array);
+                arg_sig = st->dest.sig = int_array[i+1];
 
                 /* skip associated opt flag arg as well */
                 if (arg_sig & PARROT_ARG_OPT_FLAG)
@@ -1409,7 +1420,8 @@
                 /* Don't walk off the end of the array */
                 if (i+1 >= st->dest.n)
                     continue;
-                arg_sig = st->dest.sig = SIG_ITEM(st->dest.u.op.signature, 
i+1);
+                arg_sig = st->dest.sig = VTABLE_get_integer_keyed_int(interp,
+                        st->dest.u.op.signature, i+1);
                 if (arg_sig & PARROT_ARG_OPT_FLAG) {
                     i++;
                     idx = st->dest.u.op.pc[i];
@@ -1505,7 +1517,7 @@
         int has_arg;
 
         /* check if the next dest arg is :slurpy */
-        next_arg_sig(dest);
+        next_arg_sig(interp, dest);
         if (dest->sig & PARROT_ARG_SLURPY_ARRAY)
             break;
 
@@ -1534,11 +1546,11 @@
                 PARROT_ASSERT(idx >= 0);
                 store_arg(st, idx);
 
-                check_for_opt_flag(st, 0);
+                check_for_opt_flag(interp, st, 0);
 
                 /* next dest arg */
                 dest->i++;
-                next_arg_sig(dest);
+                next_arg_sig(interp, dest);
             }
 
             /* Restore value */
@@ -1553,7 +1565,7 @@
             if (!has_arg)
                 break;
             dest->i++;
-            next_arg_sig(dest);
+            next_arg_sig(interp, dest);
         }
 
         /* if there *is* an arg, convert it */
@@ -1581,7 +1593,7 @@
 
         /* if we're at an :optional argument, check for an :opt_flag */
         if (dest->sig & PARROT_ARG_OPTIONAL)
-            check_for_opt_flag(st, has_arg);
+            check_for_opt_flag(interp, st, has_arg);
     }
 
     /* 2nd: Positional :slurpy */
@@ -1653,7 +1665,7 @@
 
             /* if we're at an :optional argument, check for an :opt_flag */
             if (dest->sig & PARROT_ARG_OPTIONAL)
-                check_for_opt_flag(st, 1);
+                check_for_opt_flag(interp, st, 1);
         }
 
         /* otherwise this doesn't get reset and we can't catch positional args

Modified: trunk/src/multidispatch.c
==============================================================================
--- trunk/src/multidispatch.c   (original)
+++ trunk/src/multidispatch.c   Tue Jan 27 04:25:07 2009
@@ -593,14 +593,14 @@
 
     ASSERT_SIG_PMC(args_array);
 
-    sig_len = SIG_ELEMS(args_array);
+    sig_len = VTABLE_elements(interp, args_array);
     if (!sig_len)
         return arg_tuple;
 
     ++args_op;
 
     for (i = 0; i < sig_len; ++i, ++args_op) {
-        type = SIG_ITEM(args_array, i);
+        type = VTABLE_get_integer_keyed_int(interp, args_array, i);
 
         /* named don't MMD */
         if (type & PARROT_ARG_NAME)

Modified: trunk/src/ops/core.ops
==============================================================================
--- trunk/src/ops/core.ops      (original)
+++ trunk/src/ops/core.ops      Tue Jan 27 04:25:07 2009
@@ -564,7 +564,7 @@
 
     /* for now just point to the opcode */
     interp->current_args = _this;
-    argc = SIG_ELEMS(signature);
+    argc = VTABLE_elements(interp, signature);
     goto OFFSET(argc + 2);
 }
 
@@ -574,7 +574,7 @@
     INTVAL argc;
 
     CONTEXT(interp)->current_results = _this;
-    argc = SIG_ELEMS(signature);
+    argc = VTABLE_elements(interp, signature);
     goto OFFSET(argc + 2);
 }
 
@@ -608,7 +608,7 @@
         Parrot_free_context(interp, caller_ctx, 1);
         interp->current_args = NULL;
     }
-    argc = SIG_ELEMS(signature);
+    argc = VTABLE_elements(interp, signature);
     goto OFFSET(argc + 2);
 }
 
@@ -646,7 +646,7 @@
         parrot_pass_args(interp, ctx, ctx->caller_ctx, interp->current_returns,
                 ctx->caller_ctx->current_results, PARROT_PASS_RESULTS);
     }
-    argc = SIG_ELEMS(signature);
+    argc = VTABLE_elements(interp, signature);
     goto OFFSET(argc + 2);
 }
 

Modified: trunk/src/pbc_merge.c
==============================================================================
--- trunk/src/pbc_merge.c       (original)
+++ trunk/src/pbc_merge.c       Tue Jan 27 04:25:07 2009
@@ -762,9 +762,9 @@
             const PMC * const sig = 
bc->const_table->constants[op_ptr[1]]->u.key;
 
             /* Loop over the arguments to locate any that need a fixup. */
-            const int sig_items = SIG_ELEMS(sig);
+            const int sig_items = VTABLE_elements(interp, sig);
             for (cur_arg = 0; cur_arg < sig_items; cur_arg++) {
-                switch (SIG_ITEM(sig, cur_arg)) {
+                switch (VTABLE_get_integer_keyed_int(interp, sig, cur_arg)) {
                     case PARROT_ARG_NC:
                     case PARROT_ARG_PC:
                     case PARROT_ARG_SC:

Modified: trunk/src/pmc/fixedintegerarray.pmc
==============================================================================
--- trunk/src/pmc/fixedintegerarray.pmc (original)
+++ trunk/src/pmc/fixedintegerarray.pmc Tue Jan 27 04:25:07 2009
@@ -22,6 +22,8 @@
 #include "parrot/parrot.h"
 
 pmclass FixedIntegerArray need_ext provides array {
+    ATTR INTVAL   size;  /* number of INTVALs stored in this array */
+    ATTR INTVAL * int_array; /* INTVALs are stored here */
 
 /*
 
@@ -40,8 +42,10 @@
 */
 
     VTABLE void init() {
-        PMC_int_val(SELF) = 0;
-        PMC_data(SELF)    = NULL;
+        Parrot_FixedIntegerArray_attributes* attrs =
+            mem_allocate_zeroed_typed(Parrot_FixedIntegerArray_attributes);
+        PMC_data(SELF) = attrs;
+        PObj_active_destroy_SET(SELF);
     }
 
 /*
@@ -148,11 +152,11 @@
 */
 
     VTABLE void destroy() {
-        if (PMC_data(SELF))
-            mem_sys_free(PMC_data(SELF));
-
-        PMC_data(SELF)    = NULL;
-        PMC_int_val(SELF) = 0;
+        INTVAL* int_array;
+        GET_ATTR_int_array(INTERP, SELF, int_array);
+        if (int_array)
+            mem_sys_free(int_array);
+        mem_sys_free(PMC_data(SELF));
     }
 
 /*
@@ -173,17 +177,21 @@
          * vtable
          */
 
-        PMC * const dest =
+        INTVAL * int_array;
+        PMC    * const dest =
             PObj_constant_TEST(SELF)
                 ? constant_pmc_new(INTERP, SELF->vtable->base_type)
                 : pmc_new(INTERP, SELF->vtable->base_type);
 
-        if (PMC_data(SELF)) {
-            const INTVAL size = PMC_int_val(SELF);
-            PMC_int_val(dest) = size;
-            PMC_data(dest)    = mem_allocate_n_typed(size, INTVAL);
+        GET_ATTR_int_array(INTERP, SELF, int_array);
+        if (int_array) {
+            INTVAL      *dest_int_array;
+            const INTVAL size = SELF.elements();
+            dest_int_array = mem_allocate_n_typed(size, INTVAL);
+            SET_ATTR_size(INTERP, dest, size);
+            SET_ATTR_int_array(INTERP, dest, dest_int_array);
 
-            mem_sys_memcopy(PMC_data(dest), PMC_data(SELF), size * sizeof 
(INTVAL));
+            mem_sys_memcopy(dest_int_array, int_array, size * sizeof (INTVAL));
             PObj_active_destroy_SET(dest);
         }
 
@@ -228,7 +236,7 @@
 */
 
     VTABLE INTVAL get_integer() {
-        return PMC_int_val(SELF);
+        return PARROT_FIXEDINTEGERARRAY(SELF)->size;
     }
 
 
@@ -243,14 +251,14 @@
 */
 
     VTABLE INTVAL get_integer_keyed_int(INTVAL key) {
-        INTVAL *data;
+        INTVAL *int_array;
 
-        if (key < 0 || key >= PMC_int_val(SELF))
+        if (key < 0 || key >= SELF.elements())
             Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_OUT_OF_BOUNDS,
                 "FixedIntegerArray: index out of bounds!");
 
-        data = (INTVAL *)PMC_data(SELF);
-        return data[key];
+        GET_ATTR_int_array(INTERP, SELF, int_array);
+        return int_array[key];
     }
 
 /*
@@ -402,12 +410,15 @@
 */
 
     VTABLE void set_integer_native(INTVAL size) {
-        if (PMC_int_val(SELF) || size < 1)
+        INTVAL *int_array;
+        if (SELF.elements() || size < 1)
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
                 "FixedIntegerArray: Can't resize!");
 
-        PMC_int_val(SELF) = size;
-        mem_realloc_n_typed(PMC_data(SELF), size, INTVAL);
+        SET_ATTR_size(INTERP, SELF, size);
+        GET_ATTR_int_array(INTERP, SELF, int_array);
+        int_array = mem_realloc_n_typed(int_array, size, INTVAL);
+        SET_ATTR_int_array(INTERP, SELF, int_array);
         PObj_active_destroy_SET(SELF);
     }
 
@@ -422,14 +433,14 @@
 */
 
     VTABLE void set_integer_keyed_int(INTVAL key, INTVAL value) {
-        INTVAL *data;
+        INTVAL *int_array;
 
-        if (key < 0 || key >= PMC_int_val(SELF))
+        if (key < 0 || key >= SELF.elements())
             Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_OUT_OF_BOUNDS,
                 "FixedIntegerArray: index out of bounds!");
 
-        data      = (INTVAL *)PMC_data(SELF);
-        data[key] = value;
+        GET_ATTR_int_array(INTERP, SELF, int_array);
+        int_array[key] = value;
     }
 
 /*
@@ -488,7 +499,7 @@
 
     VTABLE void set_string_keyed_int(INTVAL key, STRING *value) {
         INTVAL tempInt;
-        PMC   * const tempPMC = temporary_pmc_new(INTERP, enum_class_Integer);
+        PMC  * const tempPMC = temporary_pmc_new(INTERP, enum_class_Integer);
         VTABLE_set_string_native(INTERP, tempPMC, value);
         tempInt        = VTABLE_get_integer(INTERP, tempPMC);
         temporary_pmc_free(interp, tempPMC);
@@ -541,10 +552,13 @@
     }
 
     METHOD sort(PMC *cmp_func) {
-        UINTVAL n = (UINTVAL)PMC_int_val(SELF);
+        INTVAL *int_array;
+        UINTVAL n = (UINTVAL)SELF.elements();
 
-        if (n > 1)
-            Parrot_quicksort(interp, PMC_data_typed(SELF, void **), n, 
cmp_func);
+        if (n > 1) {
+            GET_ATTR_int_array(INTERP, SELF, int_array);
+            Parrot_quicksort(interp, (void**)int_array, n, cmp_func);
+        }
     }
 
 /*
@@ -567,43 +581,47 @@
 
 */
 
-    VTABLE void visit(visit_info *info) {
+    /*VTABLE void visit(visit_info *info) {
         SUPER(info);
-    }
+    }*/
 
     VTABLE void freeze(visit_info *info) {
         IMAGE_IO *io = info->image_io;
-        INTVAL   *ar;
+        INTVAL   *int_array;
         INTVAL    i, n;
 
         SUPER(info);
 
         n  = SELF.get_integer();
         VTABLE_push_integer(INTERP, io, n);
-        ar = (INTVAL *)PMC_data(SELF);
+        GET_ATTR_int_array(INTERP, SELF, int_array);
 
         for (i = 0; i < n; ++i)
-            VTABLE_push_integer(INTERP, io, ar[i]);
+            VTABLE_push_integer(INTERP, io, int_array[i]);
     }
 
     VTABLE void thaw(visit_info *info) {
 
+        Parrot_FixedIntegerArray_attributes *attrs =
+            mem_allocate_zeroed_typed(Parrot_FixedIntegerArray_attributes);
+        PMC_data(SELF) = attrs;
+
         if (info->extra_flags == EXTRA_IS_NULL) {
             IMAGE_IO * const io = info->image_io;
             const INTVAL n = VTABLE_shift_integer(INTERP, io);
 
-            PMC_int_val(SELF) = 0;
-            PMC_data(SELF)    = NULL;
+            SET_ATTR_size(INTERP, SELF, 0);
+            SET_ATTR_int_array(INTERP, SELF, NULL);
 
             if (n) {
                 INTVAL  i;
-                INTVAL *ar;
+                INTVAL *int_array;
 
                 SELF.set_integer_native(n);
-                ar = (INTVAL *)PMC_data(SELF);
+                GET_ATTR_int_array(INTERP, SELF, int_array);
 
                 for (i = 0; i < n; ++i)
-                    ar[i] = VTABLE_shift_integer(INTERP, io);
+                    int_array[i] = VTABLE_shift_integer(INTERP, io);
             }
         }
         else

Modified: trunk/src/pmc/resizableintegerarray.pmc
==============================================================================
--- trunk/src/pmc/resizableintegerarray.pmc     (original)
+++ trunk/src/pmc/resizableintegerarray.pmc     Tue Jan 27 04:25:07 2009
@@ -24,6 +24,23 @@
 
 
 pmclass ResizableIntegerArray extends FixedIntegerArray need_ext provides 
array {
+    ATTR INTVAL resize_threshold; /* max size before array needs to be resized 
*/
+
+/*
+
+=item C<void init()>
+
+Initializes the array.
+
+=cut
+
+*/
+    VTABLE void init() {
+        Parrot_ResizableIntegerArray_attributes* attrs =
+            mem_allocate_zeroed_typed(Parrot_ResizableIntegerArray_attributes);
+        PMC_data(SELF) = attrs;
+        PObj_active_destroy_SET(SELF);
+    }
 
 /*
 
@@ -36,7 +53,7 @@
 */
 
     VTABLE INTVAL get_integer_keyed_int(INTVAL key) {
-        INTVAL *data;
+        INTVAL *int_array;
 
         if (key < 0)
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
@@ -45,8 +62,8 @@
         if (key >= SELF.get_integer())
             return 0;
 
-        data = (INTVAL *)PMC_data(SELF);
-        return data[key];
+        GET_ATTR_int_array(INTERP, SELF, int_array);
+        return int_array[key];
     }
 
 /*
@@ -60,7 +77,7 @@
 */
 
     VTABLE void set_integer_keyed_int(INTVAL key, INTVAL value) {
-        INTVAL *data;
+        INTVAL *int_array;
 
         if (key < 0)
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
@@ -69,8 +86,8 @@
         if (key >= SELF.get_integer())
             SELF.set_integer_native(key+1);
 
-        data      = (INTVAL *)PMC_data(SELF);
-        data[key] = value;
+        GET_ATTR_int_array(INTERP, SELF, int_array);
+        int_array[key] = value;
     }
 
 /*
@@ -84,29 +101,36 @@
 */
 
     VTABLE void set_integer_native(INTVAL size) {
+
+        INTVAL *int_array;
+        INTVAL  resize_threshold;
+
         if (size < 0)
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
                     "ResizableIntegerArray: Can't resize!");
 
-        if (!PMC_data(SELF)) {
+        GET_ATTR_int_array(INTERP, SELF, int_array);
+        GET_ATTR_resize_threshold(INTERP, SELF, resize_threshold);
+        if (!int_array) {
             /* empty - used fixed routine */
             if (size < 8) {
                 SUPER(8);
-                PMC_int_val(SELF)  = size;
-                PMC_int_val2(SELF) = 8;
+                SET_ATTR_size(INTERP, SELF, size);
+                SET_ATTR_resize_threshold(INTERP, SELF, 8);
             }
             else {
                 SUPER(size);
-                PMC_int_val2(SELF) = size;
+                SET_ATTR_resize_threshold(INTERP, SELF, size);
             }
         }
-        else if (size <= PMC_int_val2(SELF)) {
+        else if (size <= resize_threshold) {
             /* we could shrink here if necessary */
-            PMC_int_val(SELF) = size;
+            SET_ATTR_size(INTERP, SELF, size);
             return;
         }
         else {
-            INTVAL cur = PMC_int_val2(SELF);
+            INTVAL  cur = resize_threshold;
+            INTVAL *int_array;
 
             if (cur < 8192)
                 cur = size < 2 * cur ? 2 * cur : size;
@@ -116,10 +140,11 @@
                 cur          &= ~0xfff;
             }
 
-            PMC_data(SELF) = mem_sys_realloc(PMC_data(SELF),
-                    cur * sizeof (INTVAL));
-            PMC_int_val2(SELF) = cur;
-            PMC_int_val(SELF)  = size;
+            GET_ATTR_int_array(INTERP, SELF, int_array);
+            int_array = (INTVAL*)mem_sys_realloc( (void*)int_array, cur * 
sizeof (INTVAL));
+            SET_ATTR_int_array(INTERP, SELF, int_array);
+            SET_ATTR_size(INTERP, SELF, size);
+            SET_ATTR_resize_threshold(INTERP, SELF, cur);
         }
     }
 
@@ -172,18 +197,18 @@
 */
 
     VTABLE INTVAL shift_integer() {
-        INTVAL value, *data;
+        INTVAL value, *int_array;
         INTVAL size = SELF.get_integer();
 
         if (size == 0)
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
                     "ResizableIntegerArray: Can't shift from an empty array!");
 
-        data  = (INTVAL *)PMC_data(SELF);
-        value = data[0];
+        GET_ATTR_int_array(INTERP, SELF, int_array);
+        value = int_array[0];
 
         --size;
-        mem_sys_memmove(data, data + 1, size * sizeof (INTVAL));
+        mem_sys_memmove(int_array, int_array + 1, size * sizeof (INTVAL));
         SELF.set_integer_native(size);
         return value;
     }
@@ -199,13 +224,13 @@
 */
 
     VTABLE void unshift_integer(INTVAL value) {
-        INTVAL *data;
+        INTVAL *int_array;
         INTVAL size = SELF.get_integer();
 
         SELF.set_integer_native(size + 1);
-        data    = (INTVAL *)PMC_data(SELF);
-        mem_sys_memmove(data + 1, data, size * sizeof (INTVAL));
-        data[0] = value;
+        GET_ATTR_int_array(INTERP, SELF, int_array);
+        mem_sys_memmove(int_array + 1, int_array, size * sizeof (INTVAL));
+        int_array[0] = value;
     }
 
 /*
@@ -226,9 +251,10 @@
                 "ResizableIntegerArray: index out of bounds!");
         }
         else {
-            INTVAL *data = (INTVAL *)PMC_data(SELF);
+            INTVAL *int_array;
+            GET_ATTR_int_array(INTERP, SELF, int_array);
             --size;
-            mem_sys_memmove(data + key, data + key + 1, (size - key) * sizeof 
(INTVAL));
+            mem_sys_memmove(int_array + key, int_array + key + 1, (size - key) 
* sizeof (INTVAL));
             SELF.set_integer_native(size);
         }
     }
@@ -244,16 +270,80 @@
 */
 
     VTABLE PMC *clone() {
+        INTVAL size;
         PMC *copy          = SUPER();
 
         /* copy trimmed extra space */
-        PMC_int_val2(copy) = PMC_int_val(SELF);
+        GET_ATTR_size(INTERP, SELF, size);
+        SET_ATTR_resize_threshold(INTERP, SELF, size);
 
         return copy;
     }
 
-}
+/*
+
+=item C<void freeze(visit_info *info)>
+
+Used to archive the array.
+
+=item C<void thaw(visit_info *info)>
+
+Used to unarchive the array.
 
+=cut
+
+*/
+
+    VTABLE void freeze(visit_info *info) {
+        IMAGE_IO *io = info->image_io;
+        INTVAL   *int_array;
+        INTVAL    i, n, rt;
+
+        SUPER(info);
+
+        n  = SELF.get_integer();
+        GET_ATTR_resize_threshold(INTERP, SELF, rt);
+        VTABLE_push_integer(INTERP, io, n);
+        VTABLE_push_integer(INTERP, io, rt);
+
+        GET_ATTR_int_array(INTERP, SELF, int_array);
+
+        for (i = 0; i < n; ++i)
+            VTABLE_push_integer(INTERP, io, int_array[i]);
+    }
+
+    VTABLE void thaw(visit_info *info) {
+
+        Parrot_ResizableIntegerArray_attributes *attrs =
+            mem_allocate_zeroed_typed(Parrot_ResizableIntegerArray_attributes);
+        PMC_data(SELF) = attrs;
+
+        if (info->extra_flags == EXTRA_IS_NULL) {
+            IMAGE_IO * const io = info->image_io;
+            const INTVAL n = VTABLE_shift_integer(INTERP, io);
+            const INTVAL rt = VTABLE_shift_integer(INTERP, io);
+
+            SET_ATTR_size(INTERP, SELF, 0);
+            SET_ATTR_resize_threshold(INTERP, SELF, rt);
+            SET_ATTR_int_array(INTERP, SELF, NULL);
+
+            if (n) {
+                INTVAL  i;
+                INTVAL *int_array;
+
+                SELF.set_integer_native(n);
+                GET_ATTR_int_array(INTERP, SELF, int_array);
+
+                for (i = 0; i < n; ++i)
+                    int_array[i] = VTABLE_shift_integer(INTERP, io);
+            }
+        }
+        else
+            SUPER(info);
+    }
+
+
+}
 /*
 
 =back

Modified: trunk/src/pmc/string.pmc
==============================================================================
--- trunk/src/pmc/string.pmc    (original)
+++ trunk/src/pmc/string.pmc    Tue Jan 27 04:25:07 2009
@@ -890,7 +890,7 @@
         p = (unsigned char *)src->strstart;
         /* TODO verify trans table */
 
-        tr_data = PMC_data_typed(table, INTVAL *);    /* XXX */
+        GETATTR_FixedIntegerArray_int_array(INTERP, table, tr_data);
 
         for (i = 0; i < len; ++i, ++p) {
             const unsigned char ch = (unsigned char)tr_data[*p];

Modified: trunk/src/pmc/sub.pmc
==============================================================================
--- trunk/src/pmc/sub.pmc       (original)
+++ trunk/src/pmc/sub.pmc       Tue Jan 27 04:25:07 2009
@@ -715,8 +715,8 @@
 
             /* If the first instruction is a get_params... */
             if (*pc == PARROT_OP_get_params_pc) {
-                int i, sig_length;
-                PMC *sig;
+                int     i, sig_length;
+                PMC    *sig;
 
                 /* Get the signature (the next thing in the bytecode). */
                 pc++;
@@ -724,10 +724,10 @@
                 ASSERT_SIG_PMC(sig);
 
                 /* Iterate over the signature and compute argument counts. */
-                sig_length = SIG_ELEMS(sig);
+                sig_length = VTABLE_elements(INTERP, sig);
                 for (i = 0; i < sig_length; i++)
                 {
-                    int sig_item = SIG_ITEM(sig, i);
+                    int sig_item = VTABLE_get_integer_keyed_int(INTERP, sig, 
i);;
                     if (PARROT_ARG_SLURPY_ARRAY_ISSET(sig_item)){
                         if (PARROT_ARG_NAME_ISSET(sig_item))
                             sub->arg_info->named_slurpy = 1;
@@ -736,7 +736,7 @@
                     }
                     else if (PARROT_ARG_NAME_ISSET(sig_item)) {
                         i++;
-                        sig_item = SIG_ITEM(sig, i);
+                        sig_item = VTABLE_get_integer_keyed_int(INTERP, sig, 
i);;
                         if (PARROT_ARG_OPTIONAL_ISSET(sig_item))
                             sub->arg_info->named_optional++;
                         else

Reply via email to