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

NotFound at svn.parrot.org NotFound at svn.parrot.org
Thu May 27 22:43:18 UTC 2010


Author: NotFound
Date: Thu May 27 22:43:18 2010
New Revision: 47070
URL: https://trac.parrot.org/parrot/changeset/47070

Log:
[cage] some cleaning of ResizablePMCArray, no functional changes

Modified:
   trunk/src/pmc/resizablepmcarray.pmc

Modified: trunk/src/pmc/resizablepmcarray.pmc
==============================================================================
--- trunk/src/pmc/resizablepmcarray.pmc	Thu May 27 22:38:59 2010	(r47069)
+++ trunk/src/pmc/resizablepmcarray.pmc	Thu May 27 22:43:18 2010	(r47070)
@@ -11,7 +11,7 @@
 This class, ResizablePMCArray, implements an resizable array which stores PMCs.
 It puts things into Integer, Float, or String PMCs as appropriate.
 
-=head2 Functions
+=head2 Vtable Functions
 
 =over 4
 
@@ -25,6 +25,21 @@
 
 /* HEADERIZER HFILE: none */
 /* HEADERIZER BEGIN: static */
+/* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
+
+PARROT_DOES_NOT_RETURN
+static void throw_pop_empty(PARROT_INTERP)
+        __attribute__nonnull__(1);
+
+PARROT_DOES_NOT_RETURN
+static void throw_shift_empty(PARROT_INTERP)
+        __attribute__nonnull__(1);
+
+#define ASSERT_ARGS_throw_pop_empty __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp))
+#define ASSERT_ARGS_throw_shift_empty __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp))
+/* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
 /* HEADERIZER END: static */
 
 pmclass ResizablePMCArray extends FixedPMCArray auto_attrs provides array {
@@ -134,8 +149,7 @@
         FLOATVAL  value;
 
         if (0 == size)
-            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
-                    "ResizablePMCArray: Can't shift from an empty array!");
+            throw_shift_empty(INTERP);
 
         item           = PMC_array(SELF);
         data           = item[0];
@@ -156,8 +170,7 @@
         INTVAL    value;
 
         if (0 == size)
-            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
-                    "ResizablePMCArray: Can't shift from an empty array!");
+            throw_shift_empty(INTERP);
 
         item           = PMC_array(SELF);
         data           = item[0];
@@ -176,8 +189,7 @@
         PMC   **item;
 
         if (0 == size)
-            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
-                    "ResizablePMCArray: Can't shift from an empty array!");
+            throw_shift_empty(INTERP);
 
         item           = PMC_array(SELF);
         data           = item[0];
@@ -196,8 +208,7 @@
         STRING  *value;
 
         if (0 == size)
-            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
-                    "ResizablePMCArray: Can't shift from an empty array!");
+            throw_shift_empty(INTERP);
 
         item           = PMC_array(SELF);
         data           = item[0];
@@ -435,8 +446,7 @@
         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!");
+            throw_pop_empty(INTERP);
 
         data           = PMC_array(SELF)[--size];
         PMC_size(SELF) = size;
@@ -450,8 +460,7 @@
         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!");
+            throw_pop_empty(INTERP);
 
         data           = PMC_array(SELF)[--size];
         PMC_size(SELF) = size;
@@ -465,8 +474,7 @@
         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!");
+            throw_pop_empty(INTERP);
 
         data           = PMC_array(SELF)[--size];
         PMC_size(SELF) = size;
@@ -480,8 +488,7 @@
         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!");
+            throw_pop_empty(INTERP);
 
         data           = PMC_array(SELF)[--size];
         PMC_size(SELF) = size;
@@ -604,43 +611,6 @@
 
 /*
 
-=item METHOD append(PMC *other)
-
-Append the other array to this array.
-
-=cut
-
-*/
-
-    METHOD append(PMC *other) {
-
-        const INTVAL n = VTABLE_elements(INTERP, SELF);
-        const INTVAL m = VTABLE_elements(INTERP, other);
-
-        if (!m)
-            RETURN(void);
-
-        /* pre-size it */
-        VTABLE_set_integer_native(INTERP, SELF, n + m);
-
-        if (other->vtable->base_type == SELF->vtable->base_type
-        ||  other->vtable->base_type == enum_class_FixedPMCArray) {
-            PMC ** const other_data = PMC_array(other);
-            PMC ** const 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 ** const this_data = PMC_array(SELF);
-            INTVAL i;
-
-            for (i = 0; i < m; ++i)
-                this_data[n + i] = VTABLE_get_pmc_keyed_int(INTERP, other, i);
-        }
-    }
-/*
-
 =item C<STRING *get_repr()>
 
 Returns the Parrot string representation C<ResizablePMCArray>.
@@ -725,6 +695,50 @@
 
 /*
 
+=back
+
+=head2 Methdos
+
+=over 4
+
+=item METHOD append(PMC *other)
+
+Append the other array to this array.
+
+=cut
+
+*/
+
+    METHOD append(PMC *other) {
+
+        const INTVAL n = VTABLE_elements(INTERP, SELF);
+        const INTVAL m = VTABLE_elements(INTERP, other);
+
+        if (!m)
+            RETURN(void);
+
+        /* pre-size it */
+        VTABLE_set_integer_native(INTERP, SELF, n + m);
+
+        if (other->vtable->base_type == SELF->vtable->base_type
+        ||  other->vtable->base_type == enum_class_FixedPMCArray) {
+            PMC ** const other_data = PMC_array(other);
+            PMC ** const 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 ** const this_data = PMC_array(SELF);
+            INTVAL i;
+
+            for (i = 0; i < m; ++i)
+                this_data[n + i] = VTABLE_get_pmc_keyed_int(INTERP, other, i);
+        }
+    }
+
+/*
+
 =item METHOD PMC* shift()
 
 =item METHOD PMC* pop()
@@ -772,6 +786,42 @@
 
 =back
 
+=head2 Auxiliar functions
+
+=over 4
+
+=item C<static void throw_shift_empty(PARROT_INTERP)>
+
+=item C<static void throw_pop_empty(PARROT_INTERP)>
+
+Throws with the appropiate message.
+
+=cut
+
+*/
+
+PARROT_DOES_NOT_RETURN
+static void
+throw_shift_empty(PARROT_INTERP)
+{
+    ASSERT_ARGS(throw_shift_empty)
+    Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_OUT_OF_BOUNDS,
+            "ResizablePMCArray: Can't shift from an empty array!");
+}
+
+PARROT_DOES_NOT_RETURN
+static void
+throw_pop_empty(PARROT_INTERP)
+{
+    ASSERT_ARGS(throw_pop_empty)
+    Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_OUT_OF_BOUNDS,
+            "ResizablePMCArray: Can't pop from an empty array!");
+}
+
+/*
+
+=back
+
 =head1 See also
 
 F<docs/pdds/pdd17_basic_types.pod>.


More information about the parrot-commits mailing list