From 8759e5e270e595a73e2689e257d7f555175237d8 Mon Sep 17 00:00:00 2001 From: "David G. Holm" Date: Wed, 17 Nov 1999 00:40:27 +0000 Subject: [PATCH] See ChangeLog entry 19991116-19:25 EDT David G. Holm --- harbour/ChangeLog | 37 ++++++++++++++++++++++++++++ harbour/config/dos/djgpp.cf | 2 +- harbour/config/os2/gcc.cf | 2 +- harbour/config/w32/gcc.cf | 4 ++-- harbour/source/compiler/expropt.c | 40 +++++++++++++++++++++++-------- harbour/source/compiler/harbour.y | 2 +- 6 files changed, 72 insertions(+), 15 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index e88b2a6afb..58e12a9240 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,26 @@ +19991116-19:25 EDT David G. Holm + + * config/dos/djgpp.cf + * config/os2/gcc.cf + * config/w32/gcc.cf + - Removed -g compiler option and -DDEBUG preprocessor option + If you want to compile with debug, add -g and -DDEBUG to the + C_USR environment variable. + + * source/compiler/expropt.c + ! Corrected the division optimization to return 0 for any attempt + to divide by 0. + ! Corrected the division optimization to only return a long when the + result of dividing long values is a whole value instead of returning + a long when the result is within the range of a long (the result of + dividing a long by a long will always be within the range of a long). + % Changed the double results to return 2 decimal places after division + optimization, which still isn't correct (see the source code for + TODO: NOTE 1), but is more accurate than returning 0 decimal places. + + * source/compiler/harbour.y + - Removed one of two occurrences of ExprEqual (on line 209). + 19991117-01:03 GMT+1 Victor Szel * include/hbver.h * Version number updated to reflect the deep changes. @@ -18,7 +41,9 @@ * new expression optimizer * start of introducing new functions' naming scheme 'hb_comp' * nonprintable characters (CR/LF/TAB, etc.) are inserted into + generated C code using hexdecimal numbers instead of quoted char + (they can appear as a result of expression optimization) * source/pp/hbpp.c @@ -28,19 +53,31 @@ * changes to support new functions' naming scheme 'hb_comp' *include/pcode.h + *HB_P_ARRAYAAT -> HB_P_ARRAYPUSH + HB_P_ARRAYAPUT -> HB_P_ARRAYPOP - it removes value from the stack + This is compatible with the handling of usual variables + *source/debug/debugger.prg + * corrected the following syntax: + something other := another + for example: + ? 2 + a:=5 -1 + This syntax is not allowed in Clipper and in new Harbour rules too + It should be used: + ? 2 + (a:=5) -1 + * doc/compiler.txt * added description of incompatibility with Clipper in object handling diff --git a/harbour/config/dos/djgpp.cf b/harbour/config/dos/djgpp.cf index 9fbbf7b6df..8e2b331ff4 100644 --- a/harbour/config/dos/djgpp.cf +++ b/harbour/config/dos/djgpp.cf @@ -13,7 +13,7 @@ CC = gcc CC_IN = -c CC_OUT = -o CPPFLAGS = -I. -I$(HB_INC_COMPILE) -CFLAGS = -Wall -g +CFLAGS = -Wall LD = gcc LD_OUT = -o diff --git a/harbour/config/os2/gcc.cf b/harbour/config/os2/gcc.cf index e336712a20..ced63a1a86 100644 --- a/harbour/config/os2/gcc.cf +++ b/harbour/config/os2/gcc.cf @@ -13,7 +13,7 @@ CC = gcc CC_IN = -c CC_OUT = -o CPPFLAGS = -DDEBUG -I. -I$(HB_INC_COMPILE) -DHARBOUR_GCC_OS2 -CFLAGS = -Wall -g +CFLAGS = -Wall LD = gcc LD_OUT = -o $(SPACE) diff --git a/harbour/config/w32/gcc.cf b/harbour/config/w32/gcc.cf index a570900d51..757885eaef 100644 --- a/harbour/config/w32/gcc.cf +++ b/harbour/config/w32/gcc.cf @@ -12,8 +12,8 @@ LIB_EXT = .a CC = gcc CC_IN = -c CC_OUT = -o -CPPFLAGS = -DDEBUG -I. -I$(HB_INC_COMPILE) -CFLAGS = -Wall -g +CPPFLAGS = -I. -I$(HB_INC_COMPILE) +CFLAGS = -Wall LD = gcc LD_OUT = -o diff --git a/harbour/source/compiler/expropt.c b/harbour/source/compiler/expropt.c index 79c5e062f0..09c6de5188 100644 --- a/harbour/source/compiler/expropt.c +++ b/harbour/source/compiler/expropt.c @@ -41,6 +41,7 @@ * stored in next element of the array. */ +#include #include "compiler.h" /* memory allocation @@ -4298,23 +4299,27 @@ static HB_EXPR_FUNC( hb_compExprUseDiv ) if( pLeft->ExprType == HB_ET_NUMERIC && pRight->ExprType == HB_ET_NUMERIC ) { unsigned char bType = ( pLeft->value.asNum.NumType & pRight->value.asNum.NumType ); + double dVal = 0.0; switch( bType ) { case HB_ET_LONG: { - double dVal = pLeft->value.asNum.lVal / pRight->value.asNum.lVal; + if( pRight->value.asNum.lVal ) + dVal = ( double )pLeft->value.asNum.lVal / ( double )pRight->value.asNum.lVal; - if( ( double )LONG_MIN <= dVal && dVal <= ( double )LONG_MAX ) + if( fmod( dVal, 1.0 ) == 0.0 ) { - pSelf->value.asNum.lVal = pLeft->value.asNum.lVal / pRight->value.asNum.lVal; + /* Return integer results as long */ + pSelf->value.asNum.lVal = dVal; pSelf->value.asNum.bDec = 0; pSelf->value.asNum.NumType = HB_ET_LONG; } else { + /* Return non-integer results as double */ pSelf->value.asNum.dVal = dVal; - pSelf->value.asNum.bDec = 0; + pSelf->value.asNum.bDec = 2; /* TODO: See NOTE 1 */ pSelf->value.asNum.NumType = HB_ET_DOUBLE; } } @@ -4322,9 +4327,11 @@ static HB_EXPR_FUNC( hb_compExprUseDiv ) case HB_ET_DOUBLE: { - pSelf->value.asNum.dVal = pLeft->value.asNum.dVal / pRight->value.asNum.dVal; + if( pRight->value.asNum.dVal != 0.0 ) + dVal = pLeft->value.asNum.dVal / pRight->value.asNum.dVal; + pSelf->value.asNum.dVal = dVal; pSelf->value.asNum.NumType = HB_ET_DOUBLE; - pSelf->value.asNum.bDec = pLeft->value.asNum.bDec + pRight->value.asNum.bDec; + pSelf->value.asNum.bDec = 2; /* TODO: See NOTE 1 */ } break; @@ -4332,16 +4339,29 @@ static HB_EXPR_FUNC( hb_compExprUseDiv ) { if( pLeft->value.asNum.NumType == HB_ET_DOUBLE ) { - pSelf->value.asNum.dVal = pLeft->value.asNum.dVal / ( double ) pRight->value.asNum.lVal; - pSelf->value.asNum.bDec = pLeft->value.asNum.bDec; + if( pRight->value.asNum.lVal ) + dVal = pLeft->value.asNum.dVal / ( double ) pRight->value.asNum.lVal; + pSelf->value.asNum.dVal = dVal; + pSelf->value.asNum.bDec = 2; /* TODO: See NOTE 1 */ } else { - pSelf->value.asNum.dVal = ( double ) pLeft->value.asNum.lVal / pRight->value.asNum.dVal; - pSelf->value.asNum.bDec = pRight->value.asNum.bDec; + if( pRight->value.asNum.dVal != 0.0 ) + dVal = ( double ) pLeft->value.asNum.lVal / pRight->value.asNum.dVal; + pSelf->value.asNum.dVal = dVal; + pSelf->value.asNum.bDec = 2; /* TODO: See NOTE 1 */ } pSelf->value.asNum.NumType = HB_ET_DOUBLE; } + /* TODO: NOTE 1 + Clipper manages to print the default number of decimal + digits for optimized division results. Should we add a + "marker value" that tells Harbour to print the default + number of decimal digits? For example: pSelf->value. + asNum.bDec = HB_DEC_DEFAULT and then have Harbour check + for HB_DEC_DEFAULT when formatting numbers and print + the current default number of decimal digits. + */ } pSelf->ExprType = HB_ET_NUMERIC; pSelf->ValType = HB_EV_NUMERIC; diff --git a/harbour/source/compiler/harbour.y b/harbour/source/compiler/harbour.y index 0c87a94044..a7735517b9 100644 --- a/harbour/source/compiler/harbour.y +++ b/harbour/source/compiler/harbour.y @@ -206,7 +206,7 @@ USHORT hb_comp_wCaseCounter = 0; %type PareExpList PareExpListAlias %type Expression SimpleExpression LValue %type EmptyExpression -%type ExprAssign ExprOperEq ExprEqual ExprPreOp ExprPostOp +%type ExprAssign ExprOperEq ExprPreOp ExprPostOp %type ExprEqual ExprMath ExprBool ExprRelation %type ArrayIndex IndexList %type DimIndex DimList