[svn:parrot] r41856 - in branches/pcc_optimize_sig: src/pmc t/pmc

chromatic at svn.parrot.org chromatic at svn.parrot.org
Wed Oct 14 20:43:33 UTC 2009


Author: chromatic
Date: Wed Oct 14 20:43:31 2009
New Revision: 41856
URL: https://trac.parrot.org/parrot/changeset/41856

Log:
[PMC] Added exists_keyed() and exists_keyed_int() VTABLE entries to
CallSignature PMC, including tests for truth and falseness.  Modified tests to
check for boolean return values, not any specific value.

Modified:
   branches/pcc_optimize_sig/src/pmc/callsignature.pmc
   branches/pcc_optimize_sig/t/pmc/callsignature.t

Modified: branches/pcc_optimize_sig/src/pmc/callsignature.pmc
==============================================================================
--- branches/pcc_optimize_sig/src/pmc/callsignature.pmc	Wed Oct 14 19:15:52 2009	(r41855)
+++ branches/pcc_optimize_sig/src/pmc/callsignature.pmc	Wed Oct 14 20:43:31 2009	(r41856)
@@ -1035,6 +1035,26 @@
         return PMCNULL;
     }
 
+    VTABLE INTVAL exists_keyed(PMC *key) {
+        Hash *hash = get_hash(interp, SELF);
+
+        if (hash) {
+            void     *k = hash_key_from_pmc(interp, hash, key);
+            return parrot_hash_exists(interp, hash, k);
+        }
+
+        return 0;
+    }
+
+    VTABLE INTVAL exists_keyed_int(INTVAL key) {
+        Parrot_CallSignature_attributes * const attrs = PARROT_CALLSIGNATURE(SELF);
+
+        if (attrs->num_positionals)
+            return key < attrs->num_positionals;
+
+        return 0;
+    }
+
 /*
 
 =back

Modified: branches/pcc_optimize_sig/t/pmc/callsignature.t
==============================================================================
--- branches/pcc_optimize_sig/t/pmc/callsignature.t	Wed Oct 14 19:15:52 2009	(r41855)
+++ branches/pcc_optimize_sig/t/pmc/callsignature.t	Wed Oct 14 20:43:31 2009	(r41856)
@@ -19,7 +19,7 @@
 .sub 'main' :main
     .include 'test_more.pir'
 
-    plan(63)
+    plan(65)
 
     test_instantiate()
     test_get_set_attrs()
@@ -273,11 +273,16 @@
     $P0['foo'] = 100
 
     $I0 = exists $P0[0]
-    is( $I0, 100, 'exists_keyed_int' )
+    ok( $I0, 'exists_keyed_int' )
 
     $I0 = exists $P0['foo']
-    is( $I0, 100, 'exists_keyed_str' )
+    ok( $I0, 'exists_keyed_str' )
 
+    $I0 = exists $P0[100]
+    nok( $I0, 'exists_keyed_int -- non-existant' )
+
+    $I0 = exists $P0['bar']
+    nok( $I0, 'exists_keyed_str -- non-existant' )
 .end
 
 # Local Variables:


More information about the parrot-commits mailing list