[svn:parrot] r49470 - trunk/src/pmc
cotto at svn.parrot.org
cotto at svn.parrot.org
Thu Oct 7 22:07:29 UTC 2010
Author: cotto
Date: Thu Oct 7 22:07:28 2010
New Revision: 49470
URL: https://trac.parrot.org/parrot/changeset/49470
Log:
[pmc] make AddrRegistry able to hold and mark both STRINGs and PMCs
Modified:
trunk/src/pmc/addrregistry.pmc
Modified: trunk/src/pmc/addrregistry.pmc
==============================================================================
--- trunk/src/pmc/addrregistry.pmc Thu Oct 7 22:06:32 2010 (r49469)
+++ trunk/src/pmc/addrregistry.pmc Thu Oct 7 22:07:28 2010 (r49470)
@@ -32,7 +32,10 @@
/* HEADERIZER BEGIN: static */
/* HEADERIZER END: static */
-pmclass AddrRegistry extends Hash provides hash auto_attrs {
+pmclass AddrRegistry provides hash auto_attrs {
+ATTR Hash *pmc_registry;
+ATTR Hash *str_registry;
+
/*
=item C<void init()>
@@ -44,17 +47,71 @@
*/
VTABLE void init() {
- Hash *registry = parrot_create_hash(INTERP,
+ Hash *pmc_registry = parrot_create_hash(INTERP,
enum_type_int,
Hash_key_type_PMC_ptr);
- SET_ATTR_hash(INTERP, SELF, registry);
+ Hash *str_registry = parrot_create_hash(INTERP,
+ enum_type_int,
+ Hash_key_type_STRING);
+
+ SET_ATTR_pmc_registry(INTERP, SELF, pmc_registry);
+ SET_ATTR_str_registry(INTERP, SELF, str_registry);
PObj_custom_mark_destroy_SETALL(SELF);
}
/*
+=item C<void mark()>
+
+Mark any PMCs and STRINGs in this registry.
+
+=cut
+
+*/
+
+
+ VTABLE void mark() {
+ Hash *str_registry, *pmc_registry;
+
+ GET_ATTR_str_registry(INTERP, SELF, str_registry);
+ GET_ATTR_pmc_registry(INTERP, SELF, pmc_registry);
+
+ parrot_mark_hash(interp, pmc_registry);
+ parrot_mark_hash(interp, str_registry);
+
+ }
+
+
+/*
+
+=item C<void destroy()>
+
+Destroy this PMC.
+
+=cut
+
+*/
+
+ VTABLE void destroy() {
+ Hash *str_registry, *pmc_registry;
+
+ GET_ATTR_str_registry(INTERP, SELF, str_registry);
+ GET_ATTR_pmc_registry(INTERP, SELF, pmc_registry);
+
+ parrot_hash_destroy(interp, pmc_registry);
+ parrot_hash_destroy(interp, str_registry);
+
+ SET_ATTR_str_registry(INTERP, SELF, NULL);
+ SET_ATTR_pmc_registry(INTERP, SELF, NULL);
+
+ }
+
+
+
+/*
+
=item C<INTVAL get_integer_keyed(PMC *key)>
Returns the reference count for C<key> or 0 if the key doesn't exist.
@@ -75,7 +132,7 @@
Hash *hash;
const void *value;
- GET_ATTR_hash(INTERP, SELF, hash);
+ GET_ATTR_pmc_registry(INTERP, SELF, hash);
value = parrot_hash_get(INTERP, hash, key);
if (value)
@@ -85,19 +142,23 @@
}
VTABLE INTVAL elements() {
- const Hash *hash;
+ const Hash *pmc_registry, *str_registry;
- GET_ATTR_hash(INTERP, SELF, hash);
+ GET_ATTR_pmc_registry(INTERP, SELF, pmc_registry);
+ GET_ATTR_str_registry(INTERP, SELF, str_registry);
- return parrot_hash_size(INTERP, hash);
+ return parrot_hash_size(INTERP, pmc_registry) +
+ parrot_hash_size(INTERP, str_registry);
}
VTABLE INTVAL get_bool() {
- const Hash *hash;
+ const Hash *pmc_registry, *str_registry;
- GET_ATTR_hash(INTERP, SELF, hash);
+ GET_ATTR_pmc_registry(INTERP, SELF, pmc_registry);
+ GET_ATTR_str_registry(INTERP, SELF, str_registry);
- return parrot_hash_size(INTERP, hash) != 0;
+ return (parrot_hash_size(INTERP, pmc_registry) +
+ parrot_hash_size(INTERP, str_registry)) != 0;
}
/*
@@ -112,6 +173,8 @@
=item C<void delete_keyed(PMC *key)>
+=item C<void delete_keyed_str(STRING *key)>
+
Decrement the reference count of C<key>. If the reference count
reaches 0, delete the entry.
@@ -126,7 +189,23 @@
Hash *hash;
UNUSED(value);
- GET_ATTR_hash(INTERP, SELF, hash);
+ GET_ATTR_pmc_registry(INTERP, SELF, hash);
+
+ oldval = parrot_hash_get(INTERP, hash, key);
+
+ if (oldval)
+ newval += (long)oldval;
+
+ parrot_hash_put(INTERP, hash, key, (void *)newval);
+ }
+
+ VTABLE void set_pmc_keyed_str(STRING *key, PMC *value) {
+ const void *oldval;
+ long newval = 1;
+ Hash *hash;
+ UNUSED(value);
+
+ GET_ATTR_str_registry(INTERP, SELF, hash);
oldval = parrot_hash_get(INTERP, hash, key);
@@ -138,7 +217,7 @@
VTABLE void set_integer_keyed(PMC *key, INTVAL value) {
Hash *hash;
- GET_ATTR_hash(INTERP, SELF, hash);
+ GET_ATTR_pmc_registry(INTERP, SELF, hash);
parrot_hash_put(INTERP, hash, key, (void *)value);
}
@@ -146,7 +225,26 @@
Hash *hash;
void *value;
- GET_ATTR_hash(INTERP, SELF, hash);
+ GET_ATTR_pmc_registry(INTERP, SELF, hash);
+ value = parrot_hash_get(INTERP, hash, key);
+
+ /* these casts look bad, but they avoid type punning warnings with -O */
+ if (value) {
+ long val = (long)value;
+ if (val == 1L)
+ parrot_hash_delete(INTERP, hash, key);
+ else {
+ value = (void *)(--val);
+ parrot_hash_put(INTERP, hash, key, value);
+ }
+ }
+ }
+
+ VTABLE void delete_keyed_str(STRING *key) {
+ Hash *hash;
+ void *value;
+
+ GET_ATTR_str_registry(INTERP, SELF, hash);
value = parrot_hash_get(INTERP, hash, key);
/* these casts look bad, but they avoid type punning warnings with -O */
More information about the parrot-commits
mailing list