The enclosed patch allows one to use the if op with a PerlArray,
 as in:

        new P0, PerlArray
        if P0, TRUE
        print "false\n"
        end

TRUE:   print "true\n"
        end

 Currently, this works the same way that if(@array) does in Perl, ie
 it's false if and only if the array has a length of zero. Patch also
 includes the appropriate regression test.

 It should be straightforward to add this to PerlHash as well, but my 
 attempt to do so seems to have brought some bugs to light - currently
 investigating this.

 Simon

--- default.pmc.old     Sat Jan  5 08:00:01 2002
+++ default.pmc Thu Jan 10 15:39:11 2002
@@ -69,10 +69,10 @@
    }
 
    BOOLVAL get_bool () {
-     /*  Everything has to be true */
+     /*  Everything has to be false */
      if (   SELF->vtable->get_integer(INTERP, SELF) == 0 
         && SELF->vtable->get_number(INTERP, SELF) == 0.0
-        && string_bool(SELF->vtable->get_string(INTERP, SELF))
+        && string_bool(SELF->vtable->get_string(INTERP, SELF)) == 0
            )
        {
         return 0;

--- perlarray.pmc.old   Thu Jan 10 02:00:02 2002
+++ perlarray.pmc       Thu Jan 10 15:38:08 2002
@@ -86,8 +86,7 @@
        return key_pair->cache.struct_val;
     }
 
-    BOOLVAL get_bool () {
-    }
+    BOOLVAL get_bool () = default;
 
     void* get_value () {
         return &SELF->cache;

--- pmc_perlarray.t.old Thu Jan 10 15:41:40 2002
+++ pmc_perlarray.t     Thu Jan 10 16:06:30 2002
@@ -1,6 +1,6 @@
 #! perl -w
 
-use Parrot::Test tests => 3;
+use Parrot::Test tests => 4;
 
 output_is(<<'CODE', <<'OUTPUT', "size of the array");
        new P0,PerlArray
@@ -76,5 +76,38 @@
 hey
 OUTPUT
 
+output_is(<<'CODE', <<'OUTPUT', "If P");
+        new P0, PerlArray
+        if P0, TR
+        print "false\n"
+        branch NEXT   
+TR:     print "true\n"
+
+NEXT:   set P0, 1, 0
+        if P0, TR2
+        print "false\n"
+        branch NEXT2
+TR2:    print "true\n"
+
+NEXT2:  new P1, PerlArray
+        set P1, 1
+        if P1, TR3
+        print "false\n"
+        branch NEXT3
+TR3:    print "true\n"
+
+NEXT3:  set P1, 0
+        if P1, TR4
+        print "false\n"
+        end
+TR4:    print "true\n"        
+        end
+
+CODE
+false
+true
+true
+false
+OUTPUT
 
 1;

 

 
  



Reply via email to