/* tclobject.pmc
 *  Copyright (C) 2001-2003, The Perl Foundation.
 *  SVN Info
 *     $Id: tclobject.pmc 14896 2006-10-11 14:34:56Z particle $
 *  Overview:
 *     These are the vtable functions for the tclobject base class
 *  Data Structure and Algorithms:
 *    The following primary native types exist that we wish to track:
 *    strings, integers, floats, lists {@array}, arrays, {%hash}.
 *    when parsing code, everything starts out as a string. When we ask
 *    for another representation, we do the conversion once and store it.
 *    this way, the next time it's needed, we can just return it. Several
 *    commands may generate a native type without first going through the
 *    string representation - by avoiding conversion to and from string,
 *    we can maintain a speed enhancement.
 *  History:
 *  Notes:
 *  References:
 */

#include "parrot/parrot.h"

static INTVAL dynpmc_TclString;
static INTVAL dynpmc_TclFloat;
static INTVAL dynpmc_TclInt;

pmclass TclObject dynpmc group tcl_group {

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

    void morph (INTVAL type) {
        if (SELF->vtable->base_type == type)
            return;
        switch (type) {
            case enum_class_String:
                type = dynpmc_TclString;
                break;
            case enum_class_Integer:
                type = dynpmc_TclInt;
                break;
            case enum_class_Float:
                type = dynpmc_TclFloat;
                break;
        }
        pmc_reuse(INTERP, SELF, type, 0);
    }

    void set_integer_native (INTVAL value) {
        DYNSELF.morph(dynpmc_TclInt);
        PMC_int_val(SELF) = value;
    }

    void set_number_native (FLOATVAL value) {
        DYNSELF.morph(dynpmc_TclFloat);
        PMC_num_val(SELF) = value;
    }

    void set_string_native (STRING* value) {
        DYNSELF.morph(dynpmc_TclString);
        PMC_str_val(SELF) = string_copy(INTERP, value);
    }
}

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