From 234074140c20d818e8df958d7a3b6021b003cdf2 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 2 May 2000 00:12:34 +0000 Subject: [PATCH] 20000502-02:13 GMT+1 Victor Szakats --- harbour/ChangeLog | 13 ++++++++++++ harbour/source/compiler/harbour.l | 9 ++++++--- harbour/source/macro/macro.l | 6 ++++-- harbour/source/vm/hvm.c | 33 ++++++++++++++++++++----------- 4 files changed, 45 insertions(+), 16 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index adb7dd9bb0..f06676b6dd 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,16 @@ +20000502-02:13 GMT+1 Victor Szakats + + * source/compiler/harbour.l + * source/macro/macro.l + + The widths of the double values are calculated at compile time. + The widths of the doubles generated in the expression + optimizer are still forced to be calculated at runtime. + Please test this! + + * source/vm/hvm.c + % Width calculation moved to a separate function to lower the required + stack space. + 20000502-01:43 GMT+1 Victor Szakats * include/hbapi.h diff --git a/harbour/source/compiler/harbour.l b/harbour/source/compiler/harbour.l index 863c2db29b..95992c531e 100644 --- a/harbour/source/compiler/harbour.l +++ b/harbour/source/compiler/harbour.l @@ -1353,7 +1353,7 @@ Separator {SpaceTab} {Number} { return yy_ConvertNumber( yytext ); } {HexNumber} { - long lNumber = 0; + long lNumber = 0; sscanf( yytext, "%lxI", &lNumber ); @@ -1373,6 +1373,7 @@ Separator {SpaceTab} } else { + /* NOTE: This will never happen */ yylval.valDouble.dNumber = lNumber; yylval.valDouble.bWidth = HB_DEFAULT_WIDTH; yylval.valDouble.bDec = 0; @@ -1560,8 +1561,10 @@ static int yy_ConvertNumber( char * szBuffer ) ptr = strchr( szBuffer, '.' ); if( ptr ) { - yylval.valDouble.bWidth = HB_DEFAULT_WIDTH; yylval.valDouble.bDec = strlen( ptr + 1 ); + yylval.valDouble.bWidth = strlen( szBuffer ) - yylval.valDouble.bDec; + if( yylval.valDouble.bDec ) + yylval.valDouble.bWidth--; yylval.valDouble.szValue = szBuffer; return NUM_DOUBLE; } @@ -1583,7 +1586,7 @@ static int yy_ConvertNumber( char * szBuffer ) } else { - yylval.valDouble.bWidth = HB_DEFAULT_WIDTH; + yylval.valDouble.bWidth = strlen( szBuffer ) + 1; yylval.valDouble.bDec = 0; yylval.valDouble.szValue = szBuffer; return NUM_DOUBLE; diff --git a/harbour/source/macro/macro.l b/harbour/source/macro/macro.l index 09425c37e7..2180f4d9cf 100644 --- a/harbour/source/macro/macro.l +++ b/harbour/source/macro/macro.l @@ -305,8 +305,10 @@ Separator {SpaceTab} ptr = strchr( yytext, '.' ); if( ptr ) { - yylval_ptr->valDouble.bWidth = HB_DEFAULT_WIDTH; yylval_ptr->valDouble.bDec = strlen( ptr + 1 ); + yylval_ptr->valDouble.bWidth = strlen( yytext ) - yylval_ptr->valDouble.bDec; + if( yylval_ptr->valDouble.bDec ) + yylval_ptr->valDouble.bWidth--; yylval_ptr->valDouble.szValue = yytext ; return NUM_DOUBLE; } @@ -321,7 +323,7 @@ Separator {SpaceTab} } else { - yylval_ptr->valDouble.bWidth = HB_DEFAULT_WIDTH; + yylval_ptr->valDouble.bWidth = strlen( yytext ) + 1; yylval_ptr->valDouble.bDec = 0; yylval_ptr->valDouble.szValue = yytext; return NUM_DOUBLE; diff --git a/harbour/source/vm/hvm.c b/harbour/source/vm/hvm.c index 5a3302efb5..d4dc9672e2 100644 --- a/harbour/source/vm/hvm.c +++ b/harbour/source/vm/hvm.c @@ -2832,7 +2832,7 @@ static HARBOUR hb_vmDoBlock( void ) HB_ITEM_PTR hb_vmEvalBlock( HB_ITEM_PTR pBlock ) { HB_TRACE(HB_TR_DEBUG, ("hb_vmEvalBlock(%p)", pBlock)); - + hb_vmPushSymbol( &hb_symEval ); hb_vmPush( pBlock ); hb_vmDo( 0 ); @@ -2861,7 +2861,7 @@ HB_ITEM_PTR hb_vmEvalBlockV( HB_ITEM_PTR pBlock, USHORT uiArgCount, ... ) for( i=1; i<= uiArgCount; i++ ) hb_vmPush( va_arg( va, PHB_ITEM ) ); va_end( va ); - + hb_vmDo( uiArgCount ); return &hb_stack.Return; @@ -3090,6 +3090,21 @@ void hb_vmPushDouble( double dNumber, int iDec ) hb_stackPush(); } +static int hb_vmCalcDoubleWidth( double dNumber, int iDec ) +{ + char buffer[ 360 ]; + int iLength; + + sprintf( buffer, "%.*f", 0, dNumber ); + + iLength = strlen( buffer ); + + if( iDec == 0 ) + iLength++; + + return iLength; +} + static void hb_vmPushDoubleConst( double dNumber, int iWidth, int iDec ) { HB_TRACE(HB_TR_DEBUG, ("hb_vmPushDoubleConst(%lf, %d, %d)", dNumber, iWidth, iDec)); @@ -3102,23 +3117,19 @@ static void hb_vmPushDoubleConst( double dNumber, int iWidth, int iDec ) else hb_stack.pPos->item.asDouble.decimal = iDec; + /* NOTE: Part of these width calculations could be moved to the compiler for + maximum speed. */ + if( dNumber >= 1000000000.0 ) { - /* NOTE: If the width info is not provided by the pcode stream, + /* NOTE: If the width info is not provided by the pcode stream, it will be determined at runtime with a relatively slow method. [vszakats] */ if( iWidth == HB_DEFAULT_WIDTH ) - { - char buffer[ 360 ]; - sprintf( buffer, "%.*f", 0, dNumber ); - hb_stack.pPos->item.asDouble.length = strlen( buffer ) + 1; - } + hb_stack.pPos->item.asDouble.length = hb_vmCalcDoubleWidth( dNumber, iDec ); else hb_stack.pPos->item.asDouble.length = iWidth; - - if( iDec ) - hb_stack.pPos->item.asDouble.length--; } else if( dNumber <= -1000000000.0 ) hb_stack.pPos->item.asDouble.length = 20;