cvsuser     04/12/07 09:24:53

  Modified:    .        vtable.tbl
               classes  deleg_pmc.pmc ref.pmc sharedref.pmc
               dynclasses pyint.pmc pyobject.pmc
               include/parrot mmd.h
               ops      math.ops ops.num
  Log:
  Support __pow__ in PyInt
  
  Revision  Changes    Path
  1.72      +2 -1      parrot/vtable.tbl
  
  Index: vtable.tbl
  ===================================================================
  RCS file: /cvs/public/parrot/vtable.tbl,v
  retrieving revision 1.71
  retrieving revision 1.72
  diff -u -r1.71 -r1.72
  --- vtable.tbl        7 Dec 2004 10:50:42 -0000       1.71
  +++ vtable.tbl        7 Dec 2004 17:24:48 -0000       1.72
  @@ -1,4 +1,4 @@
  -# $Id: vtable.tbl,v 1.71 2004/12/07 10:50:42 leo Exp $
  +# $Id: vtable.tbl,v 1.72 2004/12/07 17:24:48 rubys Exp $
   # [MAIN] #default section name
   
   void init()
  @@ -167,6 +167,7 @@
   
   void pow(PMC* value, PMC* dest)        MMD_POW
   void pow_float(FLOATVAL value, PMC* dest) MMD_POW_FLOAT
  +void pow_int(INTVAL value, PMC* dest) MMD_POW_INT
   
   void neg(PMC* dest)
   
  
  
  
  1.5       +2 -1      parrot/classes/deleg_pmc.pmc
  
  Index: deleg_pmc.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/classes/deleg_pmc.pmc,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- deleg_pmc.pmc     7 Dec 2004 10:50:36 -0000       1.4
  +++ deleg_pmc.pmc     7 Dec 2004 17:24:50 -0000       1.5
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2004 The Perl Foundation.  All Rights Reserved.
  -$Id: deleg_pmc.pmc,v 1.4 2004/12/07 10:50:36 leo Exp $
  +$Id: deleg_pmc.pmc,v 1.5 2004/12/07 17:24:50 rubys Exp $
   
   =head1 NAME
   
  @@ -80,6 +80,7 @@
   #define VTABLE_is_equal_str(i,l,r) mmd_dispatch_i_pp(i,l,r,MMD_STREQ)
   #define VTABLE_pow(i, l, r, d) mmd_dispatch_v_ppp(i, l, r, d, MMD_POW)
   #define VTABLE_pow_float(i, l, r, d) mmd_dispatch_v_pnp(i, l, r, d, 
MMD_POW_FLOAT)
  +#define VTABLE_pow_int(i, l, r, d) mmd_dispatch_v_pnp(i, l, r, d, 
MMD_POW_INT)
   
   
   pmclass deleg_pmc {
  
  
  
  1.23      +2 -1      parrot/classes/ref.pmc
  
  Index: ref.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/classes/ref.pmc,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- ref.pmc   7 Dec 2004 10:50:36 -0000       1.22
  +++ ref.pmc   7 Dec 2004 17:24:50 -0000       1.23
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: ref.pmc,v 1.22 2004/12/07 10:50:36 leo Exp $
  +$Id: ref.pmc,v 1.23 2004/12/07 17:24:50 rubys Exp $
   
   =head1 NAME
   
  @@ -80,6 +80,7 @@
   #define VTABLE_is_equal_str(i,l,r) mmd_dispatch_i_pp(i,l,r,MMD_STREQ)
   #define VTABLE_pow(i, l, r, d) mmd_dispatch_v_ppp(i, l, r, d, MMD_POW)
   #define VTABLE_pow_float(i, l, r, d) mmd_dispatch_v_pnp(i, l, r, d, 
MMD_POW_FLOAT)
  +#define VTABLE_pow_int(i, l, r, d) mmd_dispatch_v_pnp(i, l, r, d, 
MMD_POW_INT)
   
   
   pmclass Ref does ref {
  
  
  
  1.20      +2 -1      parrot/classes/sharedref.pmc
  
  Index: sharedref.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/classes/sharedref.pmc,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- sharedref.pmc     7 Dec 2004 10:50:36 -0000       1.19
  +++ sharedref.pmc     7 Dec 2004 17:24:50 -0000       1.20
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: sharedref.pmc,v 1.19 2004/12/07 10:50:36 leo Exp $
  +$Id: sharedref.pmc,v 1.20 2004/12/07 17:24:50 rubys Exp $
   
   =head1 NAME
   
  @@ -92,6 +92,7 @@
   #define VTABLE_is_equal_str(i,l,r) mmd_dispatch_i_pp(i,l,r,MMD_STREQ)
   #define VTABLE_pow(i, l, r, d) mmd_dispatch_v_ppp(i, l, r, d, MMD_POW)
   #define VTABLE_pow_float(i, l, r, d) mmd_dispatch_v_pnp(i, l, r, d, 
MMD_POW_FLOAT)
  +#define VTABLE_pow_int(i, l, r, d) mmd_dispatch_v_pnp(i, l, r, d, 
MMD_POW_INT)
   
   pmclass SharedRef does ref need_ext is_shared extends Ref {
   
  
  
  
  1.5       +63 -33    parrot/dynclasses/pyint.pmc
  
  Index: pyint.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/dynclasses/pyint.pmc,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- pyint.pmc 1 Dec 2004 09:49:33 -0000       1.4
  +++ pyint.pmc 7 Dec 2004 17:24:51 -0000       1.5
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: pyint.pmc,v 1.4 2004/12/01 09:49:33 leo Exp $
  +$Id: pyint.pmc,v 1.5 2004/12/07 17:24:51 rubys Exp $
   
   =head1 NAME
   
  @@ -99,38 +99,6 @@
           PMC_int_val(ret) = PMC_int_val(SELF);
           return ret;
       }
  -
  -/*
  -
  -=item C<PMC* "__pow__"(PMC *value)>
  -
  -Raises C<SELF> to the power of C<*value> and returns the result.
  -
  -=cut
  -
  -*/
  -
  -    METHOD PMC* __pow__(PMC *value) {
  -        /* XXX: redo as a proper MMD if/when a proper op is implemented */
  -        FLOATVAL valf = VTABLE_get_number(INTERP, value);
  -        INTVAL vali = VTABLE_get_integer(INTERP, value);
  -        PMC * ret;
  -        if ( (vali < 0) || ((FLOATVAL)vali != valf) ) {
  -            ret = pmc_new(INTERP, dynclass_PyFloat);
  -            VTABLE_set_number_native(INTERP, ret,
  -                (FLOATVAL) pow( (FLOATVAL) PMC_int_val(SELF), valf) );
  -        }
  -        else {
  -            int i;
  -            ret = pmc_new(INTERP, dynclass_PyInt);
  -            PMC_int_val(ret) = 1;
  -            for (i=1; i<=vali; i++) {
  -                PMC_int_val(ret) *= PMC_int_val(SELF);
  -            }
  -        }
  -        return ret;
  -    }
  -
   /*
   
   =item C<PMC* "__truediv__"(PMC *value)>
  @@ -704,6 +672,68 @@
   
   /*
   
  +=item C<PMC* pow(PMC *value, PMC *dest)>
  +
  +Raises C<SELF> to the power of C<*value> and returns the result.
  +
  +=cut
  +
  +*/
  +
  +    void pow (PMC *value, PMC *dest) {
  +MMD_PyInt: {
  +            INTVAL vali = VTABLE_get_integer(INTERP, value);
  +            mmd_dispatch_v_pip(INTERP, SELF, vali, dest, MMD_POW_INT);
  +        }
  +MMD_PyFloat: {
  +            FLOATVAL valf = VTABLE_get_number(INTERP, value);
  +            mmd_dispatch_v_pip(INTERP, SELF, valf, dest, MMD_POW_FLOAT);
  +        }
  +    }
  +
  +/*
  +
  +=item C<PMC* pow_float(FLOATVAL value, PMC *dest)>
  +
  +Raises C<SELF> to the power of C<*value> and returns the result.
  +
  +=cut
  +
  +*/
  +
  +    void pow_float (FLOATVAL value, PMC *dest) {
  +        FLOATVAL pmcf = VTABLE_get_number(INTERP, SELF);
  +        VTABLE_morph(INTERP, dest, dynclass_PyFloat);
  +        VTABLE_set_number_native(INTERP, dest, (FLOATVAL) pow(pmcf, value) );
  +    }
  +
  +/*
  +
  +=item C<PMC* pow_int(INTVAL *value, PMC *dest)>
  +
  +Raises C<SELF> to the power of C<*value> and returns the result.
  +
  +=cut
  +
  +*/
  +
  +    void pow_int (INTVAL value, PMC *dest) {
  +        if (value < 0)
  +            mmd_dispatch_v_pip(INTERP, SELF, 
  +                (FLOATVAL)value, dest, MMD_POW_FLOAT);
  +        else {
  +            int i;
  +            INTVAL pmci = PMC_int_val(SELF);
  +            VTABLE_morph(INTERP, dest, dynclass_PyInt);
  +            PMC_int_val(dest) = 1;
  +            for (i=1; i<=value; i++) {
  +                PMC_int_val(dest) *= PMC_int_val(SELF);
  +            }
  +        }
  +    }
  +
  +/*
  +
   =item C<void set_integer_native(INTVAL value)>
   
   Sets the value of the integer to the value of the C<PyInt> C<*value>.
  
  
  
  1.2       +32 -1     parrot/dynclasses/pyobject.pmc
  
  Index: pyobject.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/dynclasses/pyobject.pmc,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- pyobject.pmc      10 Nov 2004 01:23:21 -0000      1.1
  +++ pyobject.pmc      7 Dec 2004 17:24:51 -0000       1.2
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: pyobject.pmc,v 1.1 2004/11/10 01:23:21 rubys Exp $
  +$Id: pyobject.pmc,v 1.2 2004/12/07 17:24:51 rubys Exp $
   
   =head1 NAME
   
  @@ -35,6 +35,7 @@
   static STRING* __mod__;
   static STRING* __mul__;
   static STRING* __or__;
  +static STRING* __pow__;
   static STRING* __rshift__;
   static STRING* __sub__;
   static STRING* __xor__;
  @@ -336,6 +337,22 @@
   
   /*
   
  +=item C<PMC* "__pow__"(PMC *value)>
  +
  +Raise the number to the specified power and return the result.
  +
  +=cut
  +
  +*/
  +
  +    METHOD PMC* __pow__(PMC *value) {
  +        PMC * ret = pmc_new(INTERP, dynclass_PyObject);
  +        mmd_dispatch_v_ppp(INTERP, SELF, value, ret, MMD_POW);
  +        return ret;
  +    }
  +
  +/*
  +
   =item C<PMC* "__radd__"(PMC *value)>
   
   Adds C<*value> to C<SELF> and returns the result.
  @@ -466,6 +483,20 @@
   
   /*
   
  +=item C<PMC* "__rpow__"(PMC *value)>
  +
  +Raise the number to the specified power and return the result.
  +
  +=cut
  +
  +*/
  +
  +    METHOD PMC* __rpow__(PMC *value) {
  +        RIGHT(INTERP, SELF, __pow__, value);
  +    }
  +
  +/*
  +
   =item C<PMC* "__rrshift__"(PMC *value)>
   
   Bitwise shift right (C<<<>>>>>) of C<*value> by the integer and
  
  
  
  1.22      +2 -1      parrot/include/parrot/mmd.h
  
  Index: mmd.h
  ===================================================================
  RCS file: /cvs/public/parrot/include/parrot/mmd.h,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- mmd.h     7 Dec 2004 10:50:39 -0000       1.21
  +++ mmd.h     7 Dec 2004 17:24:52 -0000       1.22
  @@ -1,7 +1,7 @@
   /* mmd.h
    *  Copyright: 2003 The Perl Foundation.  All Rights Reserved.
    *  CVS Info
  - *     $Id: mmd.h,v 1.21 2004/12/07 10:50:39 leo Exp $
  + *     $Id: mmd.h,v 1.22 2004/12/07 17:24:52 rubys Exp $
    *  Overview:
    *     This is the api header for the mmd subsystem
    *  Data Structure and Algorithms:
  @@ -73,6 +73,7 @@
           MMD_CMOD_FLOAT,
           MMD_POW,
           MMD_POW_FLOAT,
  +        MMD_POW_INT,
           MMD_BAND,
           MMD_BAND_INT,
           MMD_BOR,
  
  
  
  1.32      +7 -2      parrot/ops/math.ops
  
  Index: math.ops
  ===================================================================
  RCS file: /cvs/public/parrot/ops/math.ops,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- math.ops  7 Dec 2004 10:50:40 -0000       1.31
  +++ math.ops  7 Dec 2004 17:24:53 -0000       1.32
  @@ -812,13 +812,18 @@
     goto NEXT();
   }
   
  +inline op pow(in PMC, in PMC, in PMC) :base_core {
  +  mmd_dispatch_v_ppp(interpreter, $2, $3, $1, MMD_POW);
  +  goto NEXT();
  +}
  +
   inline op pow(in PMC, in PMC, in NUM) :base_core {
     mmd_dispatch_v_pnp(interpreter, $2, $3, $1, MMD_POW_FLOAT);
     goto NEXT();
   }
   
  -inline op pow(in PMC, in PMC, in PMC) :base_core {
  -  mmd_dispatch_v_ppp(interpreter, $2, $3, $1, MMD_POW);
  +inline op pow(in PMC, in PMC, in INT) :base_core {
  +  mmd_dispatch_v_pip(interpreter, $2, $3, $1, MMD_POW_INT);
     goto NEXT();
   }
   
  
  
  
  1.51      +2 -0      parrot/ops/ops.num
  
  Index: ops.num
  ===================================================================
  RCS file: /cvs/public/parrot/ops/ops.num,v
  retrieving revision 1.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- ops.num   7 Dec 2004 10:50:40 -0000       1.50
  +++ ops.num   7 Dec 2004 17:24:53 -0000       1.51
  @@ -1356,3 +1356,5 @@
   pow_p_p_n                      1326
   pow_p_p_nc                     1327
   pow_p_p_p                      1328
  +pow_p_p_i                      1329
  +pow_p_p_ic                     1330
  
  
  

Reply via email to