From e92af8dbd2eed32d20c7fd9876683b24fb95b354 Mon Sep 17 00:00:00 2001 From: Ryszard Glab Date: Tue, 14 Feb 2006 15:12:07 +0000 Subject: [PATCH] 2006-02-14 16:10 UTC+0100 Ryszard Glab * include/hbapiitm.h * include/hbexpra.c * include/hbexprc.c * include/hbexprop.h * source/compiler/expropta.c * source/compiler/exproptb.c * source/compiler/exproptc.c * source/macro/macroa.c * source/macro/macrob.c * source/macro/macroc.c * source/vm/hvm.c * source/vm/itemapi.c * fixed code for adding date and numeric values (introduced in my last commits) * removed hb_itemPutBHLong (use hb_itemPutNInt instead) * added more optimization for localvar+=integer using HB_P_LOCALNEARADDINT pcode (borrowed from xHarbour) --- harbour/ChangeLog | 20 ++++++++++++ harbour/include/hbapiitm.h | 1 - harbour/include/hbexpra.c | 2 +- harbour/include/hbexprc.c | 50 +++++++++++++++++++++++++++--- harbour/include/hbexprop.h | 5 +-- harbour/source/compiler/expropta.c | 2 +- harbour/source/compiler/exproptb.c | 2 +- harbour/source/compiler/exproptc.c | 2 +- harbour/source/macro/macroa.c | 2 +- harbour/source/macro/macrob.c | 2 +- harbour/source/macro/macroc.c | 2 +- harbour/source/vm/hvm.c | 4 +-- harbour/source/vm/itemapi.c | 29 +---------------- 13 files changed, 79 insertions(+), 44 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 0bdbe00e44..b223b99bbc 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,26 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ * fixed <-x-> match marker +2006-02-14 16:10 UTC+0100 Ryszard Glab + * include/hbapiitm.h + * include/hbexpra.c + * include/hbexprc.c + * include/hbexprop.h + * source/compiler/expropta.c + * source/compiler/exproptb.c + * source/compiler/exproptc.c + * source/macro/macroa.c + * source/macro/macrob.c + * source/macro/macroc.c + * source/vm/hvm.c + * source/vm/itemapi.c + * fixed code for adding date and numeric values (introduced + in my last commits) + * removed hb_itemPutBHLong (use hb_itemPutNInt instead) + * added more optimization for localvar+=integer + using HB_P_LOCALNEARADDINT pcode + (borrowed from xHarbour) + 2006-02-14 14:40 UTC+0100 Ryszard Glab * include/hbexprc.c * source/compiler/exproptc.c diff --git a/harbour/include/hbapiitm.h b/harbour/include/hbapiitm.h index 48860c9e61..f20e646995 100644 --- a/harbour/include/hbapiitm.h +++ b/harbour/include/hbapiitm.h @@ -104,7 +104,6 @@ extern HB_EXPORT void hb_itemSetCMemo ( PHB_ITEM pItem ); extern HB_EXPORT PHB_ITEM hb_itemPutD ( PHB_ITEM pItem, int iYear, int iMonth, int iDay ); extern HB_EXPORT PHB_ITEM hb_itemPutDS ( PHB_ITEM pItem, const char * szDate ); extern HB_EXPORT PHB_ITEM hb_itemPutDL ( PHB_ITEM pItem, long lJulian ); -extern HB_EXPORT PHB_ITEM hb_itemPutHBLong( PHB_ITEM pItem, HB_LONG lNumber ); extern HB_EXPORT PHB_ITEM hb_itemPutL ( PHB_ITEM pItem, BOOL bValue ); extern HB_EXPORT PHB_ITEM hb_itemPutND ( PHB_ITEM pItem, double dNumber ); extern HB_EXPORT PHB_ITEM hb_itemPutNI ( PHB_ITEM pItem, int iNumber ); diff --git a/harbour/include/hbexpra.c b/harbour/include/hbexpra.c index 791e4f1e1c..63b5185c9a 100644 --- a/harbour/include/hbexpra.c +++ b/harbour/include/hbexpra.c @@ -134,7 +134,7 @@ static HB_CBVAR_PTR hb_compExprCBVarNew( char *, BYTE ); /* ************************************************************************ */ -HB_EXPR_PTR hb_compExprNew( int iType ) +HB_EXPR_PTR hb_compExprNew( HB_EXPRTYPE iType ) { HB_EXPR_PTR pExpr; diff --git a/harbour/include/hbexprc.c b/harbour/include/hbexprc.c index f351e21930..e51e245bb8 100644 --- a/harbour/include/hbexprc.c +++ b/harbour/include/hbexprc.c @@ -158,9 +158,31 @@ void hb_compExprPushOperEq( HB_EXPR_PTR pSelf, BYTE bOpEq ) if( ! ( iScope == HB_VS_LOCAL_FIELD || iScope == HB_VS_GLOBAL_FIELD ) ) { - if( pSelf->value.asOperator.pRight->ExprType == HB_ET_NUMERIC || - pSelf->value.asOperator.pRight->ExprType == HB_ET_STRING ) + HB_EXPRTYPE iType = pSelf->value.asOperator.pRight->ExprType; + + if( iType == HB_ET_NUMERIC || iType == HB_ET_STRING ) { + if( iScope == HB_VS_LOCAL_VAR && iType == HB_ET_NUMERIC && + ( bOpEq == HB_P_PLUS || bOpEq == HB_P_MINUS ) ) + { + int iLocal = hb_compLocalGetPos( pSelf->value.asOperator.pLeft->value.asSymbol ); + + if( iLocal < 256 && hb_compExprIsInteger( pSelf->value.asOperator.pRight ) ) + { + int iIncrement = ( short ) pSelf->value.asOperator.pRight->value.asNum.lVal; + + if( bOpEq == HB_P_MINUS ) + { + iIncrement = -iIncrement; + } + + hb_compGenPCode4( HB_P_LOCALNEARADDINT, ( BYTE ) iLocal, HB_LOBYTE( iIncrement ), HB_HIBYTE( iIncrement ), ( BOOL ) 0 ); + + HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_PCODE ); + + return; + } + } /* NOTE: direct type change */ pSelf->value.asOperator.pLeft->ExprType = HB_ET_VARREF; @@ -279,9 +301,29 @@ void hb_compExprUseOperEq( HB_EXPR_PTR pSelf, BYTE bOpEq ) if( ! ( iScope == HB_VS_LOCAL_FIELD || iScope == HB_VS_GLOBAL_FIELD ) ) { - if( pSelf->value.asOperator.pRight->ExprType == HB_ET_NUMERIC || - pSelf->value.asOperator.pRight->ExprType == HB_ET_STRING ) + HB_EXPRTYPE iType = pSelf->value.asOperator.pRight->ExprType; + + if( iType == HB_ET_NUMERIC || iType == HB_ET_STRING ) { + if( iScope == HB_VS_LOCAL_VAR && iType == HB_ET_NUMERIC && + ( bOpEq == HB_P_PLUS || bOpEq == HB_P_MINUS ) ) + { + int iLocal = hb_compLocalGetPos( pSelf->value.asOperator.pLeft->value.asSymbol ); + + if( iLocal < 256 && hb_compExprIsInteger( pSelf->value.asOperator.pRight ) ) + { + short iIncrement = ( short ) pSelf->value.asOperator.pRight->value.asNum.lVal; + + if( bOpEq == HB_P_MINUS ) + { + iIncrement = -iIncrement; + } + + hb_compGenPCode4( HB_P_LOCALNEARADDINT, ( BYTE ) iLocal, HB_LOBYTE( iIncrement ), HB_HIBYTE( iIncrement ), ( BOOL ) 0 ); + + return; + } + } /* NOTE: direct type change */ pSelf->value.asOperator.pLeft->ExprType = HB_ET_VARREF; diff --git a/harbour/include/hbexprop.h b/harbour/include/hbexprop.h index 20e690ecd7..e1e7090df6 100644 --- a/harbour/include/hbexprop.h +++ b/harbour/include/hbexprop.h @@ -168,6 +168,7 @@ typedef enum HB_EO_PREDEC /* pre-operators -> the highest precedence */ } HB_EXPR_OPERATOR; +typedef USHORT HB_EXPRTYPE; typedef struct HB_EXPR_ { @@ -240,7 +241,7 @@ typedef struct HB_EXPR_ } value; ULONG ulLength; ULONG Counter; - unsigned char ExprType; /* internal expression type */ + HB_EXPRTYPE ExprType; /* internal expression type */ USHORT ValType; /* language level value type */ struct HB_EXPR_ *pNext; /* next expression in the list of expressions */ } HB_EXPR, *HB_EXPR_PTR; @@ -305,7 +306,7 @@ typedef HB_EXPR_PTR HB_EXPR_ACTION( HB_EXPR_PTR pSelf, int iMessage ); #endif -HB_EXPR_PTR hb_compExprNew( int ); +HB_EXPR_PTR hb_compExprNew( HB_EXPRTYPE ); HB_EXPR_PTR hb_compExprNewEmpty( void ); HB_EXPR_PTR hb_compExprNewNil( void ); HB_EXPR_PTR hb_compExprNewDouble( double, BYTE, BYTE ); diff --git a/harbour/source/compiler/expropta.c b/harbour/source/compiler/expropta.c index 0835d0d346..567a83d092 100644 --- a/harbour/source/compiler/expropta.c +++ b/harbour/source/compiler/expropta.c @@ -5,6 +5,6 @@ /* hbexpra.c is also included from ../macro/macro.c * However it produces a slighty different code if used in * macro compiler (there is an additional parameter passed to some functions) - * 1.18 - ignore this magic number - this is used to force compilation + * 1.19 - ignore this magic number - this is used to force compilation */ #include "hbexpra.c" diff --git a/harbour/source/compiler/exproptb.c b/harbour/source/compiler/exproptb.c index 2cc4b6a689..a90876e746 100644 --- a/harbour/source/compiler/exproptb.c +++ b/harbour/source/compiler/exproptb.c @@ -5,6 +5,6 @@ /* hbexprb.c is also included from ../macro/macro.c * However it produces a slighty different code if used in * macro compiler (there is an additional parameter passed to some functions) - * 1.16 - ignore this magic number - this is used to force compilation + * 1.17 - ignore this magic number - this is used to force compilation */ #include "hbexprb.c" diff --git a/harbour/source/compiler/exproptc.c b/harbour/source/compiler/exproptc.c index c66be5521c..82bfb3eaa7 100644 --- a/harbour/source/compiler/exproptc.c +++ b/harbour/source/compiler/exproptc.c @@ -5,6 +5,6 @@ /* hbexprc.c is also included from ../macro/macro.c * However it produces a slighty different code if used in * macro compiler (there is an additional parameter passed to some functions) - * 1.8 - ignore this magic number - this is used to force compilation + * 1.9 - ignore this magic number - this is used to force compilation */ #include "hbexprc.c" diff --git a/harbour/source/macro/macroa.c b/harbour/source/macro/macroa.c index 3fb658e9fe..c3bb635839 100644 --- a/harbour/source/macro/macroa.c +++ b/harbour/source/macro/macroa.c @@ -5,7 +5,7 @@ /* hbexpra.c is also included from ../compiler/expropta.c * However it produces a slighty different code if used in * macro compiler (there is an additional parameter passed to some functions) - * 1.18 - ignore this magic number - this is used to force compilation + * 1.19 - ignore this magic number - this is used to force compilation */ #define HB_MACRO_SUPPORT diff --git a/harbour/source/macro/macrob.c b/harbour/source/macro/macrob.c index 49e250028c..8c4257b195 100644 --- a/harbour/source/macro/macrob.c +++ b/harbour/source/macro/macrob.c @@ -5,7 +5,7 @@ /* hbexprb.c is also included from ../compiler/exproptb.c * However it produces a slighty different code if used in * macro compiler (there is an additional parameter passed to some functions) - * 1.15 - ignore this magic number - this is used to force compilation + * 1.16 - ignore this magic number - this is used to force compilation */ #define HB_MACRO_SUPPORT diff --git a/harbour/source/macro/macroc.c b/harbour/source/macro/macroc.c index 5edc386110..02d07efc35 100644 --- a/harbour/source/macro/macroc.c +++ b/harbour/source/macro/macroc.c @@ -5,7 +5,7 @@ /* hbexprc.c is also included from ../compiler/exproptc.c * However it produces a slighty different code if used in * macro compiler (there is an additional parameter passed to some functions) - * 1.7 - ignore this magic number - this is used to force compilation + * 1.8 - ignore this magic number - this is used to force compilation */ #define HB_MACRO_SUPPORT diff --git a/harbour/source/vm/hvm.c b/harbour/source/vm/hvm.c index 51aa196a9c..df13591391 100644 --- a/harbour/source/vm/hvm.c +++ b/harbour/source/vm/hvm.c @@ -2159,7 +2159,7 @@ static void hb_vmPlus( HB_ITEM_PTR pResult, HB_ITEM_PTR pItem1, HB_ITEM_PTR pIte } else if( HB_IS_DATE( pItem1 ) && HB_IS_NUMERIC( pItem2 ) ) { - hb_itemPutND( pResult, ( long ) hb_itemGetND( pItem1 ) + ( long ) hb_itemGetND( pItem1 ) ); + hb_itemPutDL( pResult, ( long ) hb_itemGetND( pItem1 ) + ( long ) hb_itemGetND( pItem1 ) ); while( iPopCnt-- > 0 ) { hb_stackDec(); @@ -2235,7 +2235,7 @@ static void hb_vmMinus( HB_ITEM_PTR pResult, HB_ITEM_PTR pItem1, HB_ITEM_PTR pIt } else if( HB_IS_DATE( pItem1 ) && HB_IS_NUMERIC( pItem2 ) ) { - hb_itemPutND( pResult, ( long ) hb_itemGetND( pItem1 ) - ( long ) hb_itemGetND( pItem1 ) ); + hb_itemPutNL( pResult, ( long ) hb_itemGetND( pItem1 ) - ( long ) hb_itemGetND( pItem1 ) ); while( iPopCnt-- > 0 ) { hb_stackDec(); diff --git a/harbour/source/vm/itemapi.c b/harbour/source/vm/itemapi.c index 3e9f36edaa..400efd4c6d 100644 --- a/harbour/source/vm/itemapi.c +++ b/harbour/source/vm/itemapi.c @@ -1049,29 +1049,6 @@ HB_EXPORT PHB_ITEM hb_itemPutNLLLen( PHB_ITEM pItem, LONGLONG llNumber, int iWid } #endif -HB_EXPORT PHB_ITEM hb_itemPutHBLong( PHB_ITEM pItem, HB_LONG lNumber ) -{ - HB_TRACE(HB_TR_DEBUG, ("hb_itemPutHBLong( %p, %" PFHL "d)", pItem, lNumber)); - - if( pItem ) - { - if( HB_IS_COMPLEX( pItem ) ) - { - hb_itemClear( pItem ); - } - } - else - { - pItem = hb_itemNew( NULL ); - } - - pItem->type = HB_IT_LONG; - pItem->item.asLong.value = lNumber; - pItem->item.asLong.length = HB_LONG_LENGTH( lNumber ); - - return pItem; -} - HB_EXPORT PHB_ITEM hb_itemPutNumType( PHB_ITEM pItem, double dNumber, int iDec, int iType1, int iType2 ) { HB_TRACE(HB_TR_DEBUG, ("hb_itemPutNumType( %p, %lf, %d, %i, %i)", pItem, dNumber, iDec, iType1, iType2)); @@ -1082,11 +1059,7 @@ HB_EXPORT PHB_ITEM hb_itemPutNumType( PHB_ITEM pItem, double dNumber, int iDec, } else if ( HB_DBL_LIM_INT( dNumber ) ) { - return hb_itemPutNI( pItem, ( int ) dNumber ); - } - else if ( HB_DBL_LIM_LONG( dNumber ) ) - { - return hb_itemPutHBLong( pItem, ( HB_LONG ) dNumber ); + return hb_itemPutNInt( pItem, ( HB_LONG ) dNumber ); } else {