perl.cvs.parrot
[Top] [All Lists]

[svn:parrot] r28862 - in trunk: src/pmc t/pmc

Subject: [svn:parrot] r28862 - in trunk: src/pmc t/pmc
From:
Date: Mon, 30 Jun 2008 07:52:43 -0700 PDT
Newsgroups: perl.cvs.parrot

Author: coke
Date: Mon Jun 30 07:52:42 2008
New Revision: 28862

Modified:
   trunk/src/pmc/float.pmc
   trunk/t/pmc/float.t

Log:
Fix RT #56464 - cmp doesn't work on Float subclasses.

Float was assuming that only PMCs would subclass it. Fixup to use the vtable
to get at the float values in most cases. Add a test.




Modified: trunk/src/pmc/float.pmc
==============================================================================
--- trunk/src/pmc/float.pmc     (original)
+++ trunk/src/pmc/float.pmc     Mon Jun 30 07:52:42 2008
@@ -81,7 +81,7 @@
 */
 
     VTABLE INTVAL get_integer() {
-        return (INTVAL) PMC_num_val(SELF);
+        return (INTVAL) SELF.get_number();
     }
 
 /*
@@ -95,7 +95,7 @@
 */
 
     VTABLE INTVAL get_bool() {
-        const FLOATVAL f = PMC_num_val(SELF);
+        const FLOATVAL f = SELF.get_number();
         return !FLOAT_IS_ZERO(f);
     }
 
@@ -112,11 +112,11 @@
 */
 
     VTABLE STRING *get_string() {
-        return string_from_num(INTERP, PMC_num_val(SELF));
+        return string_from_num(INTERP, SELF.get_number());
     }
 
     VTABLE STRING *get_repr() {
-        const FLOATVAL val      = PMC_num_val(SELF);
+        const FLOATVAL val      = SELF.get_number();
         const double d          = fabs((double)val);
         const char * const sign = signbit(val) ? "-" : "";
         return Parrot_sprintf_c(INTERP, "%s" FLOATVAL_FMT, sign, d);
@@ -241,19 +241,19 @@
 
     VTABLE INTVAL is_equal(PMC *value) {
 MMD_Float: {
-        return (INTVAL)(PMC_num_val(SELF) == PMC_num_val(value));
+        return (INTVAL)(SELF.get_number() == VTABLE_get_number(INTERP, value));
         }
 MMD_DEFAULT: {
-        return (INTVAL)(PMC_num_val(SELF) == VTABLE_get_number(INTERP, value));
+        return (INTVAL)(SELF.get_number() == VTABLE_get_number(INTERP, value));
         }
     }
 
     VTABLE INTVAL is_equal_num(PMC *value) {
 MMD_Float: {
-        return (INTVAL)(PMC_num_val(SELF) == PMC_num_val(value));
+        return (INTVAL)(SELF.get_number() == VTABLE_get_number(INTERP, value));
         }
 MMD_DEFAULT: {
-        return (INTVAL)(PMC_num_val(SELF) == VTABLE_get_number(INTERP, value));
+        return (INTVAL)(SELF.get_number() == VTABLE_get_number(INTERP, value));
         }
     }
 
@@ -269,12 +269,12 @@
 
     VTABLE INTVAL cmp(PMC *value) {
 MMD_Float: {
-            const FLOATVAL diff = PMC_num_val(SELF) - PMC_num_val(value);
+            const FLOATVAL diff = SELF.get_number() - 
VTABLE_get_number(INTERP, value);
             return diff > 0 ? 1 : diff < 0 ? -1 : 0;
         }
 MMD_DEFAULT: {
             const FLOATVAL diff =
-                PMC_num_val(SELF) - VTABLE_get_number(INTERP, value);
+                SELF.get_number() - VTABLE_get_number(INTERP, value);
             return diff > 0 ? 1 : diff < 0 ? -1 : 0;
         }
     }
@@ -291,12 +291,12 @@
 
     VTABLE INTVAL cmp_num(PMC *value) {
 MMD_Float: {
-            const FLOATVAL diff = PMC_num_val(SELF) - PMC_num_val(value);
+            const FLOATVAL diff = SELF.get_number() - 
VTABLE_get_number(INTERP, value);
             return diff > 0 ? 1 : diff < 0 ? -1 : 0;
         }
 MMD_DEFAULT: {
             const FLOATVAL diff =
-                PMC_num_val(SELF) - VTABLE_get_number(INTERP, value);
+                SELF.get_number() - VTABLE_get_number(INTERP, value);
             return diff > 0 ? 1 : diff < 0 ? -1 : 0;
         }
     }
@@ -367,7 +367,7 @@
     VTABLE void freeze(visit_info *info) {
         IMAGE_IO * const io = info->image_io;
         SUPER(info);
-        VTABLE_push_float(INTERP, io, PMC_num_val(SELF));
+        VTABLE_push_float(INTERP, io, SELF.get_number());
     }
 
 /*
@@ -433,110 +433,110 @@
 
     METHOD acos() {
         PMC * const d  = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-        PMC_num_val(d) = acos(PMC_num_val(SELF));
+        PMC_num_val(d) = acos(SELF.get_number());
         RETURN(PMC *d);
     }
 
     METHOD cos() {
         PMC * const d  = pmc_new(INTERP,
                 Parrot_get_ctx_HLL_type(INTERP, enum_class_Float));
-        PMC_num_val(d) = cos(VTABLE_get_number(interp, SELF));
+        PMC_num_val(d) = cos(SELF.get_number());
         RETURN(PMC *d);
     }
 
     METHOD asec() {
         PMC * const d  = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-        PMC_num_val(d) = acos(1.0 / PMC_num_val(SELF));
+        PMC_num_val(d) = acos(1.0 / SELF.get_number());
         RETURN(PMC *d);
     }
 
     METHOD asin() {
         PMC * const d  = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-        PMC_num_val(d) = asin(PMC_num_val(SELF));
+        PMC_num_val(d) = asin(SELF.get_number());
         RETURN(PMC *d);
     }
 
     METHOD atan() {
         PMC * const d  = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-        PMC_num_val(d) = atan(PMC_num_val(SELF));
+        PMC_num_val(d) = atan(SELF.get_number());
         RETURN(PMC *d);
     }
 
     METHOD atan2(PMC *val) {
         PMC * const d  = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-        PMC_num_val(d) = atan2(PMC_num_val(SELF), PMC_num_val(val));
+        PMC_num_val(d) = atan2(SELF.get_number(), PMC_num_val(val));
         RETURN(PMC *d);
     }
 
     METHOD cosh() {
         PMC * const d  = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-        PMC_num_val(d) = cosh(PMC_num_val(SELF));
+        PMC_num_val(d) = cosh(SELF.get_number());
         RETURN(PMC *d);
     }
 
     METHOD exp() {
         PMC * const d  = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-        PMC_num_val(d) = exp(PMC_num_val(SELF));
+        PMC_num_val(d) = exp(SELF.get_number());
         RETURN(PMC *d);
     }
 
     METHOD ln() {
         PMC * const d  = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-        PMC_num_val(d) = log(PMC_num_val(SELF));
+        PMC_num_val(d) = log(SELF.get_number());
         RETURN(PMC *d);
     }
 
     METHOD log10() {
         PMC * const d  = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-        PMC_num_val(d) = log10(PMC_num_val(SELF));
+        PMC_num_val(d) = log10(SELF.get_number());
         RETURN(PMC *d);
     }
 
     METHOD log2() {
         PMC * const d  = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-        PMC_num_val(d) = log(PMC_num_val(SELF)) / log(2.0);
+        PMC_num_val(d) = log(SELF.get_number()) / log(2.0);
         RETURN(PMC *d);
     }
 
     METHOD sec() {
         PMC * const d  = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-        PMC_num_val(d) = 1.0 / cos(PMC_num_val(SELF));
+        PMC_num_val(d) = 1.0 / cos(SELF.get_number());
         RETURN(PMC *d);
     }
 
     METHOD sech() {
         PMC * const d  = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-        PMC_num_val(d) = 1.0 / cosh(PMC_num_val(SELF));
+        PMC_num_val(d) = 1.0 / cosh(SELF.get_number());
         RETURN(PMC *d);
     }
 
     METHOD sin() {
         PMC * const d  = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-        PMC_num_val(d) = sin(PMC_num_val(SELF));
+        PMC_num_val(d) = sin(SELF.get_number());
         RETURN(PMC *d);
     }
 
     METHOD sinh() {
         PMC * const d  = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-        PMC_num_val(d) = sinh(PMC_num_val(SELF));
+        PMC_num_val(d) = sinh(SELF.get_number());
         RETURN(PMC *d);
     }
 
     METHOD tan() {
         PMC * const d  = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-        PMC_num_val(d) = tan(PMC_num_val(SELF));
+        PMC_num_val(d) = tan(SELF.get_number());
         RETURN(PMC *d);
     }
 
     METHOD tanh() {
         PMC * const d  = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-        PMC_num_val(d) = tanh(PMC_num_val(SELF));
+        PMC_num_val(d) = tanh(SELF.get_number());
         RETURN(PMC *d);
     }
 
     METHOD sqrt() {
         PMC * const d  = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-        PMC_num_val(d) = sqrt(PMC_num_val(SELF));
+        PMC_num_val(d) = sqrt(SELF.get_number());
         RETURN(PMC *d);
     }
 }

Modified: trunk/t/pmc/float.t
==============================================================================
--- trunk/t/pmc/float.t (original)
+++ trunk/t/pmc/float.t Mon Jun 30 07:52:42 2008
@@ -7,7 +7,7 @@
 use lib qw( . lib ../lib ../../lib );
 
 use Test::More;
-use Parrot::Test tests => 42;
+use Parrot::Test tests => 43;
 
 =head1 NAME
 
@@ -1110,6 +1110,29 @@
 3.1
 OUTPUT
 
+pir_output_is( <<'CODE', <<'OUTPUT', 'cmp functions for subclasses' );
+.sub main :main
+    $P0 = subclass 'Float', 'Flt'
+
+    $P1 = new 'Flt'
+    $P1 = 1.5
+    $P2 = new 'Flt'
+    $P2 = 2.73
+
+    $I0 = cmp $P1, $P2
+    say $I0
+    $I0 = cmp $P1, $P1
+    say $I0
+    $I0 = cmp $P2, $P1
+    say $I0
+.end
+CODE
+-1
+0
+1
+OUTPUT
+
+
 # Local Variables:
 #   mode: cperl
 #   cperl-indent-level: 4

<Prev in Thread] Current Thread [Next in Thread>
  • [svn:parrot] r28862 - in trunk: src/pmc t/pmc, coke <=