Author: jonathan
Date: Sat Apr 14 16:45:41 2007
New Revision: 18210

Modified:
   trunk/include/parrot/global.h
   trunk/src/global.c

Log:
[PDD15]: Implement a couple of new namespace lookup functions that 
automatically choose the base namespace depending on what type of lookup is 
being done. This will be used in at least a couple of places in PDD15 
implementation.

Modified: trunk/include/parrot/global.h
==============================================================================
--- trunk/include/parrot/global.h       (original)
+++ trunk/include/parrot/global.h       Sat Apr 14 16:45:41 2007
@@ -19,6 +19,9 @@
 PARROT_API PMC *Parrot_make_namespace_keyed(Interp *, PMC *base_ns, PMC 
*pmc_key);
 PARROT_API PMC *Parrot_make_namespace_keyed_str(Interp *, PMC *base_ns, STRING 
*str_key);
 
+PARROT_API PMC *Parrot_get_namespace_autobase(Interp *interp, PMC *key);
+PARROT_API PMC *Parrot_make_namespace_autobase(Interp *interp, PMC *key);
+
 /*
  * {get,set}_global.
  *

Modified: trunk/src/global.c
==============================================================================
--- trunk/src/global.c  (original)
+++ trunk/src/global.c  Sat Apr 14 16:45:41 2007
@@ -158,6 +158,52 @@
 /*
 
 =item C<PMC *
+Parrot_get_namespace_autobase(Interp *, PMC *key)>
+
+Find a namespace with the key C<key>, which may be a String, a Key, or an
+array of strings. If it is a String, then the lookup is relative to the
+current namespace. Otherwise, it is relative to the current HLL root
+namespace. Return the namespace, or NULL if not found.
+
+=item C<PMC *
+Parrot_make_namespace_autobase(Interp *, PMC *pmc_key)>
+
+Find, or create if necessary, a namespace with the key C<key>, which may be a
+String, a Key, or an array of strings. If it is a String, then the lookup is
+relative to the current namespace. Otherwise, it is relative to the current HLL
+root namespace. Return the namespace.  Errors will result in exceptions.
+
+=cut
+
+*/
+
+
+PMC *
+Parrot_make_namespace_autobase(Interp *interp, PMC *key)
+{
+    PMC *base_ns;
+    if (VTABLE_isa(interp, key, string_from_const_cstring(interp, "String", 
0)))
+        base_ns = CONTEXT(interp->ctx)->current_namespace;
+    else
+        base_ns = interp->HLL_namespace;
+    return Parrot_make_namespace_keyed(interp, base_ns, key);
+}
+
+PMC *
+Parrot_get_namespace_autobase(Interp *interp, PMC *key)
+{
+    PMC *base_ns;
+    if (VTABLE_isa(interp, key, string_from_const_cstring(interp, "String", 
0)))
+        base_ns = CONTEXT(interp->ctx)->current_namespace;
+    else
+        base_ns = interp->HLL_namespace;
+    return Parrot_get_namespace_keyed(interp, base_ns, key);
+}
+
+
+/*
+
+=item C<PMC *
 Parrot_get_global(Interp *, PMC *ns, STRING *globalname)>
 
 Look up the global named C<globalname> in the namespace C<ns>.  Return the

Reply via email to