From 7140870656e6f53f09e75cbb51eaebe306f70025 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 22 Apr 2000 20:44:26 +0000 Subject: [PATCH] 20000422-22:47 GMT+1 Victor Szakats --- harbour/ChangeLog | 20 +++++++++++++++++++ harbour/contrib/rdd_ads/ads1.c | 2 +- harbour/include/hbexprb.c | 22 ++++++++++++++++----- harbour/include/hbexprc.c | 12 ++++++------ harbour/include/hbmacro.h | 2 ++ harbour/source/compiler/genc.c | 4 ++-- harbour/source/compiler/harbour.c | 32 ++++++++++++++++--------------- harbour/source/compiler/harbour.y | 9 ++++++--- harbour/source/rtl/gtpca/gtpca.c | 2 +- harbour/source/vm/hvm.c | 23 +++++++++++++++++++++- harbour/source/vm/macro.c | 11 +++++++++++ 11 files changed, 105 insertions(+), 34 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 8f76d17d90..3630d7155c 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,23 @@ +20000422-22:47 GMT+1 Victor Szakats + + * include/hbexprb.c + * include/hbexprc.c + * include/hbmacro.h + * source/compiler/harbour.y + * source/vm/macro.c + % Compiler now generates HB_P_DOSHORT and HB_P_FUNCTIONSHORT pcodes where + possible. + + * source/compiler/genc.c + ! Fixed pcode generation (-gc1/2) for PUSHSYMNEAR + + * source/rtl/gtpca/gtpca.c + * contrib/rdd_ads/ads1.c + ! Fixed broken trace calls. + + * source/compiler/harbour.c + ! GCC -O2 warning fixed. + 20000422-21:36 GMT+1 Victor Szakats * include/hbpcode.h diff --git a/harbour/contrib/rdd_ads/ads1.c b/harbour/contrib/rdd_ads/ads1.c index 928e2aa231..9f52798840 100644 --- a/harbour/contrib/rdd_ads/ads1.c +++ b/harbour/contrib/rdd_ads/ads1.c @@ -985,7 +985,7 @@ static ERRCODE adsOrderInfo( ADSAREAP pArea, USHORT uiIndex, LPDBORDERINFO pOrde UNSIGNED8 aucBuffer[MAX_STR_LEN + 1]; UNSIGNED16 pusLen = MAX_STR_LEN; - HB_TRACE(HB_TR_DEBUG, ("adsOrderInfo(%p, %hu, %p)", pArea, uiIndex, pInfo)); + HB_TRACE(HB_TR_DEBUG, ("adsOrderInfo(%p, %hu, %p)", pArea, uiIndex, pOrderInfo)); if( pOrderInfo->itmOrder && !HB_IS_NIL(pOrderInfo->itmOrder) ) { diff --git a/harbour/include/hbexprb.c b/harbour/include/hbexprb.c index 1021c33250..1fe1f4a49f 100644 --- a/harbour/include/hbexprb.c +++ b/harbour/include/hbexprb.c @@ -1085,7 +1085,11 @@ static HB_EXPR_FUNC( hb_compExprUseFunCall ) } else usCount = 0; - HB_EXPR_PCODE3( hb_compGenPCode3, HB_P_FUNCTION, HB_LOBYTE( usCount ), HB_HIBYTE( usCount ) ); + + if( usCount > 255 ) + HB_EXPR_PCODE3( hb_compGenPCode3, HB_P_FUNCTION, HB_LOBYTE( usCount ), HB_HIBYTE( usCount ) ); + else + HB_EXPR_PCODE2( hb_compGenPCode2, HB_P_FUNCTIONSHORT, ( BYTE ) usCount ); } break; @@ -1110,7 +1114,11 @@ static HB_EXPR_FUNC( hb_compExprUseFunCall ) } else usCount = 0; - HB_EXPR_PCODE3( hb_compGenPCode3, HB_P_DO, HB_LOBYTE( usCount ), HB_HIBYTE( usCount ) ); + + if( usCount > 255 ) + HB_EXPR_PCODE3( hb_compGenPCode3, HB_P_DO, HB_LOBYTE( usCount ), HB_HIBYTE( usCount ) ); + else + HB_EXPR_PCODE2( hb_compGenPCode2, HB_P_DOSHORT, ( BYTE ) usCount ); } break; @@ -1516,14 +1524,18 @@ static HB_EXPR_FUNC( hb_compExprUseSend ) --iParms; if( iParms ) HB_EXPR_USE( pSelf->value.asMessage.pParms, HB_EA_PUSH_PCODE ); - HB_EXPR_PCODE3( hb_compGenPCode3, HB_P_FUNCTION, HB_LOBYTE( iParms ), HB_HIBYTE( iParms ) ); + + if( iParms > 255 ) + HB_EXPR_PCODE3( hb_compGenPCode3, HB_P_FUNCTION, HB_LOBYTE( iParms ), HB_HIBYTE( iParms ) ); + else + HB_EXPR_PCODE2( hb_compGenPCode2, HB_P_FUNCTIONSHORT, ( BYTE ) iParms ); } else { /* acces to instance variable */ HB_EXPR_USE( pSelf->value.asMessage.pObject, HB_EA_PUSH_PCODE ); HB_EXPR_PCODE1( hb_compGenMessage, pSelf->value.asMessage.szMessage ); - HB_EXPR_PCODE3( hb_compGenPCode3, HB_P_FUNCTION, 0, 0 ); + HB_EXPR_PCODE2( hb_compGenPCode2, HB_P_FUNCTIONSHORT, 0 ); } } break; @@ -1536,7 +1548,7 @@ static HB_EXPR_FUNC( hb_compExprUseSend ) HB_EXPR_USE( pSelf->value.asMessage.pObject, HB_EA_PUSH_PCODE ); HB_EXPR_PCODE1( hb_compGenMessageData, pSelf->value.asMessage.szMessage ); HB_EXPR_USE( pSelf->value.asMessage.pParms, HB_EA_PUSH_PCODE ); - HB_EXPR_PCODE3( hb_compGenPCode3, HB_P_FUNCTION, 1, 0 ); + HB_EXPR_PCODE2( hb_compGenPCode2, HB_P_FUNCTIONSHORT, 1 ); } break; diff --git a/harbour/include/hbexprc.c b/harbour/include/hbexprc.c index 7075364720..f14b1bc1de 100644 --- a/harbour/include/hbexprc.c +++ b/harbour/include/hbexprc.c @@ -95,7 +95,7 @@ void hb_compExprPushOperEq( HB_EXPR_PTR pSelf, BYTE bOpEq ) #endif /* now send the message */ HB_EXPR_PCODE1( hb_compGenMessage, pObj->value.asMessage.szMessage ); - HB_EXPR_PCODE3( hb_compGenPCode3, HB_P_FUNCTION, 0, 0 ); + HB_EXPR_PCODE2( hb_compGenPCode2, HB_P_FUNCTIONSHORT, 0 ); /* NOTE: COMPATIBILITY ISSUE: * The above HB_C52_STRICT setting determines @@ -128,7 +128,7 @@ void hb_compExprPushOperEq( HB_EXPR_PTR pSelf, BYTE bOpEq ) HB_EXPR_PCODE1( hb_compGenPCode1, bOpEq ); /* call pop message with one argument */ - HB_EXPR_PCODE3( hb_compGenPCode3, HB_P_FUNCTION, 1, 0 ); + HB_EXPR_PCODE2( hb_compGenPCode2, HB_P_FUNCTIONSHORT, 1 ); } /* TODO: add a special code for arrays to correctly handle a[ i++ ]++ */ @@ -176,7 +176,7 @@ void hb_compExprUseOperEq( HB_EXPR_PTR pSelf, BYTE bOpEq ) #endif /* now send the message */ HB_EXPR_PCODE1( hb_compGenMessage, pObj->value.asMessage.szMessage ); - HB_EXPR_PCODE3( hb_compGenPCode3, HB_P_FUNCTION, 0, 0 ); + HB_EXPR_PCODE2( hb_compGenPCode2, HB_P_FUNCTIONSHORT, 0 ); /* push increment value */ HB_EXPR_USE( pSelf->value.asOperator.pRight, HB_EA_PUSH_PCODE ); @@ -184,7 +184,7 @@ void hb_compExprUseOperEq( HB_EXPR_PTR pSelf, BYTE bOpEq ) HB_EXPR_PCODE1( hb_compGenPCode1, bOpEq ); /* call pop message with one argument */ - HB_EXPR_PCODE3( hb_compGenPCode3, HB_P_FUNCTION, 1, 0 ); + HB_EXPR_PCODE2( hb_compGenPCode2, HB_P_FUNCTIONSHORT, 1 ); /* pop the value from the stack */ HB_EXPR_PCODE1( hb_compGenPCode1, HB_P_POP ); } @@ -230,13 +230,13 @@ void hb_compExprPushPreOp( HB_EXPR_PTR pSelf, BYTE bOper ) #endif /* now send the message */ HB_EXPR_PCODE1( hb_compGenMessage, pObj->value.asMessage.szMessage ); - HB_EXPR_PCODE3( hb_compGenPCode3, HB_P_FUNCTION, 0, 0 ); + HB_EXPR_PCODE2( hb_compGenPCode2, HB_P_FUNCTIONSHORT, 0 ); /* increase/decrease operation */ HB_EXPR_PCODE1( hb_compGenPCode1, bOper ); /* call pop message with one argument - it leaves the value on the stack */ - HB_EXPR_PCODE3( hb_compGenPCode3, HB_P_FUNCTION, 1, 0 ); + HB_EXPR_PCODE2( hb_compGenPCode2, HB_P_FUNCTIONSHORT, 1 ); } else { diff --git a/harbour/include/hbmacro.h b/harbour/include/hbmacro.h index 9f3c8c6f23..0631c982a5 100644 --- a/harbour/include/hbmacro.h +++ b/harbour/include/hbmacro.h @@ -87,6 +87,7 @@ extern void hb_macroError( int, HB_MACRO_DECL ); extern int hb_compParse( HB_MACRO_PTR ); extern void hb_compGenPCode1( BYTE, HB_MACRO_DECL ); +extern void hb_compGenPCode2( BYTE, BYTE, HB_MACRO_DECL ); extern void hb_compGenPCode3( BYTE, BYTE, BYTE, HB_MACRO_DECL ); extern void hb_compGenPCodeN( BYTE * pBuffer, ULONG ulSize, HB_MACRO_DECL ); @@ -130,6 +131,7 @@ extern void hb_compGenPushDouble( double dNumber, BYTE bDec, HB_MACRO_DECL ); extern void hb_compGenPushFunCall( char * szFunName, HB_MACRO_DECL ); extern void hb_compGenPushString( char * szText, ULONG ulStrLen, HB_MACRO_DECL ); extern void hb_compGenPCode1( BYTE byte, HB_MACRO_DECL ); +extern void hb_compGenPCode2( BYTE byte1, BYTE byte2, HB_MACRO_DECL ); extern void hb_compGenPCode3( BYTE byte1, BYTE byte2, BYTE byte3, HB_MACRO_DECL ); extern void hb_compGenPCodeN( BYTE * pBuffer, ULONG ulSize, HB_MACRO_DECL ); extern void hb_compCodeBlockStart( HB_MACRO_DECL ); diff --git a/harbour/source/compiler/genc.c b/harbour/source/compiler/genc.c index 6a1d21ce2a..16226d6968 100644 --- a/harbour/source/compiler/genc.c +++ b/harbour/source/compiler/genc.c @@ -280,7 +280,7 @@ static void hb_compGenCReadable( PFUNCTION pFunc, FILE * yyc ) break; case HB_P_DOSHORT: - fprintf( yyc, "\tHB_P_DO, %i,\n", pFunc->pCode[ lPCodePos + 1 ] ); + fprintf( yyc, "\tHB_P_DOSHORT, %i,\n", pFunc->pCode[ lPCodePos + 1 ] ); lPCodePos += 2; break; @@ -1158,7 +1158,7 @@ static void hb_compGenCReadable( PFUNCTION pFunc, FILE * yyc ) break; case HB_P_PUSHSYMNEAR: - fprintf( yyc, "\tHB_P_PUSHSYMNEAR, %i, %i,", + fprintf( yyc, "\tHB_P_PUSHSYMNEAR, %i,", pFunc->pCode[ lPCodePos + 1 ] ); if( bVerbose ) fprintf( yyc, "\t/* %s */", hb_compSymbolGetPos( pFunc->pCode[ lPCodePos + 1 ] )->szName ); fprintf( yyc, "\n" ); diff --git a/harbour/source/compiler/harbour.c b/harbour/source/compiler/harbour.c index f0ae9f0e1b..589aa0a51b 100644 --- a/harbour/source/compiler/harbour.c +++ b/harbour/source/compiler/harbour.c @@ -2237,11 +2237,11 @@ void hb_compGenPushInteger( int iNumber ) { if( lNumber == 0 ) hb_compGenPCode1( HB_P_ZERO ); - else if ( lNumber == 1 ) + else if( lNumber == 1 ) hb_compGenPCode1( HB_P_ONE ); - else if ( ( ( char * ) &lNumber )[ 2 ] == 0 && ( ( char * ) &lNumber )[ 3 ] == 0 ) + else if( ( ( char * ) &lNumber )[ 2 ] == 0 && ( ( char * ) &lNumber )[ 3 ] == 0 ) { - if ( ( ( char * ) &lNumber )[ 1 ] == 0 ) + if( ( ( char * ) &lNumber )[ 1 ] == 0 ) hb_compGenPCode2( HB_P_PUSHBYTE, ( ( char * ) &lNumber )[ 0 ] ); else hb_compGenPCode3( HB_P_PUSHINT, ( ( char * ) &lNumber )[ 0 ], ( ( char * ) &lNumber )[ 1 ] ); @@ -2260,11 +2260,11 @@ void hb_compGenPushLong( long lNumber ) { if( lNumber == 0 ) hb_compGenPCode1( HB_P_ZERO ); - else if ( lNumber == 1 ) + else if( lNumber == 1 ) hb_compGenPCode1( HB_P_ONE ); - else if ( ( ( char * ) &lNumber )[ 2 ] == 0 && ( ( char * ) &lNumber )[ 3 ] == 0 ) + else if( ( ( char * ) &lNumber )[ 2 ] == 0 && ( ( char * ) &lNumber )[ 3 ] == 0 ) { - if ( ( ( char * ) &lNumber )[ 1 ] == 0 ) + if( ( ( char * ) &lNumber )[ 1 ] == 0 ) hb_compGenPCode2( HB_P_PUSHBYTE, ( ( char * ) &lNumber )[ 0 ] ); else hb_compGenPCode3( HB_P_PUSHINT, ( ( char * ) &lNumber )[ 0 ], ( ( char * ) &lNumber )[ 1 ] ); @@ -2399,7 +2399,7 @@ void hb_compOptimizeFrames() bLocals++; } - if ( bLocals || pFunc->wParamCount ) + if( bLocals || pFunc->wParamCount ) { pFunc->pCode[ 1 ] = ( BYTE )( bLocals - pFunc->wParamCount ); pFunc->pCode[ 2 ] = ( BYTE )( pFunc->wParamCount ); @@ -2423,22 +2423,22 @@ void hb_compOptimizeFrames() pOptimized = ( BYTE * ) hb_xgrab( pFunc->lPCodePos - 6 ); ulNextByte = 6; - while ( ulNextByte < pFunc->lPCodePos ) + while( ulNextByte < pFunc->lPCodePos ) pOptimized[ ulOptimized++ ] = pFunc->pCode[ ulNextByte++ ]; pFunc->lPCodePos -= 6; } - else if ( bSkipFRAME ) + else if( bSkipFRAME ) { pOptimized = ( BYTE * ) hb_xgrab( hb_comp_functions.pLast->lPCodePos - 3 ); ulNextByte = 3; - while ( ulNextByte < pFunc->lPCodePos ) - pOptimized[ ulOptimized++ ] = pFunc->pCode[ ulNextByte++ ]; + while( ulNextByte < pFunc->lPCodePos ) + pOptimized[ ulOptimized++ ] = pFunc->pCode[ ulNextByte++ ]; pFunc->lPCodePos -= 3; } - else if ( bSkipSFRAME ) + else if( bSkipSFRAME ) { pOptimized = ( BYTE * ) hb_xgrab( hb_comp_functions.pLast->lPCodePos - 3 ); @@ -2454,6 +2454,8 @@ void hb_compOptimizeFrames() pFunc->lPCodePos -= 3; } + else + pOptimized = NULL; /* To avoid GCC -O2 warning */ hb_xfree( ( void * ) pFunc->pCode ); pFunc->pCode = pOptimized; @@ -2680,7 +2682,7 @@ void hb_compOptimizeJumps( void ) { ulBytes2Copy = ( pNOOPs[ iNOOP ] - ulNextByte ) ; - while ( ulBytes2Copy-- > 0 ) + while( ulBytes2Copy-- > 0 ) pOptimized[ ulOptimized++ ] = pCode[ ulNextByte++ ]; /* Skip the NOOP and point to next valid byte */ @@ -2691,8 +2693,8 @@ void hb_compOptimizeJumps( void ) //getchar(); /* Copy remainder beyond the last NOOP. */ - while ( ulNextByte < hb_comp_functions.pLast->lPCodePos ) - pOptimized[ ulOptimized++ ] = pCode[ ulNextByte++ ]; + while( ulNextByte < hb_comp_functions.pLast->lPCodePos ) + pOptimized[ ulOptimized++ ] = pCode[ ulNextByte++ ]; //printf( "\rCopied" ); //getchar(); diff --git a/harbour/source/compiler/harbour.y b/harbour/source/compiler/harbour.y index a1c4768873..0c018ba460 100644 --- a/harbour/source/compiler/harbour.y +++ b/harbour/source/compiler/harbour.y @@ -305,10 +305,10 @@ Statement : ExecFlow CrlfStmnt { } | ExprEqual CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); } | ExprAssign CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); } | DoProc CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); } - | BREAK CrlfStmnt { hb_compGenBreak(); hb_compGenPCode3( HB_P_DO, 0, 0 ); + | BREAK CrlfStmnt { hb_compGenBreak(); hb_compGenPCode2( HB_P_DOSHORT, 0 ); hb_comp_functions.pLast->bFlags |= FUN_BREAK_CODE; } | BREAK { hb_compLinePushIfInside(); } Expression Crlf { hb_compGenBreak(); hb_compExprDelete( hb_compExprGenPush( $3 ) ); - hb_compGenPCode3( HB_P_DO, 1, 0 ); + hb_compGenPCode2( HB_P_DOSHORT, 1 ); hb_comp_functions.pLast->bFlags |= FUN_BREAK_CODE; } | RETURN CrlfStmnt { @@ -1827,7 +1827,10 @@ static void hb_compRTVariableGen( char * szCreateFun ) ++usCount; /* call function that will create either PUBLIC or PRIVATE variables */ - hb_compGenPCode3( HB_P_DO, HB_LOBYTE( usCount ), HB_HIBYTE( usCount ) ); + if( usCount > 255 ) + hb_compGenPCode3( HB_P_DO, HB_LOBYTE( usCount ), HB_HIBYTE( usCount ) ); + else + hb_compGenPCode2( HB_P_DOSHORT, ( BYTE ) usCount ); /* pop initial values */ while( pVar ) diff --git a/harbour/source/rtl/gtpca/gtpca.c b/harbour/source/rtl/gtpca/gtpca.c index 18ae712896..9a18fab3b8 100644 --- a/harbour/source/rtl/gtpca/gtpca.c +++ b/harbour/source/rtl/gtpca/gtpca.c @@ -357,7 +357,7 @@ void hb_gt_GetText( USHORT usTop, USHORT usLeft, USHORT usBottom, USHORT usRight void hb_gt_PutText( USHORT usTop, USHORT usLeft, USHORT usBottom, USHORT usRight, BYTE *src ) { - HB_TRACE(HB_TR_DEBUG, ("hb_gt_PutText(%hu, %hu, %hu, %hu, %p)", usTop, usLeft, usBottom, usRight, srce) ); + HB_TRACE(HB_TR_DEBUG, ("hb_gt_PutText(%hu, %hu, %hu, %hu, %p)", usTop, usLeft, usBottom, usRight, src) ); HB_SYMBOL_UNUSED( usTop ); HB_SYMBOL_UNUSED( usLeft ); HB_SYMBOL_UNUSED( usBottom ); diff --git a/harbour/source/vm/hvm.c b/harbour/source/vm/hvm.c index 545b0460d5..ea9ba59b3d 100644 --- a/harbour/source/vm/hvm.c +++ b/harbour/source/vm/hvm.c @@ -541,11 +541,22 @@ void hb_vmExecute( const BYTE * pCode, PHB_SYMB pSymbols ) w += 3; break; + case HB_P_DOSHORT: + hb_inkeyPoll(); /* Poll the console keyboard */ + hb_vmDo( pCode[ w + 1 ] ); + w += 2; + break; + case HB_P_FUNCTION: hb_vmFunction( pCode[ w + 1 ] + ( pCode[ w + 2 ] * 256 ) ); w += 3; break; + case HB_P_FUNCTIONSHORT: + hb_vmFunction( pCode[ w + 1 ] ); + w += 2; + break; + case HB_P_LINE: HB_TRACE(HB_TR_INFO, ("Opcode: HB_P_LINE: %s (%i)", hb_stack.pBase->item.asSymbol.value->szName, hb_stack.pBase->item.asSymbol.lineno)); @@ -907,10 +918,15 @@ void hb_vmExecute( const BYTE * pCode, PHB_SYMB pSymbols ) { USHORT uiSize = pCode[ w + 1 ] + ( pCode[ w + 2 ] * 256 ); hb_vmPushString( ( char * ) pCode + w + 3, ( ULONG ) uiSize ); - w += ( uiSize + 3 ); + w += ( 3 + uiSize ); } break; + case HB_P_PUSHSTRSHORT: + hb_vmPushString( ( char * ) pCode + w + 2, ( ULONG ) pCode[ w + 1 ] ); + w += ( 2 + pCode[ w + 1 ] ); + break; + case HB_P_PUSHBLOCK: /* +0 -> _pushblock * +1 +2 -> size of codeblock @@ -932,6 +948,11 @@ void hb_vmExecute( const BYTE * pCode, PHB_SYMB pSymbols ) w += 3; break; + case HB_P_PUSHSYMNEAR: + hb_vmPushSymbol( pSymbols + ( USHORT ) pCode[ w + 1 ] ); + w += 2; + break; + case HB_P_PUSHALIAS: hb_vmPushAlias(); w++; diff --git a/harbour/source/vm/macro.c b/harbour/source/vm/macro.c index bb48d62138..78550ad770 100644 --- a/harbour/source/vm/macro.c +++ b/harbour/source/vm/macro.c @@ -1137,6 +1137,17 @@ void hb_compGenPCode1( BYTE byte, HB_MACRO_DECL ) pFunc->pCode[ pFunc->lPCodePos++ ] = byte; } +void hb_compGenPCode2( BYTE byte1, BYTE byte2, HB_MACRO_DECL ) +{ + HB_PCODE_INFO_PTR pFunc = HB_PCODE_DATA; + + if( ( pFunc->lPCodeSize - pFunc->lPCodePos ) < 2 ) + pFunc->pCode = ( BYTE * ) hb_xrealloc( pFunc->pCode, pFunc->lPCodeSize += HB_PCODE_SIZE ); + + pFunc->pCode[ pFunc->lPCodePos++ ] = byte1; + pFunc->pCode[ pFunc->lPCodePos++ ] = byte2; +} + void hb_compGenPCode3( BYTE byte1, BYTE byte2, BYTE byte3, HB_MACRO_DECL ) { HB_PCODE_INFO_PTR pFunc = HB_PCODE_DATA;