/* TclInt.pmc
 *  Copyright (C) 2001-2003, The Perl Foundation.
 *  SVN Info
 *     $Id: tclint.pmc 15174 2006-11-07 18:01:55Z paultcochrane $
 *  Overview:
 *     These are the vtable functions for the TclInt base class
 *  Data Structure and Algorithms:
 *  History:
 *  References:
 */

#include "parrot/parrot.h"

pmclass TclInt
    dynpmc
    extends TclObject
    extends Integer
    does    integer
    group   tcl_group
    hll     Tcl
    maps    Integer
{

    /*
     * MMD Override:
     *   TclInt shouldn't automatically promote division to float.
     */
    PMC* divide (PMC* value, PMC* dest) {
      MMD_TclInt: {
        INTVAL n = PMC_int_val(SELF);
        INTVAL d = PMC_int_val(value);

        if (d == 0)
            real_exception(INTERP, NULL, E_ZeroDivisionError, "divide by zero");

        if (!dest)
            dest = pmc_new(INTERP, SELF->vtable->base_type);

        VTABLE_set_integer_native(INTERP, dest, n / d);
        return dest;
      }
      MMD_DEFAULT: {
        FLOATVAL d = VTABLE_get_number(INTERP, value);

        if (d == 0.0)
            real_exception(INTERP, NULL, E_ZeroDivisionError,
                           "float division by zero");

        if (!dest)
            dest = pmc_new(INTERP, SELF->vtable->base_type);
        VTABLE_set_number_native(INTERP, dest, DYNSELF.get_number() / d);
        return dest;
      }
    }

    METHOD PMC* interpret() {
        return SELF;
    }

}

/*
 * Local variables:
 *   c-file-style: "parrot"
 * End:
 * vim: expandtab shiftwidth=4:
 */
