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

cotto at svn.parrot.org cotto at svn.parrot.org
Mon Mar 23 22:39:16 UTC 2009


Author: cotto
Date: Mon Mar 23 22:39:14 2009
New Revision: 37657
URL: https://trac.parrot.org/parrot/changeset/37657

Log:
[PMC] replace most remaining PMC_struct_val instances in Hash-like PMCs, remove some redundant code

Modified:
   trunk/src/pmc/addrregistry.pmc
   trunk/src/pmc/lexinfo.pmc
   trunk/src/pmc/namespace.pmc
   trunk/src/pmc/orderedhash.pmc

Modified: trunk/src/pmc/addrregistry.pmc
==============================================================================
--- trunk/src/pmc/addrregistry.pmc	Mon Mar 23 21:49:01 2009	(r37656)
+++ trunk/src/pmc/addrregistry.pmc	Mon Mar 23 22:39:14 2009	(r37657)
@@ -32,61 +32,28 @@
 #include "pmc_hash.h"
 
 pmclass AddrRegistry extends Hash need_ext provides hash {
-    ATTR Hash *hash;    /* a PMC Hash */
 /*
 
 =item C<void init()>
 
 Initializes the instance.
 
-=item C<void destroy()>
-
-Free hash structure.
-
 =cut
 
 */
 
     VTABLE void init() {
-        Hash                       *registry;
-        Parrot_AddrRegistry_attributes * const addr_registry =
-            mem_allocate_zeroed_typed(Parrot_AddrRegistry_attributes);
-
-        PMC_data(SELF)      = addr_registry;
+        Hash  *registry = parrot_create_hash(INTERP,
+                enum_type_int,
+                Hash_key_type_PMC,
+                int_compare,
+                key_hash_int);
+
+        /* prevent set_pointer from trying to delete an invalid hash */
+        PMC_struct_val(SELF) = NULL;
+        SELF.set_pointer(registry);
         PObj_custom_mark_destroy_SETALL(SELF);
 
-        registry = parrot_create_hash(INTERP, enum_type_int, Hash_key_type_PMC,
-                              int_compare, key_hash_int);
-
-        PMC_struct_val(SELF) = registry;
-        addr_registry->hash  = registry;
-        registry->container  = SELF;
-
-    }
-
-    VTABLE void destroy() {
-        if (PMC_data(SELF)) {
-            Parrot_AddrRegistry_attributes * const registry = PARROT_ADDRREGISTRY(SELF);
-
-            parrot_hash_destroy(INTERP, registry->hash);
-            mem_sys_free(registry);
-            PMC_data(SELF) = NULL;
-        }
-    }
-
-/*
-
-=item C<void mark()>
-
-Marks the hash as live.
-
-=cut
-
-*/
-
-    VTABLE void mark() {
-        if (PMC_data(SELF))
-            parrot_mark_hash(INTERP, PARROT_ADDRREGISTRY(SELF)->hash);
     }
 
 /*
@@ -108,7 +75,7 @@
 */
 
     VTABLE INTVAL get_integer_keyed(PMC *key) {
-        Hash   *hash  = PARROT_ADDRREGISTRY(SELF)->hash;
+        Hash   *hash  = (Hash *)SELF.get_pointer();
         void   *value = parrot_hash_get(INTERP, hash, key);
 
         if (value)
@@ -118,11 +85,11 @@
     }
 
     VTABLE INTVAL elements() {
-        return parrot_hash_size(INTERP, PARROT_ADDRREGISTRY(SELF)->hash);
+        return parrot_hash_size(INTERP, (Hash *)SELF.get_pointer());
     }
 
     VTABLE INTVAL get_bool() {
-        return parrot_hash_size(INTERP, PARROT_ADDRREGISTRY(SELF)->hash) != 0;
+        return parrot_hash_size(INTERP, (Hash *)SELF.get_pointer()) != 0;
     }
 /*
 
@@ -146,7 +113,7 @@
 */
 
     VTABLE void set_pmc_keyed(PMC *key, PMC *value) {
-        Hash       * const hash = PARROT_ADDRREGISTRY(SELF)->hash;
+        Hash       * const hash = (Hash *)SELF.get_pointer();
         void       *oldval      = parrot_hash_get(INTERP, hash, key);
         long        newval      = 1;
         UNUSED(value);
@@ -158,12 +125,12 @@
     }
 
     VTABLE void set_integer_keyed(PMC *key, INTVAL value) {
-        Hash *hash = PARROT_ADDRREGISTRY(SELF)->hash;
+        Hash *hash = (Hash *)SELF.get_pointer();
         parrot_hash_put(INTERP, hash, key, (void *)value);
     }
 
     VTABLE void delete_keyed(PMC *key) {
-        Hash       * const hash  = PARROT_ADDRREGISTRY(SELF)->hash;
+        Hash       * const hash  = (Hash *)SELF.get_pointer();
         void              *value = parrot_hash_get(INTERP, hash, key);
 
         /* these casts look bad, but they avoid type punning warnings with -O */
@@ -189,7 +156,7 @@
 */
 
     VTABLE PMC *get_pmc_keyed(PMC *key) {
-        Hash * const hash = PARROT_ADDRREGISTRY(SELF)->hash;
+        Hash * const hash = (Hash *)SELF.get_pointer();
 
         if (KEY_IS_HASH_ITERATOR(key))
             return (PMC *)parrot_hash_get_idx(INTERP, hash, key);

Modified: trunk/src/pmc/lexinfo.pmc
==============================================================================
--- trunk/src/pmc/lexinfo.pmc	Mon Mar 23 21:49:01 2009	(r37656)
+++ trunk/src/pmc/lexinfo.pmc	Mon Mar 23 22:39:14 2009	(r37657)
@@ -72,28 +72,14 @@
             (hash_comp_fn)Parrot_str_not_equal,     /* STRING compare */
             (hash_hash_key_fn)Parrot_str_to_hashval); /*        hash    */
 
-        PMC_struct_val(SELF) = hash;
-        hash->container      = SELF;
+        /* prevent set_pointer from trying to delete an invalid hash */
+        PMC_struct_val(SELF) = NULL;
+        SELF.set_pointer(hash);
         PObj_active_destroy_SET(SELF);
     }
 
 /*
 
-=item C<void destroy()>
-
-Frees any malloced memory held by this PMC.
-
-=cut
-
-*/
-
-    void destroy() {
-        if (PMC_struct_val(SELF))
-            parrot_hash_destroy(INTERP, (Hash *)PMC_struct_val(SELF));
-    }
-
-/*
-
 =item C<void declare_lex_preg(STRING *name, INTVAL preg)>
 
 Declare a lexical variable that is an alias for a PMC register.  The PIR
@@ -108,11 +94,11 @@
 */
 
     METHOD declare_lex_preg(STRING *name, INTVAL preg) {
-        parrot_hash_put(INTERP, (Hash*)PMC_struct_val(SELF), name, (void*)preg);
+        parrot_hash_put(INTERP, (Hash *)SELF.get_pointer(), name, (void*)preg);
     }
 
     VTABLE INTVAL elements() {
-        return parrot_hash_size(INTERP, (Hash *)PMC_struct_val(SELF));
+        return parrot_hash_size(INTERP, (Hash *)SELF.get_pointer());
     }
 
 
@@ -130,7 +116,7 @@
     VTABLE PMC *inspect_str(STRING *what) {
         if (Parrot_str_equal(interp, what, CONST_STRING(interp, "symbols"))) {
             PMC *result     = pmc_new(interp, enum_class_ResizableStringArray);
-            Hash *hash      = (Hash *)PMC_struct_val(SELF);
+            Hash *hash      = (Hash *)SELF.get_pointer();
             UINTVAL entries = hash->entries;
             UINTVAL found   = 0;
             INTVAL  i;
@@ -191,7 +177,7 @@
              */
 
             SELF.init_pmc(NULL);
-            hash          = (Hash *)PMC_struct_val(SELF);
+            hash          = (Hash *)SELF.get_pointer();
             hash->entries = elems;
         }
         else {

Modified: trunk/src/pmc/namespace.pmc
==============================================================================
--- trunk/src/pmc/namespace.pmc	Mon Mar 23 21:49:01 2009	(r37656)
+++ trunk/src/pmc/namespace.pmc	Mon Mar 23 22:39:14 2009	(r37657)
@@ -118,7 +118,6 @@
 } NS_slot_enum;
 
 #define FPA_is_ns_ext PObj_private0_FLAG
-#define NS_HASH(pmc) ((Hash *)PMC_struct_val(pmc))
 
 pmclass NameSpace extends Hash provides hash need_ext no_ro {
 
@@ -241,7 +240,7 @@
                               :value->vtable->base_type == enum_class_NameSpace;
 
         /* don't need this everywhere yet */
-        PMC *old = (PMC *)parrot_hash_get(INTERP, NS_HASH(SELF), key);
+        PMC *old = (PMC *)parrot_hash_get(INTERP, (Hash *)SELF.get_pointer(), key);
 
         /* If it's a sub... */
         if (!PMC_IS_NULL(value) && VTABLE_isa(INTERP, value, CONST_STRING(INTERP, "Sub"))) {
@@ -326,7 +325,7 @@
                 VTABLE_set_pmc_keyed_int(INTERP, new_tuple, NS_slot_var_sub,
                                          old);
 
-                parrot_hash_put(INTERP, NS_HASH(SELF), key, new_tuple);
+                parrot_hash_put(INTERP, (Hash *)SELF.get_pointer(), key, new_tuple);
                 /* distinction from a plain FPA, which doesn't extend the
                  * namespace storage */
             }
@@ -334,7 +333,7 @@
         else if (new_tuple) {
             VTABLE_set_pmc_keyed_int(INTERP, new_tuple, NS_slot_ns, old);
             VTABLE_set_pmc_keyed_int(INTERP, new_tuple, NS_slot_var_sub, value);
-            parrot_hash_put(INTERP, NS_HASH(SELF), key, new_tuple);
+            parrot_hash_put(INTERP, (Hash *)SELF.get_pointer(), key, new_tuple);
         }
     }
 
@@ -380,7 +379,7 @@
     }
 
     VTABLE PMC *get_pmc_keyed_str(STRING *key) {
-        PMC *ns = (PMC *)parrot_hash_get(INTERP, NS_HASH(SELF), key);
+        PMC *ns = (PMC *)parrot_hash_get(INTERP, (Hash *)SELF.get_pointer(), key);
 
         if (!ns)
             return PMCNULL;
@@ -445,7 +444,7 @@
 */
 
     VTABLE void *get_pointer_keyed_str(STRING *key) {
-        PMC *ns = (PMC *)parrot_hash_get(INTERP, NS_HASH(SELF), key);
+        PMC *ns = (PMC *)parrot_hash_get(INTERP, (Hash *)SELF.get_pointer(), key);
 
         /* Be extra careful about returning PMCNULL */
         if (! PMC_IS_NULL(ns)) {
@@ -660,7 +659,7 @@
 
     METHOD find_namespace(STRING *key) {
         STRING * const s_ns = CONST_STRING(INTERP, "NameSpace");
-        PMC    * const ns   = (PMC *)parrot_hash_get(INTERP, NS_HASH(SELF),
+        PMC    * const ns   = (PMC *)parrot_hash_get(INTERP, (Hash *)SELF.get_pointer(),
                                                      key);
 
         if (!ns)
@@ -685,7 +684,7 @@
 
     METHOD find_sub(STRING *key) {
         STRING * const s_sub = CONST_STRING(INTERP, "Sub");
-        PMC    * const sub   = (PMC *)parrot_hash_get(INTERP, NS_HASH(SELF),
+        PMC    * const sub   = (PMC *)parrot_hash_get(INTERP, (Hash *)SELF.get_pointer(),
                                                       key);
 
         if (!sub)
@@ -709,7 +708,7 @@
 */
 
     METHOD find_var(STRING *key) {
-        PMC * const val = (PMC *)parrot_hash_get(INTERP, NS_HASH(SELF), key);
+        PMC * const val = (PMC *)parrot_hash_get(INTERP, (Hash *)SELF.get_pointer(), key);
 
         if (!val)
             RETURN(PMC *PMCNULL);
@@ -730,7 +729,7 @@
 */
 
     METHOD del_namespace(STRING *name) {
-        Hash   * const hash = NS_HASH(SELF);
+        Hash   * const hash = (Hash *)SELF.get_pointer();
         PMC    * const ns   = (PMC *)parrot_hash_get(INTERP, hash, name);
         STRING * const s_ns = CONST_STRING(INTERP, "NameSpace");
 
@@ -758,7 +757,7 @@
 */
 
     METHOD del_sub(STRING *name) {
-        Hash   * const hash  = NS_HASH(SELF);
+        Hash   * const hash  = (Hash *)SELF.get_pointer();
         PMC    * const sub   = (PMC *)parrot_hash_get(INTERP, hash, name);
         STRING * const s_sub = CONST_STRING(INTERP, "Sub");
 
@@ -784,7 +783,7 @@
 */
 
     METHOD del_var(STRING *name) {
-        parrot_hash_delete(INTERP, NS_HASH(SELF), name);
+        parrot_hash_delete(INTERP, (Hash *)SELF.get_pointer(), name);
     }
 
 /*
@@ -799,7 +798,7 @@
 */
 
     METHOD get_sym(STRING *key) {
-        PMC *ns = (PMC *)parrot_hash_get(INTERP, NS_HASH(SELF), key);
+        PMC *ns = (PMC *)parrot_hash_get(INTERP, (Hash *)SELF.get_pointer(), key);
 
         if (!ns)
             RETURN(PMC *PMCNULL);

Modified: trunk/src/pmc/orderedhash.pmc
==============================================================================
--- trunk/src/pmc/orderedhash.pmc	Mon Mar 23 21:49:01 2009	(r37656)
+++ trunk/src/pmc/orderedhash.pmc	Mon Mar 23 22:39:14 2009	(r37657)
@@ -54,7 +54,7 @@
 */
 
     VTABLE void mark() {
-        Hash * const h = (Hash *)PMC_struct_val(SELF);
+        Hash * const h = (Hash *)SELF.get_pointer();
         INTVAL  i;
 
         if (!h)
@@ -90,7 +90,7 @@
 */
 
     VTABLE PMC *get_pmc_keyed_int(INTVAL idx) {
-        Hash * const h = (Hash *)PMC_struct_val(SELF);
+        Hash * const h = (Hash *)SELF.get_pointer();
         const INTVAL n = h->entries;
         HashBucket *b;
 
@@ -137,7 +137,7 @@
 */
 
     VTABLE STRING *get_string_keyed_int(INTVAL idx) {
-        Hash * const h = (Hash *)PMC_struct_val(SELF);
+        Hash * const h = (Hash *)SELF.get_pointer();
         const INTVAL n = h->entries;
 
         HashBucket *b;
@@ -186,7 +186,7 @@
 */
 
     VTABLE INTVAL get_integer_keyed_int(INTVAL idx) {
-        Hash * const h = (Hash *)PMC_struct_val(SELF);
+        Hash * const h = (Hash *)SELF.get_pointer();
         const INTVAL n = h->entries;
         HashBucket *b;
 
@@ -236,7 +236,7 @@
 */
 
     VTABLE FLOATVAL get_number_keyed_int(INTVAL idx) {
-        Hash * const h = (Hash *)PMC_struct_val(SELF);
+        Hash * const h = (Hash *)SELF.get_pointer();
         const INTVAL n = h->entries;
         HashBucket *b;
 
@@ -288,7 +288,7 @@
 */
 
     VTABLE void set_pmc_keyed_int(INTVAL idx, PMC *val) {
-        Hash * const     h = (Hash *)PMC_struct_val(SELF);
+        Hash * const     h = (Hash *)SELF.get_pointer();
         const INTVAL     n = h->entries;
         STRING * const fmt = CONST_STRING(INTERP, "\1%d");
 
@@ -379,7 +379,7 @@
 */
 
     VTABLE INTVAL exists_keyed_int(INTVAL idx) {
-        Hash * const h = (Hash *)PMC_struct_val(SELF);
+        Hash * const h = (Hash *)SELF.get_pointer();
         const INTVAL n = h->entries;
         HashBucket  *b;
 
@@ -401,7 +401,7 @@
         if (PObj_get_FLAGS(key) & KEY_integer_FLAG) {
             PMC        *item, *next;
             HashBucket *b;
-            Hash       * const h   = (Hash *)PMC_struct_val(SELF);
+            Hash       * const h   = (Hash *)SELF.get_pointer();
             INTVAL             idx = key_integer(INTERP, key);
             const INTVAL       n   = h->entries;
 
@@ -429,7 +429,7 @@
     }
 
     VTABLE INTVAL exists_keyed_str(STRING *key) {
-        const Hash * const       h = (Hash *)PMC_struct_val(SELF);
+        const Hash * const       h = (Hash *)SELF.get_pointer();
         const HashBucket * const b = parrot_hash_get_bucket(INTERP, h, key);
 
         return (b && b->key);
@@ -449,7 +449,7 @@
 
     VTABLE INTVAL defined_keyed(PMC *key) {
         if (PObj_get_FLAGS(key) & KEY_integer_FLAG) {
-            Hash * const h   = (Hash *)PMC_struct_val(SELF);
+            Hash * const h   = (Hash *)SELF.get_pointer();
             INTVAL       idx = key_integer(INTERP, key);
             const INTVAL n   = h->entries;
 
@@ -481,7 +481,7 @@
     }
 
     VTABLE INTVAL defined_keyed_int(INTVAL idx) {
-        Hash * const h = (Hash *)PMC_struct_val(SELF);
+        Hash * const h = (Hash *)SELF.get_pointer();
         const INTVAL n = h->entries;
         HashBucket  *b;
 
@@ -536,7 +536,7 @@
     }
 
     VTABLE void delete_keyed_int(INTVAL idx) {
-        Hash * const h = (Hash *)PMC_struct_val(SELF);
+        Hash * const h = (Hash *)SELF.get_pointer();
         const INTVAL n = h->entries;
         HashBucket  *b;
 
@@ -556,7 +556,7 @@
     }
 
     VTABLE void delete_keyed_str(STRING *key) {
-        const Hash * const h = (Hash *)PMC_struct_val(SELF);
+        const Hash * const h = (Hash *)SELF.get_pointer();
         HashBucket * const b = parrot_hash_get_bucket(INTERP, h, key);
 
         if (!b)
@@ -579,8 +579,8 @@
 
     VTABLE PMC *clone() {
         PMC  * const dest   = pmc_new(INTERP, SELF->vtable->base_type);
-        Hash * const hash   = (Hash *)PMC_struct_val(SELF);
-        Hash * const h_dest = (Hash *)PMC_struct_val(dest);
+        Hash * const hash   = (Hash *)SELF.get_pointer();
+        Hash * const h_dest = (Hash *)VTABLE_get_pointer(INTERP, dest);
         UINTVAL     i;
 
         for (i = 0; i <= N_BUCKETS(hash->mask-1); i++) {
@@ -627,7 +627,7 @@
             case VISIT_FREEZE_NORMAL:
             case VISIT_FREEZE_AT_DESTRUCT:
                 {
-                    Hash     * const hash = (Hash *)PMC_struct_val(SELF);
+                    Hash     * const hash = (Hash *)SELF.get_pointer();
                     IMAGE_IO * const io   = info->image_io;
                     UINTVAL i;
 


More information about the parrot-commits mailing list