Author: jonathan
Date: Mon Apr 9 16:05:48 2007
New Revision: 18094
Modified:
trunk/src/pmc/class.pmc
trunk/src/pmc/namespace.pmc
trunk/src/pmc/role.pmc
Log:
[PDD15]: Initial work on associating classes with namespaces. Add get_class and
set_class methods to the NameSpace PMC (may have to change later), then use
these from Class and Role PMCs. Make .namespace accept a NameSpace, Key or
String PMC for both Class and Role and lookup as required.
Modified: trunk/src/pmc/class.pmc
==============================================================================
--- trunk/src/pmc/class.pmc (original)
+++ trunk/src/pmc/class.pmc Mon Apr 9 16:05:48 2007
@@ -484,25 +484,47 @@
PMC *ret_namespace = NULL;
if (got_name) {
- /* Check namespace is a key. */
- if (namespace->vtable->base_type != enum_class_Key)
- {
- real_exception(interp, NULL, E_NameError, "Namespace must be a
key");
- return;
+ /* If namespace is a key or a string, need to look it up. */
+ switch (namespace->vtable->base_type) {
+ case enum_class_NameSpace:
+ /* It's fine, don't need to do anything. */
+ break;
+ case enum_class_Key:
+ /* Look it up relative to HLL base. */
+ namespace = Parrot_get_namespace_keyed(interp,
+ interp->HLL_namespace, namespace);
+ if (PMC_IS_NULL(namespace))
+ real_exception(interp, NULL, E_NameError, "Namespace
cannot be found");
+ break;
+ case enum_class_String:
+ /* Look it up relative to current namespace. */
+ namespace = Parrot_get_namespace_keyed_str(interp,
+ CONTEXT(interp->ctx)->current_namespace,
+ VTABLE_get_string(interp, namespace));
+ if (PMC_IS_NULL(namespace))
+ real_exception(interp, NULL, E_NameError, "Namespace
cannot be found");
+ break;
+ default:
+ /* Don't know what to do with it. */
+ real_exception(interp, NULL, E_NameError, "Namespace must
be a key");
}
/* If we already have a namespace, it shouldn't refer to the
class any more. */
if (class->namespace)
{
- /* XXX */
+ PMC *class_ns = class->namespace;
+ PCCINVOKE(interp, class_ns, "set_class", PMC* PMCNULL);
}
/* Set namespace. */
class->namespace = Parrot_get_namespace_keyed(interp,
interp->HLL_namespace, namespace);
- /* XXX Link namespace to this class; currently missing slot for
that. */
+ /* Link namespace to this class. */
+ PCCINVOKE(interp, namespace, "set_class", PMC* SELF);
+
+ /* XXX Get methods from the namespace we were linked to. */
}
ret_namespace = class->namespace;
Modified: trunk/src/pmc/namespace.pmc
==============================================================================
--- trunk/src/pmc/namespace.pmc (original)
+++ trunk/src/pmc/namespace.pmc Mon Apr 9 16:05:48 2007
@@ -632,6 +632,38 @@
return PMC_pmc_val(SELF) ? PMC_pmc_val(SELF) : PMCNULL;
}
+/*
+
+=item C<METHOD PMC* get_class()>
+
+Returns the class or role PMC that is associated with this namespace.
+
+=cut
+
+*/
+
+ METHOD PMC* get_class()
+ {
+ Parrot_NSInfo *nsinfo = PARROT_NSINFO(SELF);
+ return nsinfo->class;
+ }
+
+/*
+
+=item C<METHOD void set_class(PMC *class_or_role)>
+
+Sets the class or role PMC that is associated with this namespace.
+
+=cut
+
+*/
+
+ METHOD set_class(PMC *class_or_role)
+ {
+ Parrot_NSInfo *nsinfo = PARROT_NSINFO(SELF);
+ nsinfo->class = class_or_role;
+ }
+
}
/*
Modified: trunk/src/pmc/role.pmc
==============================================================================
--- trunk/src/pmc/role.pmc (original)
+++ trunk/src/pmc/role.pmc Mon Apr 9 16:05:48 2007
@@ -313,6 +313,31 @@
PMC *ret_namespace = NULL;
if (got_name) {
+ /* If namespace is a key or a string, need to look it up. */
+ switch (namespace->vtable->base_type) {
+ case enum_class_NameSpace:
+ /* It's fine, don't need to do anything. */
+ break;
+ case enum_class_Key:
+ /* Look it up relative to HLL base. */
+ namespace = Parrot_get_namespace_keyed(interp,
+ interp->HLL_namespace, namespace);
+ if (PMC_IS_NULL(namespace))
+ real_exception(interp, NULL, E_NameError, "Namespace
cannot be found");
+ break;
+ case enum_class_String:
+ /* Look it up relative to current namespace. */
+ namespace = Parrot_get_namespace_keyed_str(interp,
+ CONTEXT(interp->ctx)->current_namespace,
+ VTABLE_get_string(interp, namespace));
+ if (PMC_IS_NULL(namespace))
+ real_exception(interp, NULL, E_NameError, "Namespace
cannot be found");
+ break;
+ default:
+ /* Don't know what to do with it. */
+ real_exception(interp, NULL, E_NameError, "Namespace must
be a key");
+ }
+
/* Check namespace is a key. */
if (namespace->vtable->base_type != enum_class_Key)
{
@@ -324,14 +349,18 @@
role any more. */
if (role->namespace)
{
- /* XXX */
+ PMC *role_ns = role->namespace;
+ PCCINVOKE(interp, role_ns, "set_class", PMC* PMCNULL);
}
/* Set namespace. */
role->namespace = Parrot_get_namespace_keyed(interp,
interp->HLL_namespace, namespace);
- /* XXX Link namespace to this role; currently missing slot for
that. */
+ /* Link namespace to this role. */
+ PCCINVOKE(interp, namespace, "set_class", PMC* SELF);
+
+ /* XXX Get methods from the namespace we were linked to. */
}
ret_namespace = role->namespace;