/*
Copyright (C) 2001-2007, The Perl Foundation.
$Id: /mirror/trunk/src/pmc/pointer.pmc 33204 2008-11-25T03:53:21.729029Z tewk  $

=head1 NAME

src/pmc/pointer.pmc - Pointer

=head1 DESCRIPTION

These are the vtable functions for the Pointer base class.

The actual pointer is in C<PMC_data>.

=head2 Methods

=over 4

=cut

*/

#include "parrot/parrot.h"

pmclass Pointer need_ext {

/*

=item C<void init()>

Initializes the pointer.

=cut

*/

    VTABLE void init() {
        PObj_custom_mark_SET(SELF);
    }

/*

=item C<void morph(INTVAL type)>

Does nothing.

=cut

*/

    VTABLE void morph(INTVAL type) {
    }

/*

=item C<void mark()>

Marks the pointer as live.

=cut

*/

    VTABLE void mark() {
        void (*mark_function)(Interp *, void *) =
            (void (*)(Interp *, void *))D2FPTR(PMC_struct_val(SELF));

        if (PMC_data(SELF) && PMC_struct_val(SELF))
            (*mark_function)(INTERP, PMC_data(SELF));
    }

/*

=item C<PMC *clone()>

Creates and returns a clone of the pointer.

=cut

*/

    VTABLE PMC *clone() {
        PMC * const dest = pmc_new_noinit(INTERP, SELF->vtable->base_type);
        PObj_custom_mark_SET(dest);
        PMC_data(dest) = PMC_data(SELF);
        return dest;
    }

/*

=item C<INTVAL get_integer()>

Returns the pointer value as an integer.

=cut

*/

    VTABLE INTVAL get_integer() {
        return (INTVAL)PMC_data(SELF);
    }

/*

=item C<FLOATVAL get_number()>

Returns the pointer value as a floating-point number.

=cut

*/

    VTABLE FLOATVAL get_number() {
        return (FLOATVAL)(INTVAL)PMC_data(SELF);
    }

/*

=item C<STRING *get_repr()>

Returns the pointer value as a Parrot string.

=cut

*/

    VTABLE STRING *get_repr() {
        return Parrot_sprintf_c(INTERP, "Pointer = 0x%p", PMC_data(SELF));
    }


/*

=item C<STRING *get_string()>

Returns the pointer value as a Parrot string.

=cut

*/

    VTABLE STRING *get_string() {
        return Parrot_sprintf_c(INTERP, "%s", PMC_data(SELF));
    }

/*

=item C<INTVAL get_bool()>

Returns whether the pointer is not C<NULL>.

=cut

*/

    VTABLE INTVAL get_bool() {
        return (INTVAL)(PMC_data(SELF) != NULL);
    }

/*

=item C<INTVAL is_same(PMC *pmc2)>

Returns whether the pointer has the same value as C<*pmc2>.

=cut

*/

    VTABLE INTVAL is_same(PMC *pmc2) {
        return (INTVAL)(SELF->vtable   == pmc2->vtable &&
                        PMC_data(SELF) == PMC_data(pmc2));
    }
}

/*

=back

=cut

*/

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