20000502-02:13 GMT+1 Victor Szakats <info@szelvesz.hu>

This commit is contained in:
Viktor Szakats
2000-05-02 00:12:34 +00:00
parent be7f72c97d
commit 234074140c
4 changed files with 45 additions and 16 deletions

View File

@@ -1,3 +1,16 @@
20000502-02:13 GMT+1 Victor Szakats <info@szelvesz.hu>
* 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 <info@szelvesz.hu>
* include/hbapi.h

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;