Hmph.  I thought I already sent that message correcting that error in
the cmp ops.

Anyway, here's the corrected one with a couple tests (which I should
have written in the first place).

Index: core.ops
===================================================================
RCS file: /cvs/public/parrot/core.ops,v
retrieving revision 1.274
diff -u -r1.274 core.ops
--- core.ops    30 May 2003 01:06:23 -0000      1.274
+++ core.ops    8 Jun 2003 05:45:43 -0000
@@ -688,6 +688,43 @@
 
 =cut
 
+########################################
+
+=item B<cmp>(out INT, in INT, in INT)
+
+=item B<cmp>(out INT, in NUM, in NUM)
+
+=item B<cmp>(out INT, in STR, in STR)
+
+=item B<cmp>(out INT, in PMC, in PMC)
+
+Sets $1 to -1 if $2 < $3, +1 if $2 > $3, and 0 otherwise.
+
+=cut
+
+inline op cmp(out INT, in INT, in INT) {
+  $1 = $2 < $3 ? -1 :
+       $2 > $3 ? +1 :
+       0;
+  goto NEXT();
+}
+
+inline op cmp(out INT, in NUM, in NUM) {
+  $1 = $2 < $3 ? -1 :
+       $2 > $3 ? +1 :
+       0;
+  goto NEXT();
+}
+
+inline op cmp(out INT, in STR, in STR) {
+  $1 = string_compare(interpreter, $2, $3);
+  goto NEXT();
+}
+
+inline op cmp(out INT, in PMC, in PMC) {
+  $1 = VTABLE_cmp(interpreter, $2, $3);
+  goto NEXT();
+}
 
 ########################################
 
Index: t/op/comp.t
===================================================================
RCS file: /cvs/public/parrot/t/op/comp.t,v
retrieving revision 1.1
diff -u -r1.1 comp.t
--- t/op/comp.t 9 Nov 2002 12:42:55 -0000       1.1
+++ t/op/comp.t 8 Jun 2003 05:45:43 -0000
@@ -1,6 +1,6 @@
 #! perl -w
 
-use Parrot::Test tests => 6;
+use Parrot::Test tests => 7;
 
 # some of these were failing with JIT/i386
 
@@ -135,6 +135,34 @@
 ok 1
 ok 2
 ok 3
+OUTPUT
+
+output_is(<<'CODE', <<OUTPUT, "cmp");
+        set I0, 10
+        cmp I1, I0, 9
+        set N0, -2.4
+        cmp I2, -2.4, N0
+        set S0, "Bruhaha"
+        cmp I3, S0, "Crumbum"
+        new P0, .PerlInt
+        new P1, .PerlInt
+        set P0, 452
+        set P1, -15
+        cmp I4, P0, P1
+
+        print I1
+        print "\n"
+        print I2
+        print "\n"
+        print I3
+        print "\n"
+        print I4
+        print "\n"
+CODE
+1
+0
+-1
+1
 OUTPUT
 
 1;

Reply via email to