/* TclArray.pmc
 *  Copyright (C) 2001-2003, The Perl Foundation.
 *  SVN Info
 *     $Id: tclarray.pmc 15326 2006-11-10 07:22:36Z coke $
 *  Overview:
 *     These are the vtable functions for the TclArray base class
 *  Data Structure and Algorithms:
 *  History:
 *  Notes:
 *  References:

=head1 NAME

pmc/tclarray.pmc - Tcl Array PMC

=head1 DESCRIPTION

This is the Array PMC for the Tcl implementation.

=head2 Functions

=over 4

=cut

 */

#include "parrot/parrot.h"

static INTVAL dynpmc_TclString;

pmclass TclArray
    need_ext
    dynpmc
    extends Hash
    does    hash
    group   tcl_group
    hll     Tcl
    maps    Hash
{

/*

=item C<void class_init()>

Initializes variables needed by the class.

=cut

*/

    void class_init () {
        if (pass) {
            dynpmc_TclString = pmc_type(INTERP,
                string_from_const_cstring(INTERP, "TclString", 0));
        }
    }

/*

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

Copy the contents of other to self.

=cut

*/

    void assign_pmc (PMC *other) {
        STRING *hash   = string_from_const_cstring(INTERP, "hash", 4);
        STRING *undef  = string_from_const_cstring(INTERP, "Undef", 5);

        if (VTABLE_does(INTERP, other, hash))
        {
            PMC *iter = pmc_new_init(INTERP, enum_class_Iterator, other);

            pmc_reuse(INTERP, SELF, SELF->vtable->base_type, 0);
            while (VTABLE_get_bool(INTERP, iter))
            {
                STRING *key   = VTABLE_shift_string(INTERP, iter);
                PMC    *value = VTABLE_get_pmc_keyed_str(INTERP, other, key);
                VTABLE_set_pmc_keyed_str(INTERP, SELF, key, value);
            }
        }
        else if (VTABLE_isa(INTERP, other, undef))
        {
            pmc_reuse(INTERP, SELF, other->vtable->base_type, 0);
        }
        else
        {
            real_exception(INTERP, NULL, E_TypeError,
                           "unable to assign self to this type");
        }
    }

}

/*

=back

=cut

*/

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