cvsuser 03/06/22 03:26:15
Modified: . core.ops
t/op comp.t
Log:
cmp ops by Luke Palmer
Revision Changes Path
1.291 +37 -0 parrot/core.ops
Index: core.ops
===================================================================
RCS file: /cvs/public/parrot/core.ops,v
retrieving revision 1.290
retrieving revision 1.291
diff -u -w -r1.290 -r1.291
--- core.ops 21 Jun 2003 19:40:35 -0000 1.290
+++ core.ops 22 Jun 2003 10:26:10 -0000 1.291
@@ -735,6 +735,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();
+}
########################################
1.2 +29 -1 parrot/t/op/comp.t
Index: comp.t
===================================================================
RCS file: /cvs/public/parrot/t/op/comp.t,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -r1.1 -r1.2
--- comp.t 9 Nov 2002 12:42:55 -0000 1.1
+++ comp.t 22 Jun 2003 10:26:15 -0000 1.2
@@ -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;