static void PushBaseSize( void ) { DIPHDL( type, th ); dip_type_info ti; TypeBase( ExprSP->th, th, NULL, NULL ); TypeInfo( th, ExprSP->lc, &ti ); PushNum( ti.size ); }
static bool IsCodePointer( stack_entry *entry ) { DIPHDL( type, base_th ); dip_type_info ti; if( entry->th == NULL ) return( FALSE ); if( TypeBase( entry->th, base_th, NULL, NULL ) != DS_OK ) return( FALSE ); if( TypeInfo( base_th, entry->lc, &ti ) != DS_OK ) return( FALSE ); switch( ti.kind ) { case TK_CODE: case TK_FUNCTION: return( TRUE ); } return( FALSE ); }
void DoAPoints( stack_entry *stk, type_kind def ) { stack_flags was_imp_addr; addr_off off; LRValue( stk ); was_imp_addr = stk->flags & SF_IMP_ADDR; switch( stk->info.kind ) { case TK_BOOL: case TK_ENUM: case TK_CHAR: case TK_INTEGER: //NYI: 64 bit offsets off = U32FetchTrunc( stk->v.uint ); stk->v.addr = DefAddrSpaceForAddr( Context.execution ); stk->v.addr.mach.offset = off; stk->info.modifier = TM_NEAR; /* fall through */ case TK_POINTER: case TK_ADDRESS: if( stk->th != NULL ) { LocationCreate( &stk->v.loc, LT_ADDR, &stk->v.addr ); TypeBase( stk->th, stk->th, stk->lc, &stk->v.loc ); ClassifyEntry( stk, &stk->info ); if( stk->info.kind == TK_VOID ) Error( ERR_NONE, LIT( ERR_VOID_BASE ) ); } else { if( def == TK_NONE ) def = TK_INTEGER; stk->info.kind = def; switch( def ) { case TK_INTEGER: stk->info.modifier = TM_UNSIGNED; stk->info.size = DefaultSize( DK_INT ); break; case TK_ADDRESS: ExprSetAddrInfo( stk, FALSE ); break; } LocationCreate( &stk->v.loc, LT_ADDR, &stk->v.addr ); } stk->flags |= SF_LOCATION | was_imp_addr; break; default: Error( ERR_NONE, LIT( ERR_ILL_TYPE ) ); break; } stk->flags &= ~SF_CONST; }
static unsigned MechDo( unsigned select, unsigned parm ) { unsigned long size; unsigned result = 0; DIPHDL( type, th ); dip_type_info info; mad_type_info mti; switch( select ) { case 0: DoAssign(); break; case 1: DoMul(); break; case 2: DoDiv(); break; case 3: DoMod(); break; case 4: DoMinus(); break; case 5: DoShift(); break; case 6: DoAnd(); break; case 7: DoXor(); break; case 8: DoOr(); break; case 9: DoAddr(); break; case 10: ClassToTypeInfo( parm, &info ); DoPoints( info.kind ); break; case 11: DoField(); break; case 12: DoCall( Num, parm ); break; case 13: DoConvert(); break; case 14: DoPlus(); break; case 15: MakeAddr(); break; case 16: result = TstEQ( parm ); break; case 17: result = TstLT( parm ); break; case 18: result = TstTrue( parm ); break; case 19: result = TstExist( parm ); break; case 20: size = ExprSP->info.size; PopEntry(); PushNum( size ); break; case 21: TypeBase( ExprSP->th, th, NULL, NULL ); PopEntry(); PushType( th ); break; case 22: GetMADTypeDefault( MTK_ADDRESS, &mti ); size = (mti.b.bits - mti.a.seg.bits) / BITS_PER_BYTE; if( parm ) { size += sizeof( addr_seg ); TypePointer( ExprSP->th, TM_FAR, size, th ); } else { TypePointer( ExprSP->th, TM_NEAR, size, th ); } PopEntry(); PushType( th ); break; case 23: result = UserType( th ); if( result ) { PopEntry(); PushType( th ); } break; case 24: DoMakeComplex(); break; case 25: DoStringConcat(); break; case 26: DoLConvert(); break; case 27: DoPlusScaled(); break; case 28: DoMinusScaled(); break; case 29: DoPoints( TI_KIND_EXTRACT( parm ) ); break; case 30: info.kind = TK_POINTER; info.size = TI_SIZE_EXTRACT( parm ); info.modifier = TI_MOD_EXTRACT( parm ); FillInDefaults( &info ); TypePointer( ExprSP->th, info.modifier, info.size, th ); PopEntry(); PushType( th ); break; case 31: if( parm ) { /* file scope */ if( ExprSP->flags & SF_NAME ) { ExprSP->v.li.file_scope = TRUE; } else { Error( ERR_LOC, LIT( ERR_WANT_NAME ) ); } } else { /* in a namespace */ DoScope(); } break; } return( result ); }
void LRValue( stack_entry *entry ) { location_list ll; item_mach tmp; bool extend; mad_type_info mti; DIPHDL( type, th ); ExprResolve( entry ); if( entry->flags & SF_LOCATION ) { if( entry->info.kind == TK_FUNCTION || entry->info.kind == TK_CODE ) { /* rvalue of procedure is its address */ entry->v.addr = entry->v.loc.e[0].u.addr; ExprSetAddrInfo( entry, FALSE ); entry->info.kind = TK_ADDRESS; } else if( !AddressExpression( entry ) ) { extend = FALSE; switch( entry->info.kind ) { case TK_ARRAY: /* rvalue of array is its address */ entry->v.addr = entry->v.loc.e[0].u.addr; if( entry->th != NULL ) { /* change typing from "array of..." to "pointer to..." */ GetMADTypeDefaultAt( entry->v.addr, MTK_ADDRESS, &mti ); TypeBase( entry->th, th, NULL, NULL ); TypePointer( th, TM_FAR, mti.b.bits / BITS_PER_BYTE, entry->th ); TypeInfo( entry->th, entry->lc, &entry->info ); } else { ExprSetAddrInfo( entry, FALSE ); } break; case TK_STRING: _ChkAlloc( entry->v.string.allocated, entry->info.size, LIT( ERR_NO_MEMORY_FOR_EXPR ) ); LocationCreate( &ll, LT_INTERNAL, entry->v.string.allocated ); if( LocationAssign( &ll, &entry->v.loc, entry->info.size, FALSE ) != DS_OK ) { _Free( entry->v.string.allocated ); Error( ERR_NONE, LIT( ERR_NO_ACCESS ) ); } entry->v.string.loc = ll; break; case TK_BOOL: case TK_CHAR: case TK_ENUM: case TK_INTEGER: if( (entry->info.modifier & TM_MOD_MASK) == TM_SIGNED ) extend = TRUE; /* fall through */ default: LocationCreate( &ll, LT_INTERNAL, &tmp ); if( LocationAssign( &ll, &entry->v.loc, entry->info.size, extend ) != DS_OK ) { Error( ERR_NONE, LIT( ERR_NO_ACCESS ) ); } FromItem( &tmp, entry ); break; } } entry->flags &= ~(SF_LOCATION | SF_IMP_ADDR); } if( entry->info.kind == TK_POINTER && (entry->info.modifier & TM_MOD_MASK) == TM_NEAR ) { NearToFar( entry ); } }