Front page | perl.cvs.parrot |
Postings from December 2008
[svn:parrot] r34706 - in trunk: include/parrot src src/pmc t/oo
From:
tewk
Date:
December 31, 2008 07:41
Subject:
[svn:parrot] r34706 - in trunk: include/parrot src src/pmc t/oo
Message ID:
20081231154147.B845ECB9FA@x12.develooper.com
Author: tewk
Date: Wed Dec 31 07:41:46 2008
New Revision: 34706
Modified:
trunk/include/parrot/oo.h
trunk/include/parrot/pmc.h
trunk/src/oo.c
trunk/src/pmc.c
trunk/src/pmc/class.pmc
trunk/t/oo/names.t
Log:
[class registry] Round 1 duplicate named class names now allowed, fist one in is the winner
Modified: trunk/include/parrot/oo.h
==============================================================================
--- trunk/include/parrot/oo.h (original)
+++ trunk/include/parrot/oo.h Wed Dec 31 07:41:46 2008
@@ -198,9 +198,10 @@
__attribute__nonnull__(2);
PARROT_WARN_UNUSED_RESULT
-INTVAL Parrot_oo_register_type(PARROT_INTERP, ARGIN(PMC *name))
+INTVAL Parrot_oo_register_type(PARROT_INTERP, ARGIN(PMC *name), ARGIN(PMC *name_space))
__attribute__nonnull__(1)
- __attribute__nonnull__(2);
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3);
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/oo.c */
Modified: trunk/include/parrot/pmc.h
==============================================================================
--- trunk/include/parrot/pmc.h (original)
+++ trunk/include/parrot/pmc.h Wed Dec 31 07:41:46 2008
@@ -69,6 +69,10 @@
PMC * pmc_new_noinit(PARROT_INTERP, INTVAL base_type)
__attribute__nonnull__(1);
+INTVAL
+get_new_vtable_index(PARROT_INTERP)
+ __attribute__nonnull__(1);
+
PARROT_EXPORT
INTVAL pmc_register(PARROT_INTERP, ARGIN(STRING *name))
__attribute__nonnull__(1)
Modified: trunk/src/oo.c
==============================================================================
--- trunk/src/oo.c (original)
+++ trunk/src/oo.c Wed Dec 31 07:41:46 2008
@@ -45,7 +45,7 @@
__attribute__nonnull__(2)
__attribute__nonnull__(3);
-static void fail_if_type_exists(PARROT_INTERP, ARGIN(PMC *name))
+static INTVAL fail_if_type_exists(PARROT_INTERP, ARGIN(PMC *name))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
@@ -494,48 +494,35 @@
*/
-static void
+static INTVAL
fail_if_type_exists(PARROT_INTERP, ARGIN(PMC *name))
{
- INTVAL type;
-
- PMC * const classname_hash = interp->class_hash;
- PMC * const type_pmc = (PMC *)VTABLE_get_pointer_keyed(interp,
- classname_hash, name);
-
- if (PMC_IS_NULL(type_pmc)
- || type_pmc->vtable->base_type == enum_class_NameSpace)
- type = 0;
- else
- type = VTABLE_get_integer(interp, type_pmc);
+ PMC * const value = (PMC *)VTABLE_get_pointer_keyed(interp, interp->class_hash, name);
- if (type > enum_type_undef) {
- STRING *classname;
-
- if (VTABLE_isa(interp, name, CONST_STRING(interp, "ResizableStringArray"))) {
- PMC * const base_ns = VTABLE_get_pmc_keyed_int(interp,
- interp->HLL_namespace,
- CONTEXT(interp)->current_HLL);
- PMC *ns = Parrot_get_namespace_keyed(interp,
- base_ns, name);
-
- if (!PMC_IS_NULL(ns))
- classname = VTABLE_get_string(interp, ns);
- else
- classname = CONST_STRING(interp, "");
- }
- else
- classname = VTABLE_get_string(interp, name);
+ if (PMC_IS_NULL(value))
+ return 0;
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
- "Class %Ss already registered!\n",
- string_escape_string(interp, classname));
+ switch (VTABLE_type(interp, value)) {
+ case enum_class_NameSpace:
+ return 0;
+ break;
+ case enum_class_Integer:
+ {
+ const INTVAL type = VTABLE_get_integer(interp, value);
+ if (type < enum_type_undef) {
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
+ "native type with name '%s' already exists - "
+ "can't register Class", data_types[type].name);
+ }
+ return type;
+ }
+ break;
+ default:
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INTERP_ERROR,
+ "Unrecognized class name PMC type");
+ break;
}
-
- if (type < enum_type_undef)
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
- "native type with name '%s' already exists - "
- "can't register Class", data_types[type].name);
+ return 0;
}
@@ -553,29 +540,35 @@
PARROT_WARN_UNUSED_RESULT
INTVAL
-Parrot_oo_register_type(PARROT_INTERP, ARGIN(PMC *name))
+Parrot_oo_register_type(PARROT_INTERP, ARGIN(PMC *name), ARGIN(PMC *namespace))
{
INTVAL type;
- PMC *classname_hash, *item;
+ const INTVAL typeid_exists = fail_if_type_exists(interp, name);
- fail_if_type_exists(interp, name);
+ PMC *classobj = VTABLE_get_class(interp, namespace);
+ if (!PMC_IS_NULL(classobj)) {
+ STRING *classname = VTABLE_get_string(interp, namespace);
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
+ "Class %Ss already registered!\n",
+ string_escape_string(interp, classname));
+ }
/* Type doesn't exist, so go ahead and register it. Lock interpreter so
* pt_shared_fixup() can safely do a type lookup. */
LOCK_INTERPRETER(interp);
- classname_hash = interp->class_hash;
-
- type = interp->n_vtable_max++;
-
- /* Have we overflowed the table? */
- if (type >= interp->n_vtable_alloced)
- parrot_realloc_vtables(interp);
-
- /* set entry in name->type hash */
- item = pmc_new(interp, enum_class_Integer);
- PMC_int_val(item) = type;
+ {
+ type = get_new_vtable_index(interp);
+ }
+ {
+ if (!typeid_exists) {
+ PMC *classname_hash = interp->class_hash;
+ /* set entry in name->type hash */
+ PMC *item = pmc_new(interp, enum_class_Integer);
+ PMC_int_val(item) = type;
- VTABLE_set_pmc_keyed(interp, classname_hash, name, item);
+ VTABLE_set_pmc_keyed(interp, classname_hash, name, item);
+ }
+ }
UNLOCK_INTERPRETER(interp);
return type;
Modified: trunk/src/pmc.c
==============================================================================
--- trunk/src/pmc.c (original)
+++ trunk/src/pmc.c Wed Dec 31 07:41:46 2008
@@ -505,13 +505,21 @@
=cut
*/
+INTVAL
+get_new_vtable_index(PARROT_INTERP) {
+ const INTVAL typeid = interp->n_vtable_max++;
+
+ /* Have we overflowed the table? */
+ if (typeid >= interp->n_vtable_alloced)
+ parrot_realloc_vtables(interp);
+
+ return typeid;
+}
PARROT_EXPORT
INTVAL
pmc_register(PARROT_INTERP, ARGIN(STRING *name))
{
- PMC *classname_hash;
-
/* If they're looking to register an existing class, return that
class' type number */
INTVAL type = pmc_type(interp, name);
@@ -523,15 +531,10 @@
Parrot_ex_throw_from_c_args(interp, NULL, 1,
"undefined type already exists - can't register PMC");
- classname_hash = interp->class_hash;
- type = interp->n_vtable_max++;
-
- /* Have we overflowed the table? */
- if (type >= interp->n_vtable_alloced)
- parrot_realloc_vtables(interp);
+ type = get_new_vtable_index(interp);
/* set entry in name->type hash */
- VTABLE_set_integer_keyed_str(interp, classname_hash, name, type);
+ VTABLE_set_integer_keyed_str(interp, interp->class_hash, name, type);
return type;
}
Modified: trunk/src/pmc/class.pmc
==============================================================================
--- trunk/src/pmc/class.pmc (original)
+++ trunk/src/pmc/class.pmc Wed Dec 31 07:41:46 2008
@@ -217,7 +217,7 @@
CLASS_is_anon_CLEAR(self);
/* Register a type number for the class. */
- type_num = Parrot_oo_register_type(interp, name_arg);
+ type_num = Parrot_oo_register_type(interp, name_arg, new_namespace);
/* Link the type number with the class's vtable. */
new_vtable = Parrot_clone_vtable(interp, self->vtable);
Modified: trunk/t/oo/names.t
==============================================================================
--- trunk/t/oo/names.t (original)
+++ trunk/t/oo/names.t Wed Dec 31 07:41:46 2008
@@ -44,10 +44,10 @@
$P0.'name'('Object')
pop_eh
$S0 = $P0
- ok (0, 'HLL obj created w/ same name as parrot obj')
+ ok (1, 'HLL obj created w/ same name as parrot obj')
.return()
OK_1:
- ok (1, 'HLL obj w/ same name as parrot obj not created')
+ ok (0, 'HLL obj w/ same name as parrot obj not created')
.end
# Local Variables:
-
[svn:parrot] r34706 - in trunk: include/parrot src src/pmc t/oo
by tewk