[svn:parrot] r43873 - in branches/vtable_massacre: src src/ops src/pmc t/pmc tools/dev

whiteknight at svn.parrot.org whiteknight at svn.parrot.org
Wed Feb 10 16:15:13 UTC 2010


Author: whiteknight
Date: Wed Feb 10 16:15:07 2010
New Revision: 43873
URL: https://trac.parrot.org/parrot/changeset/43873

Log:
remove *pow* vtables. Update all tests and PMC types. Notice that I replaced pow() in Complex BigInt, and BigNum types with experimental methods that perform the same operation. If we like this, we can add tests for them. Otherwise, delete them

Modified:
   branches/vtable_massacre/src/ops/math.ops
   branches/vtable_massacre/src/pmc/bigint.pmc
   branches/vtable_massacre/src/pmc/bignum.pmc
   branches/vtable_massacre/src/pmc/complex.pmc
   branches/vtable_massacre/src/pmc/default.pmc
   branches/vtable_massacre/src/pmc/integer.pmc
   branches/vtable_massacre/src/pmc/scalar.pmc
   branches/vtable_massacre/src/vtable.tbl
   branches/vtable_massacre/t/pmc/complex.t
   branches/vtable_massacre/tools/dev/vtablize.pl

Modified: branches/vtable_massacre/src/ops/math.ops
==============================================================================
--- branches/vtable_massacre/src/ops/math.ops	Wed Feb 10 15:31:30 2010	(r43872)
+++ branches/vtable_massacre/src/ops/math.ops	Wed Feb 10 16:15:07 2010	(r43873)
@@ -812,15 +812,35 @@
 }
 
 inline op pow(invar PMC, invar PMC, invar PMC) :base_core {
-    $1 = VTABLE_pow(interp, $2, $3, $1);
+    const FLOATVAL a = VTABLE_get_number(interp, $2);
+    const FLOATVAL b = VTABLE_get_number(interp, $3);
+    const FLOATVAL c = pow(a, b);
+    if (PMC_IS_NULL($1))
+        $1 = pmc_new(interp, enum_class_Float);
+    else
+        $1 = pmc_new(interp, $1->vtable->base_type);
+    VTABLE_set_number_native(interp, $1, c);
 }
 
 inline op pow(invar PMC, invar PMC, in INT) :base_core {
-    $1 = VTABLE_pow_int(interp, $2, $3, $1);
+    const FLOATVAL a = VTABLE_get_number(interp, $2);
+    const FLOATVAL b = (FLOATVAL)$3;
+    const FLOATVAL c = pow(a, b);
+    if (PMC_IS_NULL($1))
+        $1 = pmc_new(interp, enum_class_Float);
+    else
+        $1 = pmc_new(interp, $1->vtable->base_type);
+    VTABLE_set_number_native(interp, $1, c);
 }
 
 inline op pow(invar PMC, invar PMC, in NUM) :base_core {
-    $1 = VTABLE_pow_float(interp, $2, $3, $1);
+    const FLOATVAL a = VTABLE_get_number(interp, $2);
+    const FLOATVAL c = pow(a, $3);
+    if (PMC_IS_NULL($1))
+        $1 = pmc_new(interp, enum_class_Float);
+    else
+        $1 = pmc_new(interp, $1->vtable->base_type);
+    VTABLE_set_number_native(interp, $1, c);
 }
 
 inline op pow(out NUM, in NUM, in INT) :base_core {

Modified: branches/vtable_massacre/src/pmc/bigint.pmc
==============================================================================
--- branches/vtable_massacre/src/pmc/bigint.pmc	Wed Feb 10 15:31:30 2010	(r43872)
+++ branches/vtable_massacre/src/pmc/bigint.pmc	Wed Feb 10 16:15:07 2010	(r43873)
@@ -887,17 +887,10 @@
             "BigInt: no multiple dispatch variant 'i_multiply_float' for FLOATVAL");
     }
 
-    VTABLE PMC *pow_int(INTVAL value, PMC *dest) {
-        dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-
-        bigint_pow_bigint_int(INTERP, SELF, value, dest);
-        return dest;
-    }
-
-    MULTI PMC *pow(PMC *value, PMC *dest) {
+    METHOD pow(PMC *value) {
         /* XXX only Integer RHS currently */
         const INTVAL r = VTABLE_get_integer(INTERP, value);
-        dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
+        PMC *dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
 
         bigint_pow_bigint_int(INTERP, SELF, r, dest);
         return dest;

Modified: branches/vtable_massacre/src/pmc/bignum.pmc
==============================================================================
--- branches/vtable_massacre/src/pmc/bignum.pmc	Wed Feb 10 15:31:30 2010	(r43872)
+++ branches/vtable_massacre/src/pmc/bignum.pmc	Wed Feb 10 16:15:07 2010	(r43873)
@@ -1228,23 +1228,22 @@
 
 /*
 
-=item C<void pow()>
+=item C<METHOD PMC *pow()>
 
-=cut
+Raises self to the power of value. Replacement method added when the pow()
+vtable was removed
 
-*/
+TODO: Needs testing.
+TODO: Only supports Integer values for now.
 
-    VTABLE PMC *pow_int(INTVAL value, PMC *dest) {
-        dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
+=cut
 
-        bignum_pow_bignum_int(INTERP, SELF, value, dest);
-        return dest;
-    }
+*/
 
-    MULTI PMC *pow(PMC *value, PMC *dest) {
+    METHOD pow(PMC *value) {
         /* only Integer RHS currently. TODO: check number and bignum types */
         INTVAL r = VTABLE_get_integer(INTERP, value);
-        dest = pmc_new(INTERP, SELF->vtable->base_type);
+        PMC *dest = pmc_new(INTERP, SELF->vtable->base_type);
 
         bignum_pow_bignum_int(INTERP, SELF, r, dest);
         return dest;

Modified: branches/vtable_massacre/src/pmc/complex.pmc
==============================================================================
--- branches/vtable_massacre/src/pmc/complex.pmc	Wed Feb 10 15:31:30 2010	(r43872)
+++ branches/vtable_massacre/src/pmc/complex.pmc	Wed Feb 10 16:15:07 2010	(r43873)
@@ -1775,9 +1775,12 @@
 
 /*
 
-=item C<PMC *pow(PMC *value, PMC *dest)>
+=item C<METHOD PMC *pow(PMC *value)>
 
-Return SELF to the C<value>th power and return result in C<dest>.
+Raise SELF to the power of value. Replacement for the old pow() vtable, which
+was deleted.
+
+TODO: Requires testing
 
 =item C<METHOD PMC *sqrt()>
 
@@ -1792,38 +1795,19 @@
 
 */
 
-    MULTI PMC *pow(Complex value, PMC *dest) {
+    METHOD pow(PMC * value) {
         PMC *l = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
         PMC *log;
-
-        dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-
+        PMC *dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
 
         Parrot_pcc_invoke_method_from_c_args(interp, SELF, CONST_STRING(interp, "ln"),
                     "->P", &log);
 
-        l = Parrot_Complex_multi_multiply_Complex_PMC(INTERP,
-                    log, value, l);
+        l = VTABLE_multiply(INTERP, log, value, l);
 
         Parrot_pcc_invoke_method_from_c_args(interp, l, CONST_STRING(interp, "exp"),
                     "->P", &dest);
-
-        return dest;
-    }
-
-    MULTI PMC *pow(DEFAULT value, PMC *dest) {
-        PMC *l = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-        PMC *log;
-
-        dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-
-        Parrot_pcc_invoke_method_from_c_args(interp, SELF, CONST_STRING(interp, "ln"),
-                     "->P", &log);
-        l = Parrot_Complex_multi_multiply_DEFAULT_PMC(INTERP, log, value, l);
-        Parrot_pcc_invoke_method_from_c_args(interp, l, CONST_STRING(interp, "exp"),
-                     "->P", &dest);
-
-        return dest;
+        RETURN(PMC *dest);
     }
 
     METHOD sqrt() {

Modified: branches/vtable_massacre/src/pmc/default.pmc
==============================================================================
--- branches/vtable_massacre/src/pmc/default.pmc	Wed Feb 10 15:31:30 2010	(r43872)
+++ branches/vtable_massacre/src/pmc/default.pmc	Wed Feb 10 16:15:07 2010	(r43873)
@@ -1692,103 +1692,6 @@
 
 /*
 
-=item C<PMC *pow(PMC *value, PMC *dest)>
-
-Default fallback. Performs a multiple dispatch call for 'pow'.
-
-=cut
-
-*/
-
-    VTABLE PMC *pow(PMC *value, PMC *dest) {
-        PMC *result = PMCNULL;
-        Parrot_mmd_multi_dispatch_from_c_args(interp,
-                "pow", "PPP->P", SELF, value, dest, &result);
-        return result;
-    }
-
-/*
-
-=item C<PMC *pow_int(INTVAL value, PMC *dest)>
-
-Default fallback. Performs a multiple dispatch call for 'pow_int'.
-
-=cut
-
-*/
-
-    VTABLE PMC *pow_int(INTVAL value, PMC *dest) {
-        PMC *result = PMCNULL;
-        Parrot_mmd_multi_dispatch_from_c_args(interp,
-                "pow_int", "PIP->P", SELF, value, dest, &result);
-        return result;
-    }
-
-/*
-
-=item C<PMC *pow_float(FLOATVAL value, PMC *dest)>
-
-Default fallback. Performs a multiple dispatch call for 'pow_float'.
-
-=cut
-
-*/
-
-    VTABLE PMC *pow_float(FLOATVAL value, PMC *dest) {
-        PMC *result = PMCNULL;
-        Parrot_mmd_multi_dispatch_from_c_args(interp,
-                "pow_float", "PNP->P", SELF, value, dest, &result);
-        return result;
-    }
-
-/*
-
-=item C<void i_pow(PMC *value)>
-
-Default fallback. Performs a multiple dispatch call for 'i_pow'.
-
-=cut
-
-*/
-
-    VTABLE void i_pow(PMC *value) {
-        Parrot_mmd_multi_dispatch_from_c_args(interp,
-                "i_pow", "PP", SELF, value);
-    }
-
-/*
-
-=item C<void i_pow_int(INTVAL value)>
-
-Default fallback. Performs a multiple dispatch call for 'i_pow_int'.
-
-=cut
-
-*/
-
-    VTABLE void i_pow_int(INTVAL value) {
-        Parrot_mmd_multi_dispatch_from_c_args(interp,
-                "i_pow_int", "PI", SELF, value);
-    }
-
-/*
-
-=item C<void i_pow_float(FLOATVAL value)>
-
-Default fallback. Performs a multiple dispatch call for 'i_pow_float'.
-
-=cut
-
-*/
-
-    VTABLE void i_pow_float(FLOATVAL value) {
-        Parrot_mmd_multi_dispatch_from_c_args(interp,
-                "i_pow_float", "PN", SELF, value);
-    }
-
-
-/*
-
 =item C<INTVAL cmp(PMC *value)>
 
 Default fallback. Performs a multiple dispatch call for 'cmp'.

Modified: branches/vtable_massacre/src/pmc/integer.pmc
==============================================================================
--- branches/vtable_massacre/src/pmc/integer.pmc	Wed Feb 10 15:31:30 2010	(r43872)
+++ branches/vtable_massacre/src/pmc/integer.pmc	Wed Feb 10 16:15:07 2010	(r43873)
@@ -986,99 +986,6 @@
                 intval_mod(SELF.get_integer() , (INTVAL)value));
     }
 
-
-/*
-
-=item C<PMC *pow(PMC *value, PMC *dest)>
-
-=item C<PMC *pow_int(INTVAL value, PMC *dest)>
-
-Returns SELF to the C<value>th power in C<dest>.
-
-=item C<void i_pow(PMC *value)>
-
-=item C<void i_pow_int(INTVAL value)>
-
-Raises SELF to the C<value>th power.
-
-TODO:  TT #1228: Implement Complex and BigInt RHS values for the pow() functions
-
-=cut
-
-*/
-
-    MULTI PMC *pow(Integer value, PMC *dest) {
-        const INTVAL v = VTABLE_get_integer(INTERP, value);
-        return STATICSELF.pow_int(v, dest);
-    }
-
-
-    MULTI PMC *pow(DEFAULT value, PMC *dest) {
-        PMC * const auxval = pmc_new(INTERP, VTABLE_type(INTERP, value));
-        FLOATVAL selfval = SELF.get_integer();
-        VTABLE_set_number_native(INTERP, auxval, selfval);
-        return VTABLE_pow(INTERP, auxval, value, dest);
-    }
-
-
-    VTABLE PMC *pow_int(INTVAL b, PMC *dest) {
-        const INTVAL a      = SELF.get_integer();
-        const INTVAL orig_b = b;
-        INTVAL       r      = 1;
-
-        if (b < 0)
-            return SUPER(b, dest);
-
-        if (a) {
-            INTVAL temp = a;
-            while (b > 0) {
-                INTVAL prev = r;
-                if (b & 1) {
-                    r *= temp;
-                    if (r / temp != prev) {
-                        PMC *temp;
-                        maybe_throw_overflow_error(INTERP);
-                        temp = pmc_new(interp, enum_class_BigInt);
-                        VTABLE_set_integer_native(interp, temp, a);
-                        return VTABLE_pow_int(INTERP, temp, orig_b, dest);
-                    }
-                }
-
-                b >>= 1;
-                if (!b)
-                    break;
-
-                prev  = temp;
-                temp *= temp;
-
-                if (prev != 0 && temp / prev != prev) {
-                    PMC *temp;
-                    maybe_throw_overflow_error(INTERP);
-                    temp = pmc_new(interp, enum_class_BigInt);
-                    VTABLE_set_integer_native(interp, temp, a);
-                    return VTABLE_pow_int(INTERP, temp, orig_b, dest);
-                }
-            }
-        }
-
-        dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-
-        VTABLE_set_integer_native(INTERP, dest, r);
-        return dest;
-
-    }
-
-
-    VTABLE void i_pow(PMC *value) {
-        SELF.pow(value, SELF);
-    }
-
-
-    VTABLE void i_pow_int(INTVAL value) {
-        STATICSELF.pow_int(value, SELF);
-    }
-
-
 /*
 
 =item C<INTVAL is_equal(PMC *value)>

Modified: branches/vtable_massacre/src/pmc/scalar.pmc
==============================================================================
--- branches/vtable_massacre/src/pmc/scalar.pmc	Wed Feb 10 15:31:30 2010	(r43872)
+++ branches/vtable_massacre/src/pmc/scalar.pmc	Wed Feb 10 16:15:07 2010	(r43873)
@@ -579,72 +579,6 @@
 
 /*
 
-=item C<PMC *pow(PMC *value, PMC *dest)>
-
-=item C<PMC *pow_int(INTVAL value, PMC *dest)>
-
-=item C<PMC *pow_float(FLOATVAL value, PMC *dest)>
-
-Calculates  C<SELF pow value> and returns
-the result in C<dest>. See also ops/math.ops.
-
-=item C<void i_pow(PMC *value)>
-
-=item C<void i_pow_int(INTVAL value)>
-
-=item C<void i_pow_float(FLOATVAL value)>
-
-Calculates pow inplace
-
-=cut
-
-*/
-
-    MULTI PMC *pow(PMC *value, PMC *dest) {
-        const FLOATVAL d = VTABLE_get_number(INTERP, value);
-
-        dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-
-        VTABLE_set_number_native(INTERP, dest, pow(SELF.get_number(), d));
-        return dest;
-    }
-
-    VTABLE PMC *pow_int(INTVAL value, PMC *dest) {
-        dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-
-        VTABLE_set_number_native(INTERP, dest,
-                pow(SELF.get_number(), (double)value));
-
-        return dest;
-    }
-
-    VTABLE PMC *pow_float(FLOATVAL value, PMC *dest) {
-        dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-
-        VTABLE_set_number_native(INTERP, dest,
-                pow(SELF.get_number(), value));
-        return dest;
-    }
-
-    VTABLE void i_pow(PMC *value) {
-        const FLOATVAL d = VTABLE_get_number(INTERP, value);
-
-        VTABLE_set_number_native(INTERP, SELF,
-                pow(SELF.get_number(), d));
-    }
-
-    VTABLE void i_pow_int(INTVAL value) {
-        VTABLE_set_number_native(INTERP, SELF,
-                pow(SELF.get_number(), (float)value));
-    }
-
-    VTABLE void i_pow_float(FLOATVAL value) {
-        VTABLE_set_number_native(INTERP, SELF,
-                pow(SELF.get_number(), value));
-    }
-
-/*
-
 =item C<PMC *neg(PMC *dest)>
 
 =item C<void i_neg()>

Modified: branches/vtable_massacre/src/vtable.tbl
==============================================================================
--- branches/vtable_massacre/src/vtable.tbl	Wed Feb 10 15:31:30 2010	(r43872)
+++ branches/vtable_massacre/src/vtable.tbl	Wed Feb 10 16:15:07 2010	(r43873)
@@ -175,14 +175,6 @@
 void i_modulus_int(INTVAL value) :write
 void i_modulus_float(FLOATVAL value) :write
 
-PMC* pow(PMC* value, PMC* dest)
-PMC* pow_int(INTVAL value, PMC* dest)
-PMC* pow_float(FLOATVAL value, PMC* dest)
-
-void i_pow(PMC* value) :write
-void i_pow_int(INTVAL value) :write
-void i_pow_float(FLOATVAL value) :write
-
 void increment() :write
 void decrement() :write
 

Modified: branches/vtable_massacre/t/pmc/complex.t
==============================================================================
--- branches/vtable_massacre/t/pmc/complex.t	Wed Feb 10 15:31:30 2010	(r43872)
+++ branches/vtable_massacre/t/pmc/complex.t	Wed Feb 10 16:15:07 2010	(r43873)
@@ -21,7 +21,7 @@
     .include 'fp_equality.pasm'
     .include "iglobals.pasm"
 
-    plan(467)
+    plan(458)
 
     string_parsing()
     exception_malformed_string__real_part()
@@ -53,7 +53,6 @@
     test_sub()
     test_i_sub()
     sprintf_with_a_complex()
-    pow_with_complex_numbers()
     e_raised_pi_time_i__plus_1_equal_0()
     ln_of_complex_numbers()
     exp_of_complex_numbers()
@@ -641,33 +640,6 @@
     .sprintf_is( "%.3f%+.3fi", "0+i", "0.000+1.000i" )
 .end
 
-.macro pow_test_is(base, power, message)
-    c = .base
-    c2 = .power
-    c3 = pow c, c2
-    $S0 = sprintf "%.6f%+.6fi", c3
-    $S1 = .message
-    is( $S0, $S1, $S1 )
-.endm
-
-.sub pow_with_complex_numbers
-    .local pmc c, c2, c3
-    c  = new ['Complex']
-    c2 = new ['Complex']
-    c3 = new ['Complex']
-    .pow_test_is( "i", "i", "0.207880+0.000000i" )
-    .pow_test_is( "i", "2", "-1.000000+0.000000i" )
-    .pow_test_is( "2i", "2", "-4.000000+0.000000i" )
-    .pow_test_is( "2+2i", "2+2i", "-1.452505-0.809890i" )
-    .pow_test_is( "i", "0.5i", "0.455938+0.000000i" )
-    .pow_test_is( 2, "2i", "0.183457+0.983028i" )
-    c2 = new ['Integer']
-    .pow_test_is( "2i", 2, "-4.000000+0.000000i" )
-    .pow_test_is( "2", 4, "16.000000+0.000000i" )
-    c2 = new ['Float']
-    .pow_test_is( "2i", 0.5, "1.000000+1.000000i" )
-.end
-
 .sub e_raised_pi_time_i__plus_1_equal_0
     .local pmc c, c2, c3
     c  = new ['Complex']

Modified: branches/vtable_massacre/tools/dev/vtablize.pl
==============================================================================
--- branches/vtable_massacre/tools/dev/vtablize.pl	Wed Feb 10 15:31:30 2010	(r43872)
+++ branches/vtable_massacre/tools/dev/vtablize.pl	Wed Feb 10 16:15:07 2010	(r43873)
@@ -156,12 +156,6 @@
 s/^(\s*)(void\s+i_cmodulus\(PMC\s+\*\w*\)\s+{)/$1VTABLE $2/;
 s/^(\s*)(void\s+i_cmodulus_int\(INTVAL\s+\w*\)\s+{)/$1VTABLE $2/;
 s/^(\s*)(void\s+i_cmodulus_float\(FLOATVAL\s+\w*\)\s+{)/$1VTABLE $2/;
-s/^(\s*)(PMC\s+\*pow\(PMC\s+\*\w*,\s+PMC\s+\*\w*\)\s+{)/$1VTABLE $2/;
-s/^(\s*)(PMC\s+\*pow_int\(INTVAL\s+\w*,\s+PMC\s+\*\w*\)\s+{)/$1VTABLE $2/;
-s/^(\s*)(PMC\s+\*pow_float\(FLOATVAL\s+\w*,\s+PMC\s+\*\w*\)\s+{)/$1VTABLE $2/;
-s/^(\s*)(void\s+i_pow\(PMC\s+\*\w*\)\s+{)/$1VTABLE $2/;
-s/^(\s*)(void\s+i_pow_int\(INTVAL\s+\w*\)\s+{)/$1VTABLE $2/;
-s/^(\s*)(void\s+i_pow_float\(FLOATVAL\s+\w*\)\s+{)/$1VTABLE $2/;
 s/^(\s*)(void\s+increment\(\)\s+{)/$1VTABLE $2/;
 s/^(\s*)(void\s+decrement\(\)\s+{)/$1VTABLE $2/;
 s/^(\s*)(PMC\s+\*absolute\(PMC\s+\*\w*\)\s+{)/$1VTABLE $2/;


More information about the parrot-commits mailing list