cvsuser     04/12/10 00:30:36

  Modified:    classes  float.pmc perlint.pmc perlnum.pmc
               lib/Parrot Pmc2c.pm
  Log:
  class refactoring 3 - Float
  
  Revision  Changes    Path
  1.14      +191 -65   parrot/classes/float.pmc
  
  Index: float.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/classes/float.pmc,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- float.pmc 25 Aug 2004 08:03:18 -0000      1.13
  +++ float.pmc 10 Dec 2004 08:30:35 -0000      1.14
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2003 The Perl Foundation.  All Rights Reserved.
  -$Id: float.pmc,v 1.13 2004/08/25 08:03:18 leo Exp $
  +$Id: float.pmc,v 1.14 2004/12/10 08:30:35 leo Exp $
   
   =head1 NAME
   
  @@ -8,9 +8,7 @@
   
   =head1 DESCRIPTION
   
  -C<Float> extends C<mmd_default> to provide a floating-point number for
  -languages that want a value-restricted C<float> type without going to an
  -N register.
  +C<Float> extends C<scalar> to provide floating-point number operations.
   
   =head2 Methods
   
  @@ -28,129 +26,207 @@
   
   =item C<void init()>
   
  -Initializes the number.
  +Initializes the number to zero.
   
   =cut
   
   */
   
  -    void init() {   /* pmc2c doesn't like empty classes */
  -        SUPER();
  +    void init() {
  +        PMC_num_val(SELF) = 0.0;
       }
   
   /*
   
  -=item C<void set_integer_native(INTVAL value)>
  +=item C<PMC* instantiate()>
   
  -Sets the value of the number to C<value>.
  +Create a new Float from the passed in argument. This is a class method,
  +arguments are passed according to pdd03.
   
   =cut
   
   */
  -
  -    void set_integer_native(INTVAL value) {
  -        PMC_num_val(SELF) = value;
  +    PMC* instantiate() {
  +        int argcP = REG_INT(3);
  +        PMC *class = REG_PMC(2);
  +        PMC *res = pmc_new(interpreter, class->vtable->base_type);
  +        /* TODO non-PMC arguments */
  +        if (argcP)
  +            VTABLE_set_number_native(interpreter, res,
  +                    VTABLE_get_number(interpreter, REG_PMC(5)));
  +        return res;
       }
   
   /*
   
  -=item C<void set_number_native(FLOATVAL value)>
  +=item C<FLOATVAL get_number()>
   
  -Sets the value of the number to C<value>.
  +Returns the value of the number.
   
   =cut
   
   */
   
  -    void set_number_native(FLOATVAL value) {
  -        PMC_num_val(SELF) = value;
  +    FLOATVAL get_number() {
  +        return PMC_num_val(SELF);
       }
   
   /*
   
  -=item C<void set_string_native(STRING* value)>
  +=item C<INTVAL get_integer()>
   
  -Sets the value of the number by converting C<*value> to a number.
  +Returns an integer representation of the number (by casting).
   
   =cut
   
   */
   
  -    void set_string_native(STRING* value) {
  -        PMC_num_val(SELF) = string_to_num(INTERP, value);
  -    }
  +   INTVAL get_integer() {
  +        return (INTVAL) PMC_num_val(SELF);
  +   }
   
   /*
   
  -=item C<void set_pmc(PMC *value)>
  +=item C<INTVAL get_bool()>
   
  -Sets the value of the number to the value in C<*value>.
  +Evaluates the number as a boolean, i.e. it's true if it's not zero.
   
   =cut
   
   */
   
  -    void set_pmc(PMC *value) {
  -        PMC_num_val(SELF) = VTABLE_get_number(INTERP, value);
  +    INTVAL get_bool () {
  +        return (INTVAL)(PMC_num_val(SELF) != 0.0);
       }
   
   /*
   
  -=item C<FLOATVAL get_number()>
  +=item C<STRING* get_string()>
   
  -Returns the value of the number.
  +Returns a Parrot string representation of the number.
  +
  +=item C<STRING* get_repr()>
   
   =cut
   
   */
   
  -    FLOATVAL get_number() {
  -        return PMC_num_val(SELF);
  +    STRING* get_string() {
  +        return string_from_num(INTERP, PMC_num_val(SELF));
  +    }
  +
  +    STRING* get_repr () {
  +        double d = (double) PMC_num_val(SELF);
  +        const char *sign = "-";
  +     if (!signbit(PMC_num_val(SELF)))
  +            sign = "";
  +        d = fabs(d);
  +        return Parrot_sprintf_c(interpreter, "%s" FLOATVAL_FMT, sign, d);
       }
   
   /*
   
  -=item C<INTVAL get_integer()>
  +=item C<void set_integer_native(INTVAL value)>
   
  -Returns an integer representation of the number (by casting).
  +=cut
  +
  +*/
  +
  +    void set_integer_native (INTVAL value) {
  +        DYNSELF.morph(enum_class_Integer);
  +        DYNSELF.set_integer_native(value);
  +    }
  +
  +/*
  +
  +=item C<void set_number_native(FLOATVAL value)>
  +
  +Sets the value of the number to C<value>.
   
   =cut
   
   */
   
  -   INTVAL get_integer() {
  -        return (INTVAL) PMC_num_val(SELF);
  -   }
  +    void set_number_native(FLOATVAL value) {
  +        PMC_num_val(SELF) = value;
  +    }
   
   /*
   
  +=item C<void set_number_same(PMC* value)>
  +
  +Sets the value of the number to the value of C<*value>.
  +
  +=cut
  +
  +*/
  +
  +    void set_number_same (PMC* value) {
  +        PMC_num_val(SELF) = PMC_num_val(value);
  +    }
  +
   /*
   
  -=item C<INTVAL get_bool()>
  +=item C<void set_string_native(STRING *value)>
   
  -Evaluates the number as a boolean, i.e. it's true if it's not zero.
  +Sets the value of the number to the value of C<*value>.
  +
  +Note that this method morphs the number into a C<String>.
   
   =cut
   
   */
   
  -    INTVAL get_bool () {
  -        return (INTVAL)(PMC_num_val(SELF) != 0.0);
  +    void set_string_native (STRING * value) {
  +        DYNSELF.morph(enum_class_String);
  +        DYNSELF.set_string_native(value);
       }
   
   /*
   
  -=item C<STRING* get_string()>
  +=item C<void set_pmc(PMC *value)>
   
  -Returns a Parrot string representation of the number.
  +Sets the value of the number to the value in C<*value>.
   
   =cut
   
   */
   
  -   STRING* get_string() {
  -        return string_from_num(INTERP, PMC_num_val(SELF));
  -   }
  +    void set_pmc(PMC *value) {
  +        PMC_num_val(SELF) = VTABLE_get_number(INTERP, value);
  +    }
  +/*
  +
  +=item C<void morph(INTVAL type)>
  +
  +Morphs the scalar to the specified type.
  +
  +=cut
  +
  +*/
  +
  +    void morph (INTVAL type) {
  +        if (SELF->vtable->base_type == type)
  +            return;
  +        if (type == enum_class_String) {
  +            /*
  +             * if we morph to a string, first clear str_val
  +             * so that after changing the vtable a parallel
  +             * reader doesn't get a gargabe pointer
  +             */
  +            PMC_str_val(SELF) = NULL;
  +            PObj_custom_mark_SET(SELF);
  +            SELF->vtable = Parrot_base_vtables[type];
  +            return;
  +        }
  +        if (type == enum_class_BigInt || type == enum_class_Complex) {
  +            PMC_str_val(SELF) = NULL;
  +            SELF->vtable = Parrot_base_vtables[type];
  +            DYNSELF.init();
  +            return;
  +        }
  +        SELF->vtable = Parrot_base_vtables[type];
  +    }
   /*
   
   =item C<void add(PMC *value, PMC *dest)>
  @@ -162,10 +238,14 @@
   */
   
       void add (PMC* value, PMC* dest) {
  +MMD_Float: {
           VTABLE_set_number_native(INTERP, dest,
  -            PMC_num_val(SELF) +
  -            VTABLE_get_number(INTERP, value)
  -        );
  +            PMC_num_val(SELF) + PMC_num_val(value));
  +        }
  +MMD_DEFAULT: {
  +        VTABLE_set_number_native(INTERP, dest,
  +            PMC_num_val(SELF) + VTABLE_get_number(INTERP, value));
  +        }
       }
   
   /*
  @@ -208,10 +288,14 @@
   */
   
       void subtract (PMC* value, PMC* dest) {
  +MMD_Float: {
           VTABLE_set_number_native(INTERP, dest,
  -            PMC_num_val(SELF) -
  -            VTABLE_get_number(INTERP, value)
  -        );
  +            PMC_num_val(SELF) - PMC_num_val(value));
  +        }
  +MMD_DEFAULT: {
  +        VTABLE_set_number_native(INTERP, dest,
  +            PMC_num_val(SELF) - VTABLE_get_number(INTERP, value));
  +        }
       }
   
   /*
  @@ -226,8 +310,7 @@
   
       void subtract_int (INTVAL value, PMC* dest) {
           VTABLE_set_number_native(INTERP, dest,
  -            PMC_num_val(SELF) - (FLOATVAL)value
  -        );
  +            PMC_num_val(SELF) - (FLOATVAL)value);
       }
   /*
   
  @@ -255,10 +338,14 @@
   */
   
       void multiply (PMC* value, PMC* dest) {
  +MMD_Float: {
           VTABLE_set_number_native(INTERP, dest,
  -            PMC_num_val(SELF) *
  -            VTABLE_get_number(INTERP, value)
  -        );
  +            PMC_num_val(SELF) * PMC_num_val(value));
  +        }
  +MMD_DEFAULT: {
  +        VTABLE_set_number_native(INTERP, dest,
  +            PMC_num_val(SELF) * VTABLE_get_number(INTERP, value));
  +         }
       }
   
   /*
  @@ -273,8 +360,7 @@
   
       void multiply_int (INTVAL value, PMC* dest) {
           VTABLE_set_number_native(INTERP, dest,
  -            PMC_num_val(SELF) * value
  -        );
  +            PMC_num_val(SELF) * value);
       }
   /*
   
  @@ -302,10 +388,15 @@
   */
   
       void divide (PMC* value, PMC* dest) {
  +MMD_Float: {
  +        /* TODO zero dividde */
           VTABLE_set_number_native(INTERP, dest,
  -            PMC_num_val(SELF) /
  -            VTABLE_get_number(INTERP, value)
  -        );
  +            PMC_num_val(SELF) / PMC_num_val(value));
  +        }
  +MMD_DEFAULT: {
  +        VTABLE_set_number_native(INTERP, dest,
  +            PMC_num_val(SELF) / VTABLE_get_number(INTERP, value));
  +        }
       }
   
   /*
  @@ -350,9 +441,17 @@
   */
   
       void cmodulus (PMC* value, PMC* dest) {
  +MMD_Float: {
  +        /* TODO zero dividde */
  +        FLOATVAL f = PMC_num_val(value);
  +        VTABLE_set_number_native(INTERP, dest,
  +            fmod(PMC_num_val(SELF), f));
  +        }
  +MMD_DEFAULT: {
           FLOATVAL f = VTABLE_get_number(INTERP, value);
           VTABLE_set_number_native(INTERP, dest,
               fmod(PMC_num_val(SELF), f));
  +        }
       }
   
   /*
  @@ -396,9 +495,17 @@
   */
   
       void modulus (PMC* value, PMC* dest) {
  +MMD_Float: {
  +        /* TODO zero dividde */
  +        FLOATVAL f = PMC_num_val(value);
  +        VTABLE_set_number_native(INTERP, dest,
  +            floatval_mod(PMC_num_val(SELF), f));
  +        }
  +MMD_DEFAULT: {
           FLOATVAL f = VTABLE_get_number(INTERP, value);
           VTABLE_set_number_native(INTERP, dest,
               floatval_mod(PMC_num_val(SELF), f));
  +        }
       }
   
   /*
  @@ -458,7 +565,12 @@
   */
   
       INTVAL is_equal (PMC* value) {
  +MMD_Float: {
  +        return (INTVAL)(PMC_num_val(SELF) == PMC_num_val(value));
  +        }
  +MMD_DEFAULT: {
           return (INTVAL)(PMC_num_val(SELF) == VTABLE_get_number(INTERP, 
value));
  +        }
       }
   
   /*
  @@ -472,9 +584,16 @@
   */
   
       INTVAL cmp(PMC* value) {
  -        FLOATVAL diff;
  -        diff = PMC_num_val(SELF) - VTABLE_get_number(INTERP, value);
  -        return diff > 0 ? 1 : diff < 0 ? -1 : 0;
  +MMD_Float: {
  +            FLOATVAL diff;
  +            diff = PMC_num_val(SELF) - PMC_num_val(value);
  +            return diff > 0 ? 1 : diff < 0 ? -1 : 0;
  +        }
  +MMD_DEFAULT: {
  +            FLOATVAL diff;
  +            diff = PMC_num_val(SELF) - VTABLE_get_number(INTERP, value);
  +            return diff > 0 ? 1 : diff < 0 ? -1 : 0;
  +        }
       }
   
   /*
  @@ -488,9 +607,16 @@
   */
   
       INTVAL cmp_num(PMC* value) {
  -        FLOATVAL diff;
  -        diff = PMC_num_val(SELF) - VTABLE_get_number(INTERP, value);
  -        return diff > 0 ? 1 : diff < 0 ? -1 : 0;
  +MMD_Float: {
  +            FLOATVAL diff;
  +            diff = PMC_num_val(SELF) - PMC_num_val(value);
  +            return diff > 0 ? 1 : diff < 0 ? -1 : 0;
  +        }
  +MMD_DEFAULT: {
  +            FLOATVAL diff;
  +            diff = PMC_num_val(SELF) - VTABLE_get_number(INTERP, value);
  +            return diff > 0 ? 1 : diff < 0 ? -1 : 0;
  +        }
       }
   
   /*
  
  
  
  1.85      +11 -1     parrot/classes/perlint.pmc
  
  Index: perlint.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/classes/perlint.pmc,v
  retrieving revision 1.84
  retrieving revision 1.85
  diff -u -r1.84 -r1.85
  --- perlint.pmc       9 Dec 2004 13:31:04 -0000       1.84
  +++ perlint.pmc       10 Dec 2004 08:30:35 -0000      1.85
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: perlint.pmc,v 1.84 2004/12/09 13:31:04 leo Exp $
  +$Id: perlint.pmc,v 1.85 2004/12/10 08:30:35 leo Exp $
   
   =head1 NAME
   
  @@ -26,6 +26,16 @@
   /* TODO extends PerlAny or perlscalar or whatever */
   pmclass PerlInt extends Integer {
   
  +/*
  +
  +=item C<void set_pmc(PMC *value)>
  +
  +Sets the value of the number to the value in C<*value>.
  +
  +=cut
  +
  +*/
  +
   
       void set_pmc (PMC* value) {
           perlscalar.SELF.set_pmc(value);
  
  
  
  1.66      +12 -570   parrot/classes/perlnum.pmc
  
  Index: perlnum.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/classes/perlnum.pmc,v
  retrieving revision 1.65
  retrieving revision 1.66
  diff -u -r1.65 -r1.66
  --- perlnum.pmc       28 Sep 2004 11:23:10 -0000      1.65
  +++ perlnum.pmc       10 Dec 2004 08:30:35 -0000      1.66
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: perlnum.pmc,v 1.65 2004/09/28 11:23:10 jrieks Exp $
  +$Id: perlnum.pmc,v 1.66 2004/12/10 08:30:35 leo Exp $
   
   =head1 NAME
   
  @@ -19,76 +19,11 @@
   */
   
   #include "parrot/parrot.h"
  -#include "parrot/perltypes.h"
   
  -pmclass PerlNum extends perlscalar {
  -/*
  -
  -=item C<void* invoke(void* next)>
  -
  -Pythonic object constructor. SELF is a PerlNum Class object. Return a new
  -C<float> object according to 2.1. Built-in Functions.
  -
  -=cut
  -
  -*/
  -    void* invoke(void* next) {
  -        int argcP = REG_INT(3);
  -        PMC *res = pmc_new(interpreter, enum_class_PerlNum);
  -        if (argcP)
  -            VTABLE_set_number_native(interpreter, res,
  -                    VTABLE_get_number(interpreter, REG_PMC(5)));
  -        REG_PMC(5) = res;
  -        return next;
  -    }
  -
  -    void class_init () {
  -        if (pass) {
  -        }
  -    }
  -
  -/*
  -
  -=item C<void init()>
  -
  -Initializes the number to C<0.0>.
  -
  -=cut
  -
  -*/
  -
  -    void init () {
  -        PMC_num_val(SELF) = 0.0;
  -    }
  -
  -/*
  +void Parrot_perlscalar_morph(Interp* , PMC* pmc, INTVAL type);
  +void Parrot_perlscalar_set_pmc(Interp* , PMC* pmc, PMC* value);
   
  -=item C<INTVAL get_integer()>
  -
  -Returns the integer value of the number.
  -
  -=cut
  -
  -*/
  -
  -    INTVAL get_integer () {
  -        return (INTVAL)PMC_num_val(SELF);
  -    }
  -
  -/*
  -
  -=item C<BIGNUM *get_bignum()>
  -
  -Unimplemented. Returns C<NULL>.
  -
  -=cut
  -
  -*/
  -
  -    BIGNUM* get_bignum () {
  -        internal_exception(1, "perlnum: unimp get_bignum");
  -        return NULL;
  -    }
  +pmclass PerlNum extends Float {
   
   /*
   
  @@ -106,50 +41,21 @@
        if (!signbit(PMC_num_val(SELF)))
               sign = "";
           d = fabs(d);
  -        if (Interp_flags_TEST(INTERP, PARROT_PYTHON_MODE)) {
  -            /* XXX make a Python format string */
  -            STRING *s = Parrot_sprintf_c(interpreter, "%s%.12g", sign, d);
  -            if (string_str_index(interpreter, s,
  -                        const_string(interpreter, "."), 0) == -1 &&
  -                    string_str_index(interpreter, s,
  -                        const_string(interpreter, "e"), 0) == -1)
  -                string_append(INTERP, s, const_string(INTERP, ".0"), 0);
  -            return s;
  -        }
  -        return Parrot_sprintf_c(interpreter, "%s" FLOATVAL_FMT, sign, d);
  -    }
  -
  -    STRING* get_repr () {
  -        double d = (double) PMC_num_val(SELF);
  -        const char *sign = "-";
  -     if (!signbit(PMC_num_val(SELF)))
  -            sign = "";
  -        d = fabs(d);
  -        if (Interp_flags_TEST(INTERP, PARROT_PYTHON_MODE)) {
  -            /* XXX make a Python format string */
  -            STRING *s = Parrot_sprintf_c(interpreter, "%s%.17g", sign, d);
  -            if (string_str_index(interpreter, s,
  -                        const_string(interpreter, "."), 0) == -1 &&
  -                    string_str_index(interpreter, s,
  -                        const_string(interpreter, "e"), 0) == -1)
  -                string_append(INTERP, s, const_string(INTERP, ".0"), 0);
  -            return s;
  -        }
           return Parrot_sprintf_c(interpreter, "%s" FLOATVAL_FMT, sign, d);
       }
   
   /*
   
  -=item C<INTVAL get_bool()>
  +=item C<void set_pmc(PMC *value)>
   
  -Evaluates the number as a boolean, i.e. it's true if it's not zero.
  +Sets the value of the number to the value in C<*value>.
   
   =cut
   
   */
   
  -    INTVAL get_bool () {
  -        return (INTVAL)(PMC_num_val(SELF) != 0.0);
  +    void set_pmc (PMC* value) {
  +        perlscalar.SELF.set_pmc(value);
       }
   
   /*
  @@ -189,35 +95,6 @@
   
   /*
   
  -=item C<void set_number_same(PMC* value)>
  -
  -Sets the value of the number to the value of C<*value>.
  -
  -=cut
  -
  -*/
  -
  -    void set_number_same (PMC* value) {
  -        PMC_num_val(SELF) = PMC_num_val(value);
  -    }
  -
  -/*
  -
  -=item C<void set_bignum_native(BIGNUM *value)>
  -
  -Unimplemented. Does nothing.
  -
  -=cut
  -
  -*/
  -
  -    void set_bignum_native (BIGNUM* value) {
  -        internal_exception(1, "perlnum: unimp set_bignum");
  -    }
  -
  -
  -/*
  -
   =item C<void set_string_native(STRING *value)>
   
   Sets the value of the number to the value of C<*value>.
  @@ -235,452 +112,17 @@
   
   /*
   
  -=item C<void add(PMC *value, PMC *dest)>
  -
  -Adds C<*value> to the number and returns the result in C<*dest>.
  -
  -=cut
  -
  -*/
  -
  -    void add (PMC* value, PMC* dest) {
  -        VTABLE_set_number_native(INTERP, dest,
  -            PMC_num_val(SELF) +
  -            VTABLE_get_number(INTERP, value)
  -        );
  -    }
  -
  -/*
  -
  -=item C<void add_int(INTVAL value, PMC *dest)>
  -
  -Adds C<value> to the number and returns the result in C<*dest>.
  -
  -=cut
  -
  -*/
  -
  -    void add_int (INTVAL value, PMC* dest) {
  -        VTABLE_set_number_native(INTERP, dest,
  -            PMC_num_val(SELF) + value);
  -    }
  -
  -
  -/*
  -
  -=item C<void add_float(FLOATVAL value, PMC *dest)>
  -
  -Adds C<value> to the number and returns the result in C<*dest>.
  -
  -=cut
  -
  -*/
  -
  -    void add_float (FLOATVAL value, PMC* dest) {
  -        VTABLE_set_number_native(INTERP, dest,
  -            PMC_num_val(SELF) + value);
  -    }
  -
  -/*
  -
  -=item C<void subtract(PMC *value, PMC *dest)>
  -
  -Subtracts C<*value> from the number and returns the result in C<*dest>.
  -
  -=cut
  -
  -*/
  -
  -    void subtract (PMC* value, PMC* dest) {
  -        VTABLE_set_number_native(INTERP, dest,
  -            PMC_num_val(SELF) -
  -            VTABLE_get_number(INTERP, value)
  -        );
  -    }
  -
  -/*
  -
  -=item C<void subtract_int(INTVAL value, PMC *dest)>
  -
  -Subtracts C<value> from the number and returns the result in C<*dest>.
  -
  -=cut
  -
  -*/
  -
  -    void subtract_int (INTVAL value, PMC* dest) {
  -        VTABLE_set_number_native(INTERP, dest,
  -            PMC_num_val(SELF) - (FLOATVAL)value
  -        );
  -    }
  -
  -
  -/*
  -
  -=item C<void subtract_float(FLOATVAL value, PMC *dest)>
  -
  -Subtracts C<value> from the number and returns the result in C<*dest>.
  -
  -=cut
  -
  -*/
  -
  -    void subtract_float (FLOATVAL value, PMC* dest) {
  -        VTABLE_set_number_native(INTERP, dest,
  -            PMC_num_val(SELF) - value);
  -    }
  -
  -/*
  -
  -=item C<void multiply(PMC *value, PMC *dest)>
  -
  -Multiplies the number by C<*value> and returns the result in C<*dest>.
  -
  -=cut
  -
  -*/
  -
  -    void multiply (PMC* value, PMC* dest) {
  -        VTABLE_set_number_native(INTERP, dest,
  -            PMC_num_val(SELF) *
  -            VTABLE_get_number(INTERP, value)
  -        );
  -    }
  -
  -/*
  -
  -=item C<void multiply_int(INTVAL value, PMC *dest)>
  -
  -Multiplies the number by C<value> and returns the result in C<*dest>.
  -
  -=cut
  -
  -*/
  -
  -    void multiply_int (INTVAL value, PMC* dest) {
  -        VTABLE_set_number_native(INTERP, dest,
  -            PMC_num_val(SELF) * value
  -        );
  -    }
  -
  -/*
  -
  -=item C<void multiply_float(FLOATVAL value, PMC *dest)>
  -
  -Multiplies the number by C<value> and returns the result in C<*dest>.
  -
  -=cut
  -
  -*/
  -
  -    void multiply_float (FLOATVAL value, PMC* dest) {
  -        VTABLE_set_number_native(INTERP, dest,
  -            PMC_num_val(SELF) * value);
  -    }
  -
  -/*
  -
  -=item C<void divide(PMC *value, PMC *dest)>
  -
  -Divides the number by C<*value> and returns the result in C<*dest>.
  -
  -=cut
  -
  -*/
  -
  -    void divide (PMC* value, PMC* dest) {
  -        VTABLE_set_number_native(INTERP, dest,
  -            PMC_num_val(SELF) /
  -            VTABLE_get_number(INTERP, value)
  -        );
  -    }
  -
  -/*
  -
  -=item C<void divide_int(INTVAL value, PMC *dest)>
  -
  -=cut
  -
  -*/
  -
  -    void divide_int (INTVAL value, PMC* dest) {
  -        VTABLE_set_number_native(INTERP, dest,
  -            PMC_num_val(SELF) / value
  -        );
  -    }
  -
  -/*
  -
  -=item C<void divide_float(FLOATVAL value, PMC *dest)>
  -
  -Divides the number by C<value> and returns the result in C<*dest>.
  -
  -=cut
  -
  -*/
  -
  -    void divide_float (FLOATVAL value, PMC* dest) {
  -        VTABLE_set_number_native(INTERP, dest,
  -            PMC_num_val(SELF) / value
  -        );
  -    }
  -
  -/*
  -
  -=item C<void cmodulus(PMC *value, PMC *dest)>
  -
  -Calculates the value of the number C-style C<mod> C<*value> and returns
  -the result in C<*dest>.
  -
  -=cut
  -
  -*/
  -
  -    void cmodulus (PMC* value, PMC* dest) {
  -        FLOATVAL f = VTABLE_get_number(INTERP, value);
  -        VTABLE_set_number_native(INTERP, dest,
  -            fmod(PMC_num_val(SELF), f));
  -    }
  -
  -/*
  -
  -=item C<void cmodulus_float(FLOATVAL value, PMC *dest)>
  -
  -=cut
  -
  -*/
  -
  -    void cmodulus_float (FLOATVAL value, PMC* dest) {
  -        VTABLE_set_number_native(INTERP, dest,
  -            fmod(PMC_num_val(SELF), value));
  -    }
  -
  -/*
  -
  -=item C<void cmodulus_int(INTVAL value, PMC *dest)>
  +=item C<void morph(INTVAL type)>
   
  -Calculates the value of the number C-style C<mod> C<value> and returns
  -the result in C<*dest>.
  +Morphs the scalar to the specified type.
   
   =cut
   
   */
   
  -    void cmodulus_int (INTVAL value, PMC* dest) {
  -        VTABLE_set_number_native(INTERP, dest,
  -            fmod(PMC_num_val(SELF), value));
  +    void morph (INTVAL type) {
  +        perlscalar.SELF.morph(type);
       }
  -
  -/*
  -
  -=item C<void modulus(PMC *value, PMC *dest)>
  -
  -Calculates the value of the number C<mod> C<*value> and returns the
  -result in C<*dest>.
  -
  -=cut
  -
  -*/
  -
  -    void modulus (PMC* value, PMC* dest) {
  -        FLOATVAL f = VTABLE_get_number(INTERP, value);
  -        VTABLE_set_number_native(INTERP, dest,
  -            floatval_mod(PMC_num_val(SELF), f));
  -    }
  -
  -/*
  -
  -=item C<void modulus_float(FLOATVAL value, PMC *dest)>
  -
  -=cut
  -
  -*/
  -
  -    void modulus_float (FLOATVAL value, PMC* dest) {
  -        VTABLE_set_number_native(INTERP, dest,
  -            floatval_mod(PMC_num_val(SELF), value));
  -    }
  -
  -/*
  -
  -=item C<void modulus_int(INTVAL value, PMC *dest)>
  -
  -Calculates the value of the number C<mod> C<value> and returns the
  -result in C<*dest>.
  -
  -=cut
  -
  -*/
  -
  -    void modulus_int (INTVAL value, PMC* dest) {
  -        VTABLE_set_number_native(INTERP, dest,
  -            floatval_mod(PMC_num_val(SELF), value));
  -    }
  -
  -/*
  -
  -=item C<void neg(PMC *dest)>
  -
  -If C<dest> is true, then the negation of the number is returned in
  -C<*dest>. Otherwise the number itself is negated.
  -
  -=cut
  -
  -*/
  -
  -    void neg (PMC * dest) {
  -        if (!dest)
  -            PMC_num_val(SELF) = -PMC_num_val(SELF);
  -        else
  -            VTABLE_set_number_native(INTERP, dest, -PMC_num_val(SELF));
  -    }
  -
  -/*
  -
  -=item C<INTVAL is_equal(PMC* value)>
  -
  -The C<==> operation.
  -
  -=cut
  -
  -*/
  -
  -    INTVAL is_equal (PMC* value) {
  -        return (INTVAL)(PMC_num_val(SELF) == VTABLE_get_number(INTERP, 
value));
  -    }
  -
  -/*
  -
  -=item C<INTVAL cmp(PMC* value)>
  -
  -
  -
  -=cut
  -
  -*/
  -
  -    INTVAL cmp(PMC* value) {
  -        FLOATVAL diff;
  -        diff = PMC_num_val(SELF) - VTABLE_get_number(INTERP, value);
  -        return diff > 0 ? 1 : diff < 0 ? -1 : 0;
  -    }
  -
  -/*
  -
  -=item C<INTVAL cmp_num(PMC *value)>
  -
  -Returns the result of comparing the number with C<*value>.
  -
  -=cut
  -
  -*/
  -
  -    INTVAL cmp_num(PMC* value) {
  -        FLOATVAL diff;
  -        diff = PMC_num_val(SELF) - VTABLE_get_number(INTERP, value);
  -        return diff > 0 ? 1 : diff < 0 ? -1 : 0;
  -    }
  -
  -/*
  -
  -=item C<void repeat(PMC *value, PMC *dest)>
  -
  -=cut
  -
  -*/
  -
  -    void repeat (PMC* value, PMC* dest) {
  -        internal_exception(INVALID_OPERATION,
  -            "repeat() not implemented in class 'PerlNum'\n");
  -    }
  -
  -/*
  -
  -=item C<void repeat_int(INTVAL value, PMC *dest)>
  -
  -These two methods raise an "invalid operation" exception.
  -
  -=cut
  -
  -*/
  -
  -    void repeat_int (INTVAL value, PMC* dest) {
  -        internal_exception(INVALID_OPERATION,
  -            "repeat() not implemented in class 'PerlNum'\n");
  -    }
  -
  -/*
  -
  -=item C<void increment()>
  -
  -Increments the number.
  -
  -=cut
  -
  -*/
  -
  -    void increment () {
  -        PMC_num_val(SELF) ++;
  -    }
  -
  -/*
  -
  -=item C<void decrement()>
  -
  -Decrements the number.
  -
  -=cut
  -
  -*/
  -
  -    void decrement () {
  -        PMC_num_val(SELF) --;
  -    }
  -/*
  -
  -=item C<void absolute()>
  -
  -Sets C<dest> to the absolute value of SELF.
  -
  -=cut
  -
  -*/
  -
  -    void absolute(PMC *dest) {
  -        VTABLE_set_number_native(INTERP, dest, fabs(PMC_num_val(SELF)));
  -    }
  -
  -/*
  -
  -=item C<void freeze(visit_info *info)>
  -
  -Used to archive the number.
  -
  -=cut
  -
  -*/
  -    void freeze(visit_info *info) {
  -        IMAGE_IO *io = info->image_io;
  -        SUPER(info);
  -        io->vtable->push_float(INTERP, io, PMC_num_val(SELF));
  -    }
  -
  -/*
  -
  -=item C<void thaw(visit_info *info)>
  -
  -Used to unarchive the number.
  -
  -=cut
  -
  -*/
  -    void thaw(visit_info *info) {
  -        IMAGE_IO *io = info->image_io;
  -        SUPER(info);
  -        if (info->extra_flags == EXTRA_IS_NULL)
  -            PMC_num_val(SELF) = io->vtable->shift_float(INTERP, io);
  -    }
  -
   }
   
   /*
  
  
  
  1.61      +3 -1      parrot/lib/Parrot/Pmc2c.pm
  
  Index: Pmc2c.pm
  ===================================================================
  RCS file: /cvs/public/parrot/lib/Parrot/Pmc2c.pm,v
  retrieving revision 1.60
  retrieving revision 1.61
  diff -u -r1.60 -r1.61
  --- Pmc2c.pm  2 Dec 2004 10:47:57 -0000       1.60
  +++ Pmc2c.pm  10 Dec 2004 08:30:36 -0000      1.61
  @@ -1,5 +1,5 @@
   # Copyright: 2004 The Perl Foundation.  All Rights Reserved.
  -# $Id: Pmc2c.pm,v 1.60 2004/12/02 10:47:57 leo Exp $
  +# $Id: Pmc2c.pm,v 1.61 2004/12/10 08:30:36 leo Exp $
   
   =head1 NAME
   
  @@ -577,6 +577,8 @@
       while ($total_body =~ s/\bMMD_(\w+):\s*//) {
           my $right_type = $1;
           my $body_part = extract_bracketed($total_body, '{');
  +        die "Empty MMD body near '$total_body'"
  +            if (!$body_part);
           $body_part = substr($body_part, 1, -1);
           if ($right_type eq 'DEFAULT') {
               $standard_body = $body_part
  
  
  

Reply via email to