From be7f72c97dfe9b2bc7ca6be986decca300513bd7 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 1 May 2000 23:41:19 +0000 Subject: [PATCH] 20000502-01:43 GMT+1 Victor Szakats --- harbour/ChangeLog | 16 ++++++++++++++++ harbour/include/hbapi.h | 1 + harbour/include/hbexprb.c | 2 +- harbour/include/hbexprop.h | 3 ++- harbour/source/common/expropt1.c | 5 +++-- harbour/source/common/expropt2.c | 25 +++++++++++++++++++++---- harbour/source/compiler/harbour.l | 11 +++++++---- harbour/source/compiler/harbour.y | 5 +++-- harbour/source/macro/macro.l | 3 +++ harbour/source/macro/macro.y | 3 ++- harbour/source/vm/hvm.c | 2 +- 11 files changed, 60 insertions(+), 16 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 74ba697bdb..adb7dd9bb0 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,19 @@ +20000502-01:43 GMT+1 Victor Szakats + + * include/hbapi.h + * include/hbexprb.c + * include/hbexprop.h + * source/common/expropt1.c + * source/common/expropt2.c + * source/compiler/harbour.l + * source/compiler/harbour.y + * source/macro/macro.l + * source/macro/macro.y + * source/vm/hvm.c + + The compiler enhanced to internally handle the double width info. + It's not set to default at a lower level. + Note that it still isn't calculated. + 20000502-01:14 GMT+1 Victor Szakats * include/hbcomp.h diff --git a/harbour/include/hbapi.h b/harbour/include/hbapi.h index 47e20ccb60..8e829a7396 100644 --- a/harbour/include/hbapi.h +++ b/harbour/include/hbapi.h @@ -126,6 +126,7 @@ struct hb_struDate * was not specified at compile time (the value is a result of optimization * performed by the compiler) */ +#define HB_DEFAULT_WIDTH 255 #define HB_DEFAULT_DECIMALS 255 struct hb_struDouble diff --git a/harbour/include/hbexprb.c b/harbour/include/hbexprb.c index d73a79d69b..4b46dc51dc 100644 --- a/harbour/include/hbexprb.c +++ b/harbour/include/hbexprb.c @@ -278,7 +278,7 @@ static HB_EXPR_FUNC( hb_compExprUseNumeric ) break; case HB_EA_PUSH_PCODE: if( pSelf->value.asNum.NumType == HB_ET_DOUBLE ) - HB_EXPR_PCODE3( hb_compGenPushDouble, pSelf->value.asNum.dVal, -1, pSelf->value.asNum.bDec ); + HB_EXPR_PCODE3( hb_compGenPushDouble, pSelf->value.asNum.dVal, pSelf->value.asNum.bWidth, pSelf->value.asNum.bDec ); else HB_EXPR_PCODE1( hb_compGenPushLong, pSelf->value.asNum.lVal ); break; diff --git a/harbour/include/hbexprop.h b/harbour/include/hbexprop.h index bb1604cb79..14df2f9252 100644 --- a/harbour/include/hbexprop.h +++ b/harbour/include/hbexprop.h @@ -162,6 +162,7 @@ typedef struct HB_EXPR_ { long lVal; /* long value */ double dVal; /* double value */ + unsigned char bWidth; /* unsigned char used intentionally */ unsigned char bDec; /* unsigned char used intentionally */ unsigned char NumType; /* used to distinguish LONG and DOUBLE */ } asNum; @@ -268,7 +269,7 @@ typedef HB_EXPR_PTR HB_EXPR_ACTION( HB_EXPR_PTR pSelf, int iMessage ); HB_EXPR_PTR hb_compExprNew( int ); HB_EXPR_PTR hb_compExprNewEmpty( void ); HB_EXPR_PTR hb_compExprNewNil( void ); -HB_EXPR_PTR hb_compExprNewDouble( double, BYTE ); +HB_EXPR_PTR hb_compExprNewDouble( double, BYTE, BYTE ); HB_EXPR_PTR hb_compExprNewLong( LONG ); HB_EXPR_PTR hb_compExprNewString( char * ); HB_EXPR_PTR hb_compExprNewLogical( int ); diff --git a/harbour/source/common/expropt1.c b/harbour/source/common/expropt1.c index e1f9e788a8..bfdb1da9d3 100644 --- a/harbour/source/common/expropt1.c +++ b/harbour/source/common/expropt1.c @@ -151,7 +151,7 @@ HB_EXPR_PTR hb_compExprNewEmpty( void ) return hb_compExprNew( HB_ET_NONE ); } -HB_EXPR_PTR hb_compExprNewDouble( double dValue, BYTE ucDec ) +HB_EXPR_PTR hb_compExprNewDouble( double dValue, BYTE ucWidth, BYTE ucDec ) { HB_EXPR_PTR pExpr; @@ -160,6 +160,7 @@ HB_EXPR_PTR hb_compExprNewDouble( double dValue, BYTE ucDec ) pExpr =hb_compExprNew( HB_ET_NUMERIC ); pExpr->value.asNum.dVal = dValue; + pExpr->value.asNum.bWidth = ucWidth; pExpr->value.asNum.bDec = ucDec; pExpr->value.asNum.NumType = HB_ET_DOUBLE; pExpr->ValType = HB_EV_NUMERIC; @@ -176,7 +177,7 @@ HB_EXPR_PTR hb_compExprNewLong( long lValue ) pExpr =hb_compExprNew( HB_ET_NUMERIC ); pExpr->value.asNum.lVal = lValue; - pExpr->value.asNum.bDec = 0; + pExpr->value.asNum.bDec = 0; pExpr->value.asNum.NumType = HB_ET_LONG; pExpr->ValType = HB_EV_NUMERIC; diff --git a/harbour/source/common/expropt2.c b/harbour/source/common/expropt2.c index 1c3eb615c8..e3ed8346a9 100644 --- a/harbour/source/common/expropt2.c +++ b/harbour/source/common/expropt2.c @@ -76,6 +76,7 @@ HB_EXPR_PTR hb_compExprReduceMod( HB_EXPR_PTR pSelf, HB_MACRO_DECL ) else { pSelf->value.asNum.dVal = dVal; + pSelf->value.asNum.bWidth = HB_DEFAULT_WIDTH; pSelf->value.asNum.bDec = 0; pSelf->value.asNum.NumType = HB_ET_DOUBLE; } @@ -125,6 +126,7 @@ HB_EXPR_PTR hb_compExprReduceDiv( HB_EXPR_PTR pSelf, HB_MACRO_DECL ) { /* Return non-integer results as double */ pSelf->value.asNum.dVal = dVal; + pSelf->value.asNum.bWidth = HB_DEFAULT_WIDTH; pSelf->value.asNum.bDec = HB_DEFAULT_DECIMALS; pSelf->value.asNum.NumType = HB_ET_DOUBLE; } @@ -137,8 +139,9 @@ HB_EXPR_PTR hb_compExprReduceDiv( HB_EXPR_PTR pSelf, HB_MACRO_DECL ) if( pRight->value.asNum.dVal != 0.0 ) { pSelf->value.asNum.dVal = pLeft->value.asNum.dVal / pRight->value.asNum.dVal; - pSelf->value.asNum.NumType = HB_ET_DOUBLE; + pSelf->value.asNum.bWidth = HB_DEFAULT_WIDTH; pSelf->value.asNum.bDec = HB_DEFAULT_DECIMALS; + pSelf->value.asNum.NumType = HB_ET_DOUBLE; pSelf->ExprType = HB_ET_NUMERIC; } break; @@ -150,6 +153,7 @@ HB_EXPR_PTR hb_compExprReduceDiv( HB_EXPR_PTR pSelf, HB_MACRO_DECL ) if( pRight->value.asNum.lVal ) { pSelf->value.asNum.dVal = pLeft->value.asNum.dVal / ( double ) pRight->value.asNum.lVal; + pSelf->value.asNum.bWidth = HB_DEFAULT_WIDTH; pSelf->value.asNum.bDec = HB_DEFAULT_DECIMALS; } } @@ -158,6 +162,7 @@ HB_EXPR_PTR hb_compExprReduceDiv( HB_EXPR_PTR pSelf, HB_MACRO_DECL ) if( pRight->value.asNum.dVal != 0.0 ) { pSelf->value.asNum.dVal = ( double ) pLeft->value.asNum.lVal / pRight->value.asNum.dVal; + pSelf->value.asNum.bWidth = HB_DEFAULT_WIDTH; pSelf->value.asNum.bDec = HB_DEFAULT_DECIMALS; } } @@ -209,6 +214,7 @@ HB_EXPR_PTR hb_compExprReduceMult( HB_EXPR_PTR pSelf, HB_MACRO_DECL ) else { pSelf->value.asNum.dVal = dVal; + pSelf->value.asNum.bWidth = HB_DEFAULT_WIDTH; pSelf->value.asNum.bDec = 0; pSelf->value.asNum.NumType = HB_ET_DOUBLE; } @@ -219,8 +225,9 @@ HB_EXPR_PTR hb_compExprReduceMult( HB_EXPR_PTR pSelf, HB_MACRO_DECL ) case HB_ET_DOUBLE: { pSelf->value.asNum.dVal = pLeft->value.asNum.dVal * pRight->value.asNum.dVal; - pSelf->value.asNum.NumType = HB_ET_DOUBLE; + pSelf->value.asNum.bWidth = HB_DEFAULT_WIDTH; pSelf->value.asNum.bDec = pLeft->value.asNum.bDec + pRight->value.asNum.bDec; + pSelf->value.asNum.NumType = HB_ET_DOUBLE; break; } @@ -230,11 +237,13 @@ HB_EXPR_PTR hb_compExprReduceMult( HB_EXPR_PTR pSelf, HB_MACRO_DECL ) if( pLeft->value.asNum.NumType == HB_ET_DOUBLE ) { pSelf->value.asNum.dVal = pLeft->value.asNum.dVal * ( double ) pRight->value.asNum.lVal; + pSelf->value.asNum.bWidth = HB_DEFAULT_WIDTH; pSelf->value.asNum.bDec = pLeft->value.asNum.bDec; } else { pSelf->value.asNum.dVal = ( double ) pLeft->value.asNum.lVal * pRight->value.asNum.dVal; + pSelf->value.asNum.bWidth = HB_DEFAULT_WIDTH; pSelf->value.asNum.bDec = pRight->value.asNum.bDec; } pSelf->value.asNum.NumType = HB_ET_DOUBLE; @@ -279,6 +288,7 @@ HB_EXPR_PTR hb_compExprReduceMinus( HB_EXPR_PTR pSelf, HB_MACRO_DECL ) else { pSelf->value.asNum.dVal = dVal; + pSelf->value.asNum.bWidth = HB_DEFAULT_WIDTH; pSelf->value.asNum.bDec = 0; pSelf->value.asNum.NumType = HB_ET_DOUBLE; } @@ -289,11 +299,12 @@ HB_EXPR_PTR hb_compExprReduceMinus( HB_EXPR_PTR pSelf, HB_MACRO_DECL ) case HB_ET_DOUBLE: { pSelf->value.asNum.dVal = pLeft->value.asNum.dVal - pRight->value.asNum.dVal; - pSelf->value.asNum.NumType = HB_ET_DOUBLE; + pSelf->value.asNum.bWidth = HB_DEFAULT_WIDTH; if( pLeft->value.asNum.bDec < pRight->value.asNum.bDec ) pSelf->value.asNum.bDec = pRight->value.asNum.bDec; else pSelf->value.asNum.bDec = pLeft->value.asNum.bDec; + pSelf->value.asNum.NumType = HB_ET_DOUBLE; break; } @@ -303,11 +314,13 @@ HB_EXPR_PTR hb_compExprReduceMinus( HB_EXPR_PTR pSelf, HB_MACRO_DECL ) if( pLeft->value.asNum.NumType == HB_ET_DOUBLE ) { pSelf->value.asNum.dVal = pLeft->value.asNum.dVal - ( double ) pRight->value.asNum.lVal; + pSelf->value.asNum.bWidth = HB_DEFAULT_WIDTH; pSelf->value.asNum.bDec = pLeft->value.asNum.bDec; } else { pSelf->value.asNum.dVal = ( double ) pLeft->value.asNum.lVal - pRight->value.asNum.dVal; + pSelf->value.asNum.bWidth = HB_DEFAULT_WIDTH; pSelf->value.asNum.bDec = pRight->value.asNum.bDec; } pSelf->value.asNum.NumType = HB_ET_DOUBLE; @@ -357,6 +370,7 @@ HB_EXPR_PTR hb_compExprReducePlus( HB_EXPR_PTR pSelf, HB_MACRO_DECL ) else { pSelf->value.asNum.dVal = dVal; + pSelf->value.asNum.bWidth = HB_DEFAULT_WIDTH; pSelf->value.asNum.bDec = 0; pSelf->value.asNum.NumType = HB_ET_DOUBLE; } @@ -367,11 +381,12 @@ HB_EXPR_PTR hb_compExprReducePlus( HB_EXPR_PTR pSelf, HB_MACRO_DECL ) case HB_ET_DOUBLE: { pSelf->value.asNum.dVal = pLeft->value.asNum.dVal + pRight->value.asNum.dVal; - pSelf->value.asNum.NumType = HB_ET_DOUBLE; + pSelf->value.asNum.bWidth = HB_DEFAULT_WIDTH; if( pLeft->value.asNum.bDec < pRight->value.asNum.bDec ) pSelf->value.asNum.bDec = pRight->value.asNum.bDec; else pSelf->value.asNum.bDec = pLeft->value.asNum.bDec; + pSelf->value.asNum.NumType = HB_ET_DOUBLE; break; } @@ -381,11 +396,13 @@ HB_EXPR_PTR hb_compExprReducePlus( HB_EXPR_PTR pSelf, HB_MACRO_DECL ) if( pLeft->value.asNum.NumType == HB_ET_DOUBLE ) { pSelf->value.asNum.dVal = pLeft->value.asNum.dVal + ( double ) pRight->value.asNum.lVal; + pSelf->value.asNum.bWidth = HB_DEFAULT_WIDTH; pSelf->value.asNum.bDec = pLeft->value.asNum.bDec; } else { pSelf->value.asNum.dVal = ( double ) pLeft->value.asNum.lVal + pRight->value.asNum.dVal; + pSelf->value.asNum.bWidth = HB_DEFAULT_WIDTH; pSelf->value.asNum.bDec = pRight->value.asNum.bDec; } pSelf->value.asNum.NumType = HB_ET_DOUBLE; diff --git a/harbour/source/compiler/harbour.l b/harbour/source/compiler/harbour.l index 355f5aaa86..863c2db29b 100644 --- a/harbour/source/compiler/harbour.l +++ b/harbour/source/compiler/harbour.l @@ -1357,15 +1357,15 @@ Separator {SpaceTab} sscanf( yytext, "%lxI", &lNumber ); - if( ( double )SHRT_MIN <= lNumber && - lNumber <= ( double )SHRT_MAX ) + if( ( double ) SHRT_MIN <= lNumber && + lNumber <= ( double ) SHRT_MAX ) { yylval.valInteger.iNumber = lNumber; yylval.valInteger.szValue = yytext; return NUM_INTEGER; } - else if( ( double )LONG_MIN <= lNumber && - lNumber <= ( double )LONG_MAX ) + else if( ( double ) LONG_MIN <= lNumber && + lNumber <= ( double ) LONG_MAX ) { yylval.valLong.lNumber = lNumber; yylval.valLong.szValue = yytext; @@ -1374,6 +1374,7 @@ Separator {SpaceTab} else { yylval.valDouble.dNumber = lNumber; + yylval.valDouble.bWidth = HB_DEFAULT_WIDTH; yylval.valDouble.bDec = 0; yylval.valDouble.szValue = yytext; return NUM_DOUBLE; @@ -1559,6 +1560,7 @@ 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.szValue = szBuffer; return NUM_DOUBLE; @@ -1581,6 +1583,7 @@ static int yy_ConvertNumber( char * szBuffer ) } else { + yylval.valDouble.bWidth = HB_DEFAULT_WIDTH; yylval.valDouble.bDec = 0; yylval.valDouble.szValue = szBuffer; return NUM_DOUBLE; diff --git a/harbour/source/compiler/harbour.y b/harbour/source/compiler/harbour.y index c71b782b0e..4416c31629 100644 --- a/harbour/source/compiler/harbour.y +++ b/harbour/source/compiler/harbour.y @@ -145,6 +145,7 @@ char * hb_comp_szAnnounce = NULL; /* ANNOUNCEd procedure */ { double dNumber; /* to hold a double number returned by lex */ /* NOTE: Intentionally using "unsigned char" instead of "BYTE" */ + unsigned char bWidth; /* to hold the width of the value */ unsigned char bDec; /* to hold the number of decimal points in the value */ char * szValue; } valDouble; @@ -388,14 +389,14 @@ IdentName : IDENTIFIER { $$ = $1; } /* Numeric values */ -NumValue : NUM_DOUBLE { $$ = hb_compExprNewDouble( $1.dNumber, $1.bDec ); } +NumValue : NUM_DOUBLE { $$ = hb_compExprNewDouble( $1.dNumber, $1.bWidth, $1.bDec ); } | NUM_INTEGER { $$ = hb_compExprNewLong( $1.iNumber ); } | NUM_LONG { $$ = hb_compExprNewLong( $1.lNumber ); } ; NumAlias : NUM_INTEGER ALIASOP { $$ = hb_compExprNewLong( $1.iNumber ); } | NUM_LONG ALIASOP { $$ = hb_compExprNewLong( $1.lNumber ); } - | NUM_DOUBLE ALIASOP { $$ = hb_compErrorAlias( hb_compExprNewDouble( $1.dNumber, $1.bDec ) ); } + | NUM_DOUBLE ALIASOP { $$ = hb_compErrorAlias( hb_compExprNewDouble( $1.dNumber, $1.bWidth, $1.bDec ) ); } ; /* NIL value diff --git a/harbour/source/macro/macro.l b/harbour/source/macro/macro.l index 45cd9e2b46..09425c37e7 100644 --- a/harbour/source/macro/macro.l +++ b/harbour/source/macro/macro.l @@ -305,6 +305,7 @@ Separator {SpaceTab} ptr = strchr( yytext, '.' ); if( ptr ) { + yylval_ptr->valDouble.bWidth = HB_DEFAULT_WIDTH; yylval_ptr->valDouble.bDec = strlen( ptr + 1 ); yylval_ptr->valDouble.szValue = yytext ; return NUM_DOUBLE; @@ -320,6 +321,7 @@ Separator {SpaceTab} } else { + yylval_ptr->valDouble.bWidth = HB_DEFAULT_WIDTH; yylval_ptr->valDouble.bDec = 0; yylval_ptr->valDouble.szValue = yytext; return NUM_DOUBLE; @@ -343,6 +345,7 @@ Separator {SpaceTab} else { yylval_ptr->valDouble.dNumber = lNumber; + yylval_ptr->valDouble.bWidth = HB_DEFAULT_WIDTH; yylval_ptr->valDouble.bDec = 0; yylval_ptr->valDouble.szValue = yytext; return NUM_DOUBLE; diff --git a/harbour/source/macro/macro.y b/harbour/source/macro/macro.y index 54b3fff6f2..19b16418b7 100644 --- a/harbour/source/macro/macro.y +++ b/harbour/source/macro/macro.y @@ -107,6 +107,7 @@ extern void yyerror( char * ); /* parsing error management function */ { double dNumber; /* to hold a double number returned by lex */ /* NOTE: Intentionally using "unsigned char" instead of "BYTE" */ + unsigned char bWidth; /* to hold the width of the value */ unsigned char bDec; /* to hold the number of decimal points in the value */ char * szValue; } valDouble; @@ -217,7 +218,7 @@ Main : Expression '\n' { /* Numeric values */ -NumValue : NUM_DOUBLE { $$ = hb_compExprNewDouble( $1.dNumber, $1.bDec ); } +NumValue : NUM_DOUBLE { $$ = hb_compExprNewDouble( $1.dNumber, $1.bWidth, $1.bDec ); } | NUM_LONG { $$ = hb_compExprNewLong( $1.lNumber ); } ; diff --git a/harbour/source/vm/hvm.c b/harbour/source/vm/hvm.c index a06b375d75..5a3302efb5 100644 --- a/harbour/source/vm/hvm.c +++ b/harbour/source/vm/hvm.c @@ -3108,7 +3108,7 @@ static void hb_vmPushDoubleConst( double dNumber, int iWidth, int iDec ) it will be determined at runtime with a relatively slow method. [vszakats] */ - if( iWidth == -1 ) + if( iWidth == HB_DEFAULT_WIDTH ) { char buffer[ 360 ]; sprintf( buffer, "%.*f", 0, dNumber );