find_global throws an exception even if the variable in that entry is
undef, which is just silly.   This patch fixes it to only throw an
exception when it hasn't actually been store_global'd.

I personally think that it should never throw an exception -- that it
should always just return undef if the variable wasn't defined.  OTOH,
some languages like to know whether a variable exists.  I think a nice
solution would be to give the program access to the stash PMC, and then
they can do whatever they like to it.

Luke


Index: var.ops
===================================================================
RCS file: /cvs/public/parrot/var.ops,v
retrieving revision 1.7
diff -u -r1.7 var.ops
--- var.ops     23 Aug 2003 15:41:31 -0000      1.7
+++ var.ops     28 Aug 2003 11:03:11 -0000
@@ -250,16 +250,19 @@
 
 op find_global(out PMC, in STR) {
     opcode_t * resume;
+    PMC* key = key_new_string(interpreter, $2);
     if (!$2)
         internal_exception(1, "Tried to get null global.");
-    $1 = VTABLE_get_pmc_keyed(interpreter,
-                               interpreter->perl_stash->stash_hash,
-                               key_new_string(interpreter, $2));
+    
     resume = expr NEXT();
-    /* XXX doesn't work if the global is an undefined var */
-    if (!VTABLE_defined(interpreter, $1))
+    if (!VTABLE_exists_keyed(interpreter,
+                       interpreter->perl_stash->stash_hash, key)) 
         real_exception(interpreter, resume, GLOBAL_NOT_FOUND,
-            "Global '%s' not found", string_to_cstring(interpreter, $2));
+                "Global '%s' not found\n", string_to_cstring(interpreter, $2));
+                       
+    $1 = VTABLE_get_pmc_keyed(interpreter,
+                               interpreter->perl_stash->stash_hash, key);
+
     restart ADDRESS(resume);
 }
 

Reply via email to