/*
 * $Id: /mirror/trunk/languages/dotnet/pmc/int64.pmc 26661 2008-03-31T04:10:11.023606Z chromatic  $
 * Copyright (C) 2006-2008, The Perl Foundation.
 */

/* .NET 64-bit signed integer PMC */

#include "parrot/extend.h"
#include "tableinfo.h"
#include "structures.h"


pmclass Int64 dynpmc group dotnet_runtime {

    /* Instance initialization. We need a custom destroy. */
    void init()
    {
        dotnet_int64 *i      = mem_allocate_typed(dotnet_int64);
        PMC_struct_val(SELF) = i;
        i->x                 = 0;
        PObj_active_destroy_SET(SELF);
    }


    /* Destructor. */
    void destroy()
    {
        /* Cleanup any memory we're using. */
        if (PMC_struct_val(SELF)) {
            mem_sys_free(PMC_struct_val(SELF));
            PMC_struct_val(SELF) = NULL;
        }
    }


    /* Lower bits are integer assign, upper bits are PMC method. */
    void set_integer_native(INTVAL low)
    {
        dotnet_int64 *i = (dotnet_int64 *)PMC_struct_val(SELF);
        i->x = (i->x & 0xFFFFFFFF00000000) | low;
    }

    METHOD void set_high_bits(int high)
    {
        dotnet_int64 *i = (dotnet_int64 *)PMC_struct_val(SELF);
        i->x = (i->x & 0xFFFFFFFF) | ((HUGEINTVAL)high << 32);
    }

    /* Get integer casts back to integer; methods to get high and low 32s. */
    INTVAL get_integer()
    {
        dotnet_int64 *i = (dotnet_int64 *)PMC_struct_val(SELF);
        return (int) i->x;
    }

    METHOD INTVAL get_low_bits()
    {
        dotnet_int64 *i = (dotnet_int64 *)PMC_struct_val(SELF);
        INTVAL        result = (INTVAL)(i->x & 0xFFFFFFFF);
        RETURN(INTVAL result);
    }

    METHOD INTVAL get_high_bits()
    {
        dotnet_int64 *i = (dotnet_int64 *)PMC_struct_val(SELF);
        INTVAL        result = (INTVAL)(i->x >> 32);
        RETURN(INTVAL result);
    }
}


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