/*
Copyright (C) 2001-2003, The Perl Foundation.
$Id: ref.pmc 16275 2006-12-28 01:20:44Z particle $

=head1 NAME

src/pmc/ref.pmc - Reference to a PMC

=head1 DESCRIPTION

The vtable functions for the Ref base class.

All methods not present below get a default body autogenerated inside
C<Parrot::Pmc2c>.

=head2 Methods

=over 4

=cut

*/

#include "parrot/parrot.h"

pmclass Ref does ref {

/*

=item C<void init()>

Sets the referenced PMC to C<PMCNULL>.

=cut

*/

    void init() {
        SELF.init_pmc(PMCNULL);
    }

    void destroy() {
        SELF.init_pmc(NULL);
        /* don't pass it on */
    }

/*

=item C<void init_pmc(PMC *initializer)>

Sets the referenced PMC to C<initializer>.

=cut

*/

    void init_pmc(PMC* initializer) {
        PMC_pmc_val(SELF) = initializer; /* the referred PMC itself */
        PObj_custom_mark_SET(SELF);
        if (initializer) {
            /*
             * if referred PMC needs active destruction
             * we have to pass it on
             */
            if (PObj_active_destroy_TEST(initializer))
                PObj_active_destroy_SET(SELF);
        }
    }

/*

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

Sets the referenced PMC to C<*other>.

=item C<PMC* get_pmc()>

Get the referenced PMC.

=cut

*/

    void set_pmc(PMC* other) {
        PObj_active_destroy_CLEAR(SELF);
        DOD_WRITE_BARRIER(INTERP, SELF, PMC_pmc_val(SELF), other);
        SELF.init_pmc(other);
    }
    void assign_pmc(PMC* other) {
        SELF.set_pmc(other);   /* audreyt */
    }

    PMC* get_pmc() {
        return PMC_pmc_val(SELF);
    }

/*

=item C<void mark()>

Marks the referenced PMC as live.

=cut

*/

    void mark() {
        pobject_lives(INTERP, (PObj *) PMC_pmc_val(SELF));
    }

/*

=back

These two methods must be implemented because they are not delegated.

=over 4

=item C<STRING *name()>

Returns the name of the PMC, not the name of the referenced PMC.

=cut

*/

    STRING* name() {
        return SUPER();
    }
}

/*

=back

=head1 HISTORY

Initial revision by leo 2003.09.01.

Allowed null value by TOGoS 2004.07.28 (evil+bad?)

=cut

*/

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