Author: particle
Date: Thu Apr  5 11:00:44 2007
New Revision: 18003

Modified:
   trunk/src/pmc/exporter.pmc
   trunk/t/pmc/exporter.t

Log:
[pmc]: Exporter
~ 'destination' is now set to current namespace upon initialization
  (this is what you usually want)
~ 'globals' now supports either a space-separated string or a string array as 
input

Modified: trunk/src/pmc/exporter.pmc
==============================================================================
--- trunk/src/pmc/exporter.pmc  (original)
+++ trunk/src/pmc/exporter.pmc  Thu Apr  5 11:00:44 2007
@@ -29,7 +29,7 @@
 =item C<ns_dest>
 
 The destination namespace -- a NameSpace PMC.
-An empty PMC of this type is allocated upon initialization.
+A PMC representing the current namespace is allocated upon initialization.
 
 =item C<globals>
 
@@ -86,7 +86,7 @@
         /* Set up the object. */
         exp = mem_sys_allocate_zeroed(sizeof (Parrot_Exporter));
         exp->ns_src  = pmc_new(interp, enum_class_NameSpace);
-        exp->ns_dest = pmc_new(interp, enum_class_NameSpace);
+        exp->ns_dest = CONTEXT(interp->ctx)->current_namespace;
         exp->globals = PMCNULL;
         PMC_data(SELF) = exp;
     }
@@ -211,8 +211,6 @@
 If C<glb> is a String, it is split on ascii whitespace.
 If C<glb> is a FixedStringArray, it is cloned and set.
 
-TODO: get MMD working
-
 =cut
 
 */
@@ -220,24 +218,19 @@
     PCCMETHOD void globals(PMC *glb :optional, int got_glb :opt_flag) {
         Parrot_Exporter *exp = PARROT_EXPORTER(SELF);
         PMC *ret_globals;
+        STRING *s_str = CONST_STRING(interp, "String");
+        STRING *s_fsa = CONST_STRING(interp, "FixedStringArray");
 
         if (got_glb) {
-            if (PMC_IS_NULL(glb)) {
+            if (PMC_IS_NULL(glb))
                 exp->globals = PMCNULL;
-            }
-            else {
-/* xxx_MMD_FixedStringArray: { */
-                exp->globals = VTABLE_clone(interp, glb);
-/*                          }
-xxx_MMD_String: {
+            else if (VTABLE_isa(interp, glb, s_str))
                 exp->globals = string_split(interp, ' ', glb);
-            }
-xxx_MMD_DEFAULT: {
+            else if (VTABLE_isa(interp, glb, s_fsa))
+                exp->globals = VTABLE_clone(interp, glb);
+            else
                  real_exception(interp, NULL, 0,
-                         "unrecognized type in MMD dispatch");
-             }
-*/
-            }
+                     "Invalid type %d in globals()", glb->vtable->base_type);
          }
          else {
             if (PMC_IS_NULL(exp->globals)) {
@@ -257,7 +250,7 @@
     add_global(PMC *global :optional, int has_global :opt_flag)>
 
 Add C<global> to the array of globals (C<globals>.)
-Sets the array if C<glb_array> is passed, otherwise does nothing.
+Sets the array if C<global> is passed, otherwise does nothing.
 
 =cut
 

Modified: trunk/t/pmc/exporter.t
==============================================================================
--- trunk/t/pmc/exporter.t      (original)
+++ trunk/t/pmc/exporter.t      Thu Apr  5 11:00:44 2007
@@ -98,10 +98,16 @@
 .sub 'test' :main
     new $P0, .Exporter
     $P1 = $P0.'destination'()
-    if $P1 == '' goto ok_1
+    unless null $P1 goto ok_1
     print 'not '
   ok_1:
-    say 'ok 1 - destination() with no args returns destination namespace, 
which is empty at first'
+    say 'ok 1 - destination() with no args returns destination namespace'
+
+    $P99 = get_namespace
+    if $P1 == $P99 goto ok_2
+    print 'not '
+  ok_2:
+    say 'ok 2 - ...which is current namespace at first'
 
     # get a NameSpace PMC for testing
     # TODO replace with make_namespace, when implemented
@@ -110,28 +116,28 @@
 
     $P0.'destination'(ns)
     $P1 = $P0.'destination'()
-    if $P1 == 'Eponymous' goto ok_2
+    if $P1 == 'Eponymous' goto ok_3
     print 'not '
-  ok_2:
-    say 'ok 2 - destination() with args sets destination namespace'
+  ok_3:
+    say 'ok 3 - destination() with args sets destination namespace'
 
     $P1 = clone ns
 
-    push_eh ok_3
+    push_eh ok_4
     $P0.'destination'(ns, $P1)
     clear_eh
 
     print 'not '
-  ok_3:
-    say 'ok 3 - destination() with too many args fails'
+  ok_4:
+    say 'ok 4 - destination() with too many args fails'
 
-    push_eh ok_4
+    push_eh ok_5
     $P0.'destination'('foo')
     clear_eh
     print 'not '
 
-  ok_4:
-    say 'ok 4 - destination() with non-namespace arg throws exception'
+  ok_5:
+    say 'ok 5 - destination() with non-namespace arg throws exception'
 .end
 
 
@@ -140,10 +146,11 @@
 .sub 'Eponymous' :anon
 .end
 CODE
-ok 1 - destination() with no args returns destination namespace, which is 
empty at first
-ok 2 - destination() with args sets destination namespace
-ok 3 - destination() with too many args fails
-ok 4 - destination() with non-namespace arg throws exception
+ok 1 - destination() with no args returns destination namespace
+ok 2 - ...which is current namespace at first
+ok 3 - destination() with args sets destination namespace
+ok 4 - destination() with too many args fails
+ok 5 - destination() with non-namespace arg throws exception
 OUT
 
 

Reply via email to