/*
Copyright (C) 2006-2008, The Perl Foundation.
$Id: /mirror/trunk/languages/WMLScript/pmc/wmlsinteger.pmc 34379 2008-12-25T15:52:38.013371Z fperrad  $

=head1 NAME

pmc/wmlsinteger.pmc - WMLScript Integer

=head1 DESCRIPTION

C<WmlsInteger> extends C<Integer> to provide a class with the behaviour of
the WMLScript C<Integer> type.

=head2 Methods

=over 4

=cut

*/

#include "parrot/embed.h"
#include "pmc_wmlsstring.h"

static INTVAL dynpmc_WmlsBoolean;
static INTVAL dynpmc_WmlsFloat;
static INTVAL dynpmc_WmlsInteger;
static INTVAL dynpmc_WmlsInvalid;
static INTVAL dynpmc_WmlsString;

static inline INTVAL num_cmp(FLOATVAL v1, FLOATVAL v2)
{
    if (v1 == v2) {
        return 0;
    }
    else if (v1 > v2) {
        return 1;
    }
    else {
        return -1;
    }
}

static inline INTVAL int_cmp(INTVAL v1, INTVAL v2)
{
    if (v1 == v2) {
        return 0;
    }
    else if (v1 > v2) {
        return 1;
    }
    else {
        return -1;
    }
}


pmclass WmlsInteger
    extends Integer
    provides scalar
    provides integer
    dynpmc
    group wmls_group
    hll wmlscript maps Integer {

/* Class initialization. Caches constant strings that will be used later.
*/
    void class_init() {
        if (pass) {
            dynpmc_WmlsBoolean = pmc_type(INTERP,
              const_string(INTERP, "WmlsBoolean"));
            dynpmc_WmlsFloat = pmc_type(INTERP,
              const_string(INTERP, "WmlsFloat"));
            dynpmc_WmlsInteger = pmc_type(INTERP,
              const_string(INTERP, "WmlsInteger"));
            dynpmc_WmlsInvalid = pmc_type(INTERP,
              const_string(INTERP, "WmlsInvalid"));
            dynpmc_WmlsString = pmc_type(INTERP,
              const_string(INTERP, "WmlsString"));
        }
    }

/*

=item C<PMC* get_class()>

Return the integer 0.

=cut

*/
    VTABLE PMC* get_class() {
        PMC* retval = pmc_new(interp, dynpmc_WmlsInteger);
        PMC_int_val(retval) = 0;
        return retval;
    }

/*

=item C<PMC* neg(PMC *dest)>

=item C<void i_neg()>

=cut

*/
    VTABLE PMC* neg(PMC* dest) {
        dest = pmc_new(INTERP, dynpmc_WmlsInteger);
        PMC_int_val(dest) = - SELF.get_integer();
        return dest;
    }

    VTABLE void i_neg() {
        INTVAL result = - SELF.get_integer();
        SELF.set_integer_native(result);
    }

/*

=item C<PMC* bitwise_not(PMC *dest)>

=item C<void i_bitwise_not()>

=cut

*/
    VTABLE PMC* bitwise_not(PMC* dest) {
        dest = pmc_new(INTERP, dynpmc_WmlsInteger);
        PMC_int_val(dest) = ~ SELF.get_integer();
        return dest;
    }

    VTABLE void i_bitwise_not() {
        INTVAL result = ~ SELF.get_integer();
        SELF.set_integer_native(result);
    }

/*

=item C<PMC* logical_not(PMC *dest)>

=item C<void i_logical_not()>

=cut

*/
    VTABLE PMC* logical_not(PMC* dest) {
        dest = pmc_new(INTERP, dynpmc_WmlsBoolean);
        VTABLE_set_bool(INTERP, dest, ! SELF.get_bool());
        return dest;
    }

    VTABLE void i_logical_not() {
        INTVAL result = ! SELF.get_bool();
        SELF.morph(dynpmc_WmlsBoolean);
        SELF.set_integer_native(result);
    }

/*

=back

=head2 non-Vtable Methods

=over 4

=item C<void add(PMC *value, PMC *dest)>

=item C<void i_add(PMC *value)>

=cut

*/
    MULTI PMC* add(WmlsInteger value, PMC* dest) {
        INTVAL result = SELF.get_integer()
                      + VTABLE_get_integer(INTERP, value);
        dest = pmc_new(INTERP, dynpmc_WmlsInteger);
        VTABLE_set_integer_native(INTERP, dest, result);
        return dest;
    }

    MULTI PMC* add(WmlsBoolean value, PMC* dest) {
        INTVAL result = SELF.get_integer()
                      + VTABLE_get_integer(INTERP, value);
        dest = pmc_new(INTERP, dynpmc_WmlsInteger);
        VTABLE_set_integer_native(INTERP, dest, result);
        return dest;
    }

    MULTI PMC* add(WmlsFloat value, PMC* dest) {
        FLOATVAL result = SELF.get_number()
                        + VTABLE_get_number(INTERP, value);
        dest = pmc_new(INTERP, dynpmc_WmlsFloat);
        VTABLE_set_number_native(INTERP, dest, result);
        return dest;
    }

    MULTI PMC* add(WmlsString value, PMC* dest) {
        STRING* result = string_concat(INTERP,
            SELF.get_string(),
            VTABLE_get_string(INTERP, value), 0);
        dest = pmc_new(INTERP, dynpmc_WmlsString);
        VTABLE_set_string_native(INTERP, dest, result);
        return dest;
    }

    MULTI PMC* add(DEFAULT value, PMC* dest) {
        return pmc_new(INTERP, dynpmc_WmlsInvalid);
    }

    MULTI void i_add(WmlsInteger value) {
        INTVAL result = SELF.get_integer()
                      + VTABLE_get_integer(INTERP, value);
        SELF.set_integer_native(result);
    }

    MULTI void i_add(WmlsBoolean value) {
        INTVAL result = SELF.get_integer()
                      + VTABLE_get_integer(INTERP, value);
        SELF.set_integer_native(result);
    }

    MULTI void i_add(WmlsFloat value) {
        FLOATVAL result = SELF.get_number()
                        + VTABLE_get_number(INTERP, value);
        SELF.morph(dynpmc_WmlsFloat);
        SELF.set_number_native(result);
    }

    MULTI void i_add(WmlsString value) {
        STRING* result = string_concat(INTERP,
            SELF.get_string(),
            VTABLE_get_string(INTERP, value), 0);
        SELF.morph(dynpmc_WmlsString);
        SELF.set_string_native(result);
    }

    MULTI void i_add(DEFAULT value) {
        SELF.morph(dynpmc_WmlsInvalid);
    }

/*

=item C<PMC* subtract(PMC *value, PMC *dest)>

=item C<void i_subtract(PMC *value)>

=cut

*/
    MULTI PMC* subtract(WmlsInteger value, PMC* dest) {
        INTVAL result = SELF.get_integer()
                      - VTABLE_get_integer(INTERP, value);
        dest = pmc_new(INTERP, dynpmc_WmlsInteger);
        VTABLE_set_integer_native(INTERP, dest, result);
        return dest;
    }

    MULTI PMC* subtract(WmlsBoolean value, PMC* dest) {
        INTVAL result = SELF.get_integer()
                      - VTABLE_get_integer(INTERP, value);
        dest = pmc_new(INTERP, dynpmc_WmlsInteger);
        VTABLE_set_integer_native(INTERP, dest, result);
        return dest;
    }

    MULTI PMC* subtract(WmlsFloat value, PMC* dest) {
        FLOATVAL result = SELF.get_number()
                        - VTABLE_get_number(INTERP, value);
        dest = pmc_new(INTERP, dynpmc_WmlsFloat);
        VTABLE_set_number_native(INTERP, dest, result);
        return dest;
    }

    MULTI PMC* subtract(WmlsString value, PMC* dest) {
        PMC *trans;
        Parrot_PCCINVOKE(interp, value, const_string(interp, "parseInt"),
            "->P", &trans);

        if (trans->vtable->base_type == dynpmc_WmlsInteger) {
            INTVAL result = SELF.get_integer()
                          - VTABLE_get_integer(INTERP, trans);
            dest = pmc_new(INTERP, dynpmc_WmlsInteger);
            VTABLE_set_integer_native(INTERP, dest, result);
            return dest;
        }
        return pmc_new(INTERP, dynpmc_WmlsInvalid);
    }

    MULTI PMC* subtract(DEFAULT value, PMC* dest) {
        return pmc_new(INTERP, dynpmc_WmlsInvalid);
    }

    MULTI void i_subtract(WmlsInteger value) {
        INTVAL result = SELF.get_integer()
                      - VTABLE_get_integer(INTERP, value);
        SELF.set_integer_native(result);
    }

    MULTI void i_subtract(WmlsBoolean value) {
        INTVAL result = SELF.get_integer()
                      - VTABLE_get_integer(INTERP, value);
        SELF.set_integer_native(result);
    }

    MULTI void i_subtract(WmlsFloat value) {
        FLOATVAL result = SELF.get_number()
                        - VTABLE_get_number(INTERP, value);
        SELF.morph(dynpmc_WmlsFloat);
        SELF.set_number_native(result);
    }

    MULTI void i_subtract(WmlsString value) {
        PMC *trans;
        Parrot_PCCINVOKE(interp, value, const_string(interp, "parseInt"),
            "->P", &trans);

        if (trans->vtable->base_type == dynpmc_WmlsInteger) {
            INTVAL result = SELF.get_integer()
                          - VTABLE_get_integer(INTERP, trans);
            SELF.set_integer_native(result);
        }
        else {
            SELF.morph(dynpmc_WmlsInvalid);
        }
    }

    MULTI void i_subtract(DEFAULT value) {
        SELF.morph(dynpmc_WmlsInvalid);
    }

/*

=item C<PMC* multiply(PMC *value, PMC *dest)>

=item C<void i_multiply(PMC *value)>

=cut

*/
    MULTI PMC* multiply(WmlsInteger value, PMC* dest) {
        INTVAL result = SELF.get_integer()
                      * VTABLE_get_integer(INTERP, value);
        dest = pmc_new(INTERP, dynpmc_WmlsInteger);
        VTABLE_set_integer_native(INTERP, dest, result);
        return dest;
    }

    MULTI PMC* multiply(WmlsBoolean value, PMC* dest) {
        INTVAL result = SELF.get_integer()
                      * VTABLE_get_integer(INTERP, value);
        dest = pmc_new(INTERP, dynpmc_WmlsInteger);
        VTABLE_set_integer_native(INTERP, dest, result);
        return dest;
    }

    MULTI PMC* multiply(WmlsFloat value, PMC* dest) {
        FLOATVAL result = SELF.get_number()
                        * VTABLE_get_number(INTERP, value);
        dest = pmc_new(INTERP, dynpmc_WmlsFloat);
        VTABLE_set_number_native(INTERP, dest, result);
        return dest;
    }

    MULTI PMC* multiply(WmlsString value, PMC* dest) {
        PMC *trans;
        Parrot_PCCINVOKE(interp, value, const_string(interp, "parseInt"),
            "->P", &trans);

        if (trans->vtable->base_type == dynpmc_WmlsInteger) {
            INTVAL result = SELF.get_integer()
                          * VTABLE_get_integer(INTERP, trans);
            dest = pmc_new(INTERP, dynpmc_WmlsInteger);
            VTABLE_set_integer_native(INTERP, dest, result);
            return dest;
        }
        return pmc_new(INTERP, dynpmc_WmlsInvalid);
    }

    MULTI PMC* multiply(DEFAULT value, PMC* dest) {
        return pmc_new(INTERP, dynpmc_WmlsInvalid);
    }

    MULTI void i_multiply(WmlsInteger value) {
        INTVAL result = SELF.get_integer()
                      * VTABLE_get_integer(INTERP, value);
        SELF.set_integer_native(result);
    }

    MULTI void i_multiply(WmlsBoolean value) {
        INTVAL result = SELF.get_integer()
                      * VTABLE_get_integer(INTERP, value);
        SELF.set_integer_native(result);
    }

    MULTI void i_multiply(WmlsFloat value) {
        FLOATVAL result = SELF.get_number()
                        * VTABLE_get_number(INTERP, value);
        SELF.morph(dynpmc_WmlsFloat);
        SELF.set_number_native(result);
    }

    MULTI void i_multiply(WmlsString value) {
        PMC *trans;
        Parrot_PCCINVOKE(interp, value, const_string(interp, "parseInt"),
            "->P", &trans);

        if (trans->vtable->base_type == dynpmc_WmlsInteger) {
            INTVAL result = SELF.get_integer()
                          * VTABLE_get_integer(INTERP, trans);
            SELF.set_integer_native(result);
        }
        else {
            SELF.morph(dynpmc_WmlsInvalid);
        }
    }

    MULTI void i_multiply(DEFAULT value) {
        SELF.morph(dynpmc_WmlsInvalid);
    }

/*

=item C<PMC* divide(PMC *value, PMC *dest)>

=item C<void i_divide(PMC *value)>

=cut

*/
    MULTI PMC* divide(WmlsFloat value, PMC* dest) {
        FLOATVAL d = VTABLE_get_number(INTERP, value);
        if (d != 0.0) {
            FLOATVAL result = SELF.get_number() / d;
            dest = pmc_new(INTERP, dynpmc_WmlsFloat);
            VTABLE_set_number_native(INTERP, dest, result);
            return dest;
        }
        return pmc_new(INTERP, dynpmc_WmlsInvalid);
    }

    MULTI PMC* divide(WmlsInteger value, PMC* dest) {
        FLOATVAL d = VTABLE_get_number(INTERP, value);
        if (d != 0.0) {
            FLOATVAL result = SELF.get_number() / d;
            dest = pmc_new(INTERP, dynpmc_WmlsFloat);
            VTABLE_set_number_native(INTERP, dest, result);
            return dest;
        }
        return pmc_new(INTERP, dynpmc_WmlsInvalid);
    }

    MULTI PMC* divide(WmlsBoolean value, PMC* dest) {
        FLOATVAL d = VTABLE_get_number(INTERP, value);
        if (d != 0.0) {
            FLOATVAL result = SELF.get_number() / d;
            dest = pmc_new(INTERP, dynpmc_WmlsFloat);
            VTABLE_set_number_native(INTERP, dest, result);
            return dest;
        }
        return pmc_new(INTERP, dynpmc_WmlsInvalid);
    }

    MULTI PMC* divide(WmlsString value, PMC* dest) {
        PMC *trans;
        Parrot_PCCINVOKE(interp, value, const_string(interp, "parseInt"),
            "->P", &trans);

        if (trans->vtable->base_type == dynpmc_WmlsInteger) {
            FLOATVAL d = VTABLE_get_number(INTERP, trans);
            if (d != 0.0) {
                FLOATVAL result = SELF.get_number() / d;
                dest = pmc_new(INTERP, dynpmc_WmlsFloat);
                VTABLE_set_number_native(INTERP, dest, result);
                return dest;
            }
        }
        return pmc_new(INTERP, dynpmc_WmlsInvalid);
    }

    MULTI PMC* divide(DEFAULT value, PMC* dest) {
        return pmc_new(INTERP, dynpmc_WmlsInvalid);
    }

    MULTI void i_divide(WmlsFloat value) {
        FLOATVAL d = VTABLE_get_number(INTERP, value);
        if (d != 0.0) {
            FLOATVAL result = SELF.get_number() / d;
            SELF.morph(dynpmc_WmlsFloat);
            SELF.set_number_native(result);
        }
        else {
            SELF.morph(dynpmc_WmlsInvalid);
        }
    }

    MULTI void i_divide(WmlsInteger value) {
        FLOATVAL d = VTABLE_get_number(INTERP, value);
        if (d != 0.0) {
            FLOATVAL result = SELF.get_number() / d;
            SELF.morph(dynpmc_WmlsFloat);
            SELF.set_number_native(result);
        }
        else {
            SELF.morph(dynpmc_WmlsInvalid);
        }
    }

    MULTI void i_divide(WmlsBoolean value) {
        FLOATVAL d = VTABLE_get_number(INTERP, value);
        if (d != 0.0) {
            FLOATVAL result = SELF.get_number() / d;
            SELF.morph(dynpmc_WmlsFloat);
            SELF.set_number_native(result);
        }
        else {
            SELF.morph(dynpmc_WmlsInvalid);
        }
    }

    MULTI void i_divide(WmlsString value) {
        PMC *trans;
        Parrot_PCCINVOKE(interp, value, const_string(interp, "parseInt"),
            "->P", &trans);

        if (trans->vtable->base_type == dynpmc_WmlsInteger) {
            FLOATVAL d = VTABLE_get_integer(INTERP, trans);
            if (d != 0.0) {
                FLOATVAL result = SELF.get_number() / d;
                SELF.morph(dynpmc_WmlsFloat);
                SELF.set_number_native(result);
            }
            else {
                SELF.morph(dynpmc_WmlsInvalid);
            }
        }
        else {
            SELF.morph(dynpmc_WmlsInvalid);
        }
    }

    MULTI void i_divide(DEFAULT value) {
        SELF.morph(dynpmc_WmlsInvalid);
    }

/*

=item C<PMC* floor_divide(PMC *value, PMC *dest)>

=item C<void i_floor_divide(PMC *value)>

=cut

*/
    MULTI PMC* floor_divide(WmlsInteger value, PMC* dest) {
        INTVAL d = VTABLE_get_integer(INTERP, value);
        if (d != 0) {
            INTVAL result = SELF.get_integer() / d;
            dest = pmc_new(INTERP, dynpmc_WmlsInteger);
            VTABLE_set_integer_native(INTERP, dest, result);
            return dest;
        }
        return pmc_new(INTERP, dynpmc_WmlsInvalid);
    }

    MULTI PMC* floor_divide(WmlsBoolean value, PMC* dest) {
        INTVAL d = VTABLE_get_integer(INTERP, value);
        if (d != 0) {
            INTVAL result = SELF.get_integer() / d;
            dest = pmc_new(INTERP, dynpmc_WmlsInteger);
            VTABLE_set_integer_native(INTERP, dest, result);
            return dest;
        }
        return pmc_new(INTERP, dynpmc_WmlsInvalid);
    }

    MULTI PMC* floor_divide(WmlsString value, PMC* dest) {
        PMC *trans;
        Parrot_PCCINVOKE(interp, value, const_string(interp, "parseInt"),
            "->P", &trans);

        if (trans->vtable->base_type == dynpmc_WmlsInteger) {
            INTVAL d = VTABLE_get_integer(INTERP, trans);
            if (d != 0) {
                INTVAL result = SELF.get_integer() / d;
                dest = pmc_new(INTERP, dynpmc_WmlsInteger);
                VTABLE_set_integer_native(INTERP, dest, result);
                return dest;
            }
        }
        return pmc_new(INTERP, dynpmc_WmlsInvalid);
    }

    MULTI PMC* floor_divide(DEFAULT value, PMC* dest) {
        return pmc_new(INTERP, dynpmc_WmlsInvalid);
    }

    MULTI void i_floor_divide(WmlsInteger value) {
        INTVAL d = VTABLE_get_integer(INTERP, value);
        if (d != 0) {
            INTVAL result = SELF.get_integer() / d;
            SELF.set_integer_native(result);
        }
        else {
            SELF.morph(dynpmc_WmlsInvalid);
        }
    }

    MULTI void i_floor_divide(WmlsBoolean value) {
        INTVAL d = VTABLE_get_integer(INTERP, value);
        if (d != 0) {
            INTVAL result = SELF.get_integer() / d;
            SELF.set_integer_native(result);
        }
        else {
            SELF.morph(dynpmc_WmlsInvalid);
        }
    }

    MULTI void i_floor_divide(WmlsString value) {
        PMC *trans;
        Parrot_PCCINVOKE(interp, value, const_string(interp, "parseInt"),
            "->P", &trans);

        if (trans->vtable->base_type == dynpmc_WmlsInteger) {
            INTVAL d = VTABLE_get_integer(INTERP, trans);
            if (d != 0) {
                INTVAL result = SELF.get_integer() / d;
                SELF.set_integer_native(result);
            }
            else {
                SELF.morph(dynpmc_WmlsInvalid);
            }
        }
        else {
            SELF.morph(dynpmc_WmlsInvalid);
        }
    }

    MULTI void i_floor_divide(DEFAULT value) {
        SELF.morph(dynpmc_WmlsInvalid);
    }

/*

=item C<PMC* modulus(PMC *value, PMC *dest)>

=item C<void i_modulus(PMC *value)>

=cut

*/
    MULTI PMC* modulus(WmlsInteger value, PMC* dest) {
        INTVAL d = VTABLE_get_integer(INTERP, value);
        if (d != 0) {
            INTVAL result = SELF.get_integer() % d;
            dest = pmc_new(INTERP, dynpmc_WmlsInteger);
            VTABLE_set_integer_native(INTERP, dest, result);
            return dest;
        }
        return pmc_new(INTERP, dynpmc_WmlsInvalid);
    }

    MULTI PMC* modulus(WmlsBoolean value, PMC* dest) {
        INTVAL d = VTABLE_get_integer(INTERP, value);
        if (d != 0) {
            INTVAL result = SELF.get_integer() % d;
            dest = pmc_new(INTERP, dynpmc_WmlsInteger);
            VTABLE_set_integer_native(INTERP, dest, result);
            return dest;
        }
        return pmc_new(INTERP, dynpmc_WmlsInvalid);
    }

    MULTI PMC* modulus(WmlsString value, PMC* dest) {
        PMC *trans;
        Parrot_PCCINVOKE(interp, value, const_string(interp, "parseInt"),
            "->P", &trans);

        if (trans->vtable->base_type == dynpmc_WmlsInteger) {
            INTVAL d = VTABLE_get_integer(INTERP, trans);
            if (d != 0) {
                INTVAL result = SELF.get_integer() % d;
                dest = pmc_new(INTERP, dynpmc_WmlsInteger);
                VTABLE_set_integer_native(INTERP, dest, result);
                return dest;
            }
        }
        return pmc_new(INTERP, dynpmc_WmlsInvalid);
    }

    MULTI PMC* modulus(DEFAULT value, PMC* dest) {
        return pmc_new(INTERP, dynpmc_WmlsInvalid);
    }

    MULTI void i_modulus(WmlsInteger value) {
        INTVAL d = VTABLE_get_integer(INTERP, value);
        if (d != 0) {
            INTVAL result = SELF.get_integer() % d;
            SELF.set_integer_native(result);
        }
        else {
            SELF.morph(dynpmc_WmlsInvalid);
        }
    }

    MULTI void i_modulus(WmlsBoolean value) {
        INTVAL d = VTABLE_get_integer(INTERP, value);
        if (d != 0) {
            INTVAL result = SELF.get_integer() % d;
            SELF.set_integer_native(result);
        }
        else {
            SELF.morph(dynpmc_WmlsInvalid);
        }
    }

    MULTI void i_modulus(WmlsString value) {
        PMC *trans;
        Parrot_PCCINVOKE(interp, value, const_string(interp, "parseInt"),
            "->P", &trans);

        if (trans->vtable->base_type == dynpmc_WmlsInteger) {
            INTVAL d = VTABLE_get_integer(INTERP, trans);
            if (d != 0) {
                INTVAL result = SELF.get_integer() % d;
                SELF.set_integer_native(result);
            }
            else {
                SELF.morph(dynpmc_WmlsInvalid);
            }
        }
        else {
            SELF.morph(dynpmc_WmlsInvalid);
        }
    }

    MULTI void i_modulus(DEFAULT value) {
        SELF.morph(dynpmc_WmlsInvalid);
    }

/*

=item C<PMC* bitwise_or(PMC *value, PMC *dest)>

=item C<void i_bitwise_or(PMC *value)>

=cut

*/
    VTABLE PMC* bitwise_or(PMC* value, PMC* dest) {
        if (value->vtable->base_type == dynpmc_WmlsString) {
            Parrot_PCCINVOKE(interp, value, const_string(interp, "parseInt"),
                    "->P", &value);
        }
        if (value->vtable->base_type == dynpmc_WmlsInteger
          || value->vtable->base_type == dynpmc_WmlsBoolean) {
            INTVAL result = SELF.get_integer()
                          | VTABLE_get_integer(INTERP, value);
            dest = pmc_new(INTERP, dynpmc_WmlsInteger);
            VTABLE_set_integer_native(INTERP, dest, result);
            return dest;
        }
        else {
            return pmc_new(INTERP, dynpmc_WmlsInvalid);
        }
    }

    VTABLE void i_bitwise_or(PMC* value) {
        if (value->vtable->base_type == dynpmc_WmlsString) {
            Parrot_PCCINVOKE(interp, value, const_string(interp, "parseInt"),
                    "->P", &value);
        }
        if (value->vtable->base_type == dynpmc_WmlsInteger
          || value->vtable->base_type == dynpmc_WmlsBoolean) {
            INTVAL result = SELF.get_integer()
                          | VTABLE_get_integer(INTERP, value);
            SELF.morph(dynpmc_WmlsInteger);
            SELF.set_integer_native(result);
        }
        else {
            SELF.morph(dynpmc_WmlsInvalid);
        }
    }

/*

=item C<PMC* bitwise_and(PMC *value, PMC *dest)>

=item C<void i_bitwise_and(PMC *value)>

=cut

*/
    VTABLE PMC* bitwise_and(PMC* value, PMC* dest) {
        if (value->vtable->base_type == dynpmc_WmlsString) {
            Parrot_PCCINVOKE(interp, value, const_string(interp, "parseInt"),
                    "->P", &value);
        }
        if (value->vtable->base_type == dynpmc_WmlsInteger
          || value->vtable->base_type == dynpmc_WmlsBoolean) {
            INTVAL result = SELF.get_integer()
                          & VTABLE_get_integer(INTERP, value);
            dest = pmc_new(INTERP, dynpmc_WmlsInteger);
            VTABLE_set_integer_native(INTERP, dest, result);
            return dest;
        }
        else {
            return pmc_new(INTERP, dynpmc_WmlsInvalid);
        }
    }

    VTABLE void i_bitwise_and(PMC* value) {
        if (value->vtable->base_type == dynpmc_WmlsString) {
            Parrot_PCCINVOKE(interp, value, const_string(interp, "parseInt"),
                    "->P", &value);
        }
        if (value->vtable->base_type == dynpmc_WmlsInteger
          || value->vtable->base_type == dynpmc_WmlsBoolean) {
            INTVAL result = SELF.get_integer()
                          & VTABLE_get_integer(INTERP, value);
            SELF.morph(dynpmc_WmlsInteger);
            SELF.set_integer_native(result);
        }
        else {
            SELF.morph(dynpmc_WmlsInvalid);
        }
    }

/*

=item C<void bitwise_xor(PMC *value, PMC *dest)>

=item C<void i_bitwise_xor(PMC *value)>

=cut

*/
    VTABLE PMC* bitwise_xor(PMC* value, PMC* dest) {
        if (value->vtable->base_type == dynpmc_WmlsString) {
            Parrot_PCCINVOKE(interp, value, const_string(interp, "parseInt"),
                    "->P", &value);
        }
        if (value->vtable->base_type == dynpmc_WmlsInteger
          || value->vtable->base_type == dynpmc_WmlsBoolean) {
            INTVAL result = SELF.get_integer()
                          ^ VTABLE_get_integer(INTERP, value);
            dest = pmc_new(INTERP, dynpmc_WmlsInteger);
            VTABLE_set_integer_native(INTERP, dest, result);
            return dest;
        }
        else {
            return pmc_new(INTERP, dynpmc_WmlsInvalid);
        }
    }

    VTABLE void i_bitwise_xor(PMC* value) {
        if (value->vtable->base_type == dynpmc_WmlsString) {
            Parrot_PCCINVOKE(interp, value, const_string(interp, "parseInt"),
                    "->P", &value);
        }
        if (value->vtable->base_type == dynpmc_WmlsInteger
          || value->vtable->base_type == dynpmc_WmlsBoolean) {
            INTVAL result = SELF.get_integer()
                          ^ VTABLE_get_integer(INTERP, value);
            SELF.morph(dynpmc_WmlsInteger);
            SELF.set_integer_native(result);
        }
        else {
            SELF.morph(dynpmc_WmlsInvalid);
        }
    }

/*

=item C<PMC* bitwise_shr(PMC *value, PMC *dest)>

=item C<void i_bitwise_shr(PMC *value)>

=cut

*/
    VTABLE PMC* bitwise_shr(PMC* value, PMC* dest) {
        if (value->vtable->base_type == dynpmc_WmlsString) {
            Parrot_PCCINVOKE(interp, value, const_string(interp, "parseInt"),
                    "->P", &value);
        }
        if (value->vtable->base_type == dynpmc_WmlsInteger
          || value->vtable->base_type == dynpmc_WmlsBoolean) {
            INTVAL result = SELF.get_integer()
                          >> VTABLE_get_integer(INTERP, value);
            dest = pmc_new(INTERP, dynpmc_WmlsInteger);
            VTABLE_set_integer_native(INTERP, dest, result);
            return dest;
        }
        else {
            return pmc_new(INTERP, dynpmc_WmlsInvalid);
        }
    }

    VTABLE void i_bitwise_shr(PMC* value) {
        if (value->vtable->base_type == dynpmc_WmlsString) {
            Parrot_PCCINVOKE(interp, value, const_string(interp, "parseInt"),
                    "->P", &value);
        }
        if (value->vtable->base_type == dynpmc_WmlsInteger
          || value->vtable->base_type == dynpmc_WmlsBoolean) {
            INTVAL result = SELF.get_integer()
                          >> VTABLE_get_integer(INTERP, value);
            SELF.morph(dynpmc_WmlsInteger);
            SELF.set_integer_native(result);
        }
        else {
            SELF.morph(dynpmc_WmlsInvalid);
        }
    }

/*

=item C<PMC* bitwise_lsr(PMC *value, PMC *dest)>

=item C<void i_bitwise_lsr(PMC *value)>

=cut

*/
    VTABLE PMC* bitwise_lsr(PMC* value, PMC* dest) {
        if (value->vtable->base_type == dynpmc_WmlsString) {
            Parrot_PCCINVOKE(interp, value, const_string(interp, "parseInt"),
                    "->P", &value);
        }
        if (value->vtable->base_type == dynpmc_WmlsInteger
          || value->vtable->base_type == dynpmc_WmlsBoolean) {
            INTVAL result = SELF.get_integer()
                          >> VTABLE_get_integer(INTERP, value);
            dest = pmc_new(INTERP, dynpmc_WmlsInteger);
            VTABLE_set_integer_native(INTERP, dest, result);
            return dest;
        }
        else {
            return pmc_new(INTERP, dynpmc_WmlsInvalid);
        }
    }

    VTABLE void i_bitwise_lsr(PMC* value) {
        if (value->vtable->base_type == dynpmc_WmlsString) {
            Parrot_PCCINVOKE(interp, value, const_string(interp, "parseInt"),
                    "->P", &value);
        }
        if (value->vtable->base_type == dynpmc_WmlsInteger
          || value->vtable->base_type == dynpmc_WmlsBoolean) {
            INTVAL result = SELF.get_integer()
                          >> VTABLE_get_integer(INTERP, value);
            SELF.morph(dynpmc_WmlsInteger);
            SELF.set_integer_native(result);
        }
        else {
            SELF.morph(dynpmc_WmlsInvalid);
        }
    }

/*

=item C<PMC* bitwise_shl(PMC *value, PMC *dest)>

=item C<void i_bitwise_shl(PMC *value)>

=cut

*/
    VTABLE PMC* bitwise_shl(PMC* value, PMC* dest) {
        if (value->vtable->base_type == dynpmc_WmlsString) {
            Parrot_PCCINVOKE(interp, value, const_string(interp, "parseInt"),
                    "->P", &value);
        }
        if (value->vtable->base_type == dynpmc_WmlsInteger
          || value->vtable->base_type == dynpmc_WmlsBoolean) {
            INTVAL result = SELF.get_integer()
                          << VTABLE_get_integer(INTERP, value);
            dest = pmc_new(INTERP, dynpmc_WmlsInteger);
            VTABLE_set_integer_native(INTERP, dest, result);
            return dest;
        }
        else {
            return pmc_new(INTERP, dynpmc_WmlsInvalid);
        }
    }

    VTABLE void i_bitwise_shl(PMC* value) {
        if (value->vtable->base_type == dynpmc_WmlsString) {
            Parrot_PCCINVOKE(interp, value, const_string(interp, "parseInt"),
                    "->P", &value);
        }
        if (value->vtable->base_type == dynpmc_WmlsInteger
          || value->vtable->base_type == dynpmc_WmlsBoolean) {
            INTVAL result = SELF.get_integer()
                          << VTABLE_get_integer(INTERP, value);
            SELF.morph(dynpmc_WmlsInteger);
            SELF.set_integer_native(result);
        }
        else {
            SELF.morph(dynpmc_WmlsInvalid);
        }
    }

/*

=item C<PMC* is_equal(PMC* value)>

=cut

*/
    MULTI INTVAL is_equal(WmlsFloat value) {
        return SELF.get_number() == VTABLE_get_number(INTERP, value);
    }

    MULTI INTVAL is_equal(WmlsInteger value) {
        return SELF.get_integer() == VTABLE_get_integer(INTERP, value);
    }

    MULTI INTVAL is_equal(WmlsBoolean value) {
        return SELF.get_integer() == VTABLE_get_integer(INTERP, value);
    }

    MULTI INTVAL is_equal(WmlsString value) {
        return !string_equal(INTERP,
            SELF.get_string(), VTABLE_get_string(INTERP, value));
    }

    MULTI INTVAL is_equal(DEFAULT value) {
        return 4;
    }

/*

=item C<PMC* cmp(PMC *value)>

=cut

*/
    MULTI INTVAL cmp(WmlsFloat value) {
        return num_cmp(SELF.get_number(),
                       VTABLE_get_number(INTERP, value));
    }

    MULTI INTVAL cmp(WmlsInteger value) {
        return int_cmp(SELF.get_integer(),
                       VTABLE_get_integer(INTERP, value));
    }

    MULTI INTVAL cmp(WmlsBoolean value) {
        return int_cmp(SELF.get_integer(),
                       VTABLE_get_integer(INTERP, value));
    }

    MULTI INTVAL cmp(WmlsString value) {
        return string_compare(INTERP,
            SELF.get_string(), VTABLE_get_string(INTERP, value));
    }

    MULTI INTVAL cmp(DEFAULT value) {
        return 4;
    }

}

/*

=back

=cut

*/


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