示例#1
0
OVL_EXTERN bool ConvC16( stack_entry *entry, conv_class from )
{
    if( !ConvC20( entry, from ) ) return( FALSE );
    DToLD( (double)LDToD( &entry->v.cmplx.re ), &entry->v.cmplx.re );
    DToLD( (double)LDToD( &entry->v.cmplx.im ), &entry->v.cmplx.im );
    return( TRUE );
}
示例#2
0
OVL_EXTERN bool ConvC8( stack_entry *entry, conv_class from )
{
    if( !ConvC20( entry, from ) ) return( false );
    DToLD( (float)LDToD( &entry->v.cmplx.re ), &entry->v.cmplx.re );
    DToLD( (float)LDToD( &entry->v.cmplx.im ), &entry->v.cmplx.im );
    return( true );
}
示例#3
0
OVL_EXTERN bool ConvU8( stack_entry *entry, conv_class from )
{
    unsigned_64  tmp;

    switch( from ) {
    case U1:
    case U2:
    case U4:
    case U8:
        tmp = entry->v.uint;
        break;
    case I1:
    case I2:
    case I4:
    case I8:
        tmp = entry->v.sint;
        break;
    case F4:
    case F8:
    case F10:
        //NYI: 64-bit support
        I32ToI64( LDToD( &entry->v.real ), &tmp );
        break;
    case C8:
    case C16:
    case C20:
        I32ToI64( LDToD( &entry->v.cmplx.re ), &tmp );
        break;
    case NP2:
    case NP4:
        //NYI: 64-bit offsets
        U32ToU64( entry->v.addr.mach.offset, &tmp );
        break;
    case FP4:
    case HP4:
        U32ToU64( entry->v.addr.mach.offset +
                ((long) entry->v.addr.mach.segment << 16), &tmp );
        break;
    case FP6:
        U32ToU64( entry->v.addr.mach.offset, &tmp );
        break;
    default:
        return( FALSE );
    }
    entry->v.uint = tmp;
    return( TRUE );
}
示例#4
0
/*
 * ConvertTo -- convert 'entry' to the given 'class'.
 *      'entry' should be an rvalue.
 */
void ConvertTo( stack_entry *entry, type_kind k, type_modifier m, unsigned s )
{
    conv_class  from;
    char        *dest;

    if( s == 0 && k == TK_INTEGER ) {
        s = DefaultSize( DK_INT );
    }
    if( entry->info.kind == k
     && entry->info.modifier == m
     && entry->info.size == s ) return;
    from = ConvIdx( &entry->info );
    switch( from ) {
    case U1:
        U32ToU64( U8FetchTrunc( entry->v.uint ), &entry->v.uint );
        break;
    case U2:
        U32ToU64( U16FetchTrunc( entry->v.uint ), &entry->v.uint );
        break;
    case U4:
        U32ToU64( U32FetchTrunc( entry->v.uint ), &entry->v.uint );
        break;
    case I1:
        I32ToI64( I8FetchTrunc( entry->v.uint ), &entry->v.uint );
        break;
    case I2:
        I32ToI64( I16FetchTrunc( entry->v.uint ), &entry->v.uint );
        break;
    case I4:
        I32ToI64( I32FetchTrunc( entry->v.uint ), &entry->v.uint );
        break;
    case F4:
        DToLD( (float)LDToD( &entry->v.real ), &entry->v.real );
        break;
    case F8:
        DToLD( (double)LDToD( &entry->v.real ), &entry->v.real );
        break;
    case C8:
        DToLD( (float)LDToD( &entry->v.cmplx.re ), &entry->v.cmplx.re );
        DToLD( (float)LDToD( &entry->v.cmplx.im ), &entry->v.cmplx.im );
        break;
    case C16:
        DToLD( (double)LDToD( &entry->v.cmplx.re ), &entry->v.cmplx.re );
        DToLD( (double)LDToD( &entry->v.cmplx.im ), &entry->v.cmplx.im );
        break;
    case NP2:
    case FP4:
        entry->v.addr.mach.offset &= 0xffff;
        break;
    case STR:
        if( k != TK_STRING ) {
            Error( ERR_NONE, LIT( ERR_TYPE_CONVERSION ) );
        }
        if( s > entry->info.size ) {
            /* have to expand string */
            _ChkAlloc( dest, s, LIT( ERR_NO_MEMORY_FOR_EXPR ) );
            memcpy( dest, entry->v.string.loc.e[0].u.p, entry->info.size );
            memset( &dest[entry->info.size], ' ', s - entry->info.size );
            if( AllocatedString( entry ) ) {
                _Free( entry->v.string.allocated );
            }
            entry->v.string.allocated = dest;
            LocationCreate( &entry->v.string.loc, LT_INTERNAL, dest );
        }
        break;
    default:
        break;
    }
    entry->info.kind = k;
    entry->info.modifier = m;
    entry->info.size = s;
    if( !ConvFunc[ ConvIdx( &entry->info ) ]( entry, from ) ) {
        Error( ERR_NONE, LIT( ERR_TYPE_CONVERSION ) );
    }
    entry->th = NULL;
}
示例#5
0
OVL_EXTERN bool ConvR8( stack_entry *entry, conv_class from )
{
    if( !ConvR10( entry, from ) ) return( FALSE );
    DToLD( (double)LDToD( &entry->v.real ), &entry->v.real );
    return( TRUE );
}
示例#6
0
void ToItem( stack_entry *entry, item_mach *tmp )
{
    unsigned            size;
    mad_type_info       src_type;
    mad_type_info       dst_type;

    if( entry->info.size > sizeof( *tmp ) ) {
        Error( ERR_NONE, LIT( ERR_TYPE_CONVERSION ) );
    }
    //NYI: use MAD routines for all conversions
    size = entry->info.size;
    switch( entry->info.kind ) {
    case TK_BOOL:
    case TK_ENUM:
    case TK_CHAR:
    case TK_INTEGER:
        MADTypeInfo( MADTypeForDIPType( &entry->info ), &dst_type );
        if( (entry->info.modifier & TM_MOD_MASK) == TM_SIGNED ) {
            MADTypeInfoForHost( MTK_INTEGER, -(int)sizeof( entry->v.sint ), &src_type );
        } else {
            MADTypeInfoForHost( MTK_INTEGER, sizeof( entry->v.sint ), &src_type );
        }
        MADTypeConvert( &src_type, &entry->v.uint, &dst_type, tmp, 0 );
        return;
    case TK_REAL:
        MADTypeInfo( MADTypeForDIPType( &entry->info ), &dst_type );
        MADTypeInfoForHost( MTK_FLOAT, sizeof( entry->v.real ), &src_type );
        MADTypeConvert( &src_type, &entry->v.real, &dst_type, tmp, 0 );
        return;
    case TK_COMPLEX:
        switch( size ) {
        case 8:
            tmp->sc.re = LDToD( &entry->v.cmplx.re );
            tmp->sc.im = LDToD( &entry->v.cmplx.im );
            return;
        case 16:
            tmp->lc.re = LDToD( &entry->v.cmplx.re );
            tmp->lc.im = LDToD( &entry->v.cmplx.im );
            return;
        case 20:
            tmp->xc = entry->v.cmplx;
            return;
        }
        break;
    case TK_POINTER:
    case TK_ADDRESS:
        switch( entry->info.modifier & TM_MOD_MASK ) {
        case TM_NEAR:
            switch( size ) {
            case 2:
                tmp->so = entry->v.addr.mach.offset;
                return;
            case 4:
                tmp->lo = entry->v.addr.mach.offset;
                return;
            case 8:
                tmp->qo.u._32[I64LO32] = entry->v.addr.mach.offset;
                tmp->qo.u._32[I64HI32] = 0;
            }
            break;
        case TM_FAR:
        case TM_HUGE:
            switch( size ) {
            case 4:
                ConvAddr48ToAddr32( entry->v.addr.mach, tmp->sa );
                return;
            case 6:
                tmp->la = entry->v.addr.mach;
                return;
            }
            break;
        }
        break;
    }
    Error( ERR_NONE, LIT( ERR_TYPE_CONVERSION ) );
}
示例#7
0
OVL_EXTERN bool ConvR4( stack_entry *entry, conv_class from )
{
    if( !ConvR10( entry, from ) ) return( false );
    DToLD( (float)LDToD( &entry->v.real ), &entry->v.real );
    return( true );
}