/*
Copyright (C) 2001-2007, The Perl Foundation.
$Id: /mirror/trunk/src/pmc/boolean.pmc 26316 2008-03-11T09:50:21.102015Z allison  $

=head1 NAME

src/pmc/boolean.pmc - Boolean PMC

=head1 DESCRIPTION

This class implements a boolean value variable.

Albeit the C<Boolean PMC> is derived from the C<Integer PMC>,
it doesn't morph to other types. Only its value is changed.

=head2 Methods

=over 4

=cut

*/

#include "parrot/parrot.h"

pmclass Boolean extends Integer provides boolean provides scalar {

/*

=item C<PMC *instantiate(PMC *sig)>

Object constructor. SELF is a Boolean Class object. Return a new
C<bool> object according to the passed PMC value.

=cut

*/
    VTABLE PMC *instantiate(PMC *sig) {
        /* XXX other types */
        const int argcP = REG_INT(interp, 3);
        PMC * const res = pmc_new(interp, enum_class_Boolean);

        if (argcP)
            PMC_int_val(res) = VTABLE_get_bool(interp, REG_PMC(interp, 5));

        return PMCNULL; /* TODO */
    }
/*

=item C<STRING *get_string()>

Return "1" or "0".

=cut

*/
    VTABLE STRING *get_string() {
        return SUPER();
    }


/*

=item C<void set_integer_native(INTVAL value)>

=item C<void set_bool(INTVAL value)>

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

=cut

*/
    VTABLE void set_integer_native(INTVAL value) {
        PMC_int_val(SELF) = (value != 0);
    }


    VTABLE void set_bool(INTVAL value) {
        PMC_int_val(SELF) = (value != 0);
    }

/*

=item C<void set_number_native(FLOATVAL value)>

Sets the value to C<value> evaluated in a boolean context.

=cut

*/

    VTABLE void set_number_native(FLOATVAL value) {
        PMC_int_val(SELF) = !FLOAT_IS_ZERO(value);
    }

/*

=item C<void set_string_native(STRING *value)>

Sets the value to C<*value> evaluated in a boolean context.

=cut

*/

    VTABLE void set_string_native(STRING *value) {
        PMC_int_val(SELF) = string_bool(INTERP, value);
    }
}

/*

=back

=cut

*/

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