From e3971c59057c6157721940c7e06d3fabc017dcc3 Mon Sep 17 00:00:00 2001 From: Ryszard Glab Date: Tue, 30 Mar 2004 14:13:52 +0000 Subject: [PATCH] 2004-03-30 16:30 UTC+0100 Ryszard Glab * include/hbapi.h * source/vm/macro.c * added HB_ITEM_PTR pError member to HB_MACRO structure * fixed bug in macro compiler - calls to static functions are not allowed in macro compiler * source/common/expropt1.c * source/common/hbffind.c *fixed minor warnings reported by Randy Portnoff * source/rtl/set.c *SET(_SET_DEBUG) defaults to FALSE (Clipper compatible) * source/rtl/idle.c *small optimization of hb_idleState() * source/compiler/harbour.y *the compiler generates line number for DO CASE (if debug info requested - to allow breakpoint) * source/debug/debugger.prg *the debugger shows the line number for modules where no source code is available --- harbour/ChangeLog | 25 ++++++++++++++ harbour/include/hbapi.h | 1 + harbour/source/common/expropt1.c | 15 ++++---- harbour/source/common/hbffind.c | 2 +- harbour/source/compiler/harbour.y | 2 +- harbour/source/debug/debugger.prg | 3 +- harbour/source/rtl/Makefile | 2 +- harbour/source/rtl/idle.c | 44 +++++++++--------------- harbour/source/rtl/set.c | 2 +- harbour/source/vm/macro.c | 57 +++++++++++++++++++++++++------ 10 files changed, 102 insertions(+), 51 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 34551a9301..8794125cd3 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,31 @@ 2002-12-01 23:12 UTC+0100 Foo Bar */ +2004-03-30 16:30 UTC+0100 Ryszard Glab + * include/hbapi.h + * source/vm/macro.c + * added HB_ITEM_PTR pError member to HB_MACRO structure + * fixed bug in macro compiler - calls to static + functions are not allowed in macro compiler + + * source/common/expropt1.c + * source/common/hbffind.c + *fixed minor warnings reported by Randy Portnoff + + * source/rtl/set.c + *SET(_SET_DEBUG) defaults to FALSE (Clipper compatible) + + * source/rtl/idle.c + *small optimization of hb_idleState() + + * source/compiler/harbour.y + *the compiler generates line number for DO CASE + (if debug info requested - to allow breakpoint) + + * source/debug/debugger.prg + *the debugger shows the line number for modules where + no source code is available + 2004-03-29 15:00 UTC-0500 David G. Holm * source/pp/ppcore.c ! Added missing type conversions on calls to hb_xgrab diff --git a/harbour/include/hbapi.h b/harbour/include/hbapi.h index cd7ec57250..9a0c629003 100644 --- a/harbour/include/hbapi.h +++ b/harbour/include/hbapi.h @@ -542,6 +542,7 @@ typedef struct HB_MACRO_ /* a macro compiled pcode container */ ULONG pos; /* current position inside of compiled string */ int Flags; /* some flags we may need */ int status; /* status of compilation */ + HB_ITEM_PTR pError; /* error object returned from the parser */ ULONG supported; /* various flags for supported capabilities */ int FlexState; /* internal flex state during parsing */ HB_PCODE_INFO_PTR pCodeInfo; /* pointer to pcode buffer and info */ diff --git a/harbour/source/common/expropt1.c b/harbour/source/common/expropt1.c index 4107a38e01..ea0d941c4e 100644 --- a/harbour/source/common/expropt1.c +++ b/harbour/source/common/expropt1.c @@ -430,14 +430,15 @@ HB_EXPR_PTR hb_compExprNewMacro( HB_EXPR_PTR pMacroExpr, unsigned char cMacroOp, * ? &var // this is OK * ? &var.ext // this is invalid */ - char *szDupl; - BOOL bUseTextSubst; + char *szDupl; + BOOL bUseTextSubst; - szDupl = hb_strupr( hb_strdup( szName ) ); - if( ! hb_compExprIsValidMacro( szDupl, &bUseTextSubst, NULL ) ) - hb_compErrorMacro( szName ); - hb_xfree( szDupl ); - + szDupl = hb_strupr( hb_strdup( szName ) ); + if( ! hb_compExprIsValidMacro( szDupl, &bUseTextSubst, NULL ) ) + { + hb_compErrorMacro( szName ); + } + hb_xfree( szDupl ); } } else diff --git a/harbour/source/common/hbffind.c b/harbour/source/common/hbffind.c index 46a828ad76..81b12e51e5 100644 --- a/harbour/source/common/hbffind.c +++ b/harbour/source/common/hbffind.c @@ -592,7 +592,7 @@ static BOOL hb_fsFindNextLow( PHB_FFIND ffind ) nDay = nHour = nMin = - nSec = + nSec = 0; raw_attr = 0; } } diff --git a/harbour/source/compiler/harbour.y b/harbour/source/compiler/harbour.y index 094b390c4d..5cc51a879d 100644 --- a/harbour/source/compiler/harbour.y +++ b/harbour/source/compiler/harbour.y @@ -1446,7 +1446,7 @@ EndCase : ENDCASE } ; -DoCaseStart : DOCASE { ++hb_comp_wCaseCounter; } Crlf +DoCaseStart : DOCASE { ++hb_comp_wCaseCounter; hb_compLinePushIfDebugger();} Crlf ; DoCaseBegin : DoCaseStart { } diff --git a/harbour/source/debug/debugger.prg b/harbour/source/debug/debugger.prg index b25dad23a8..651b5bcf93 100644 --- a/harbour/source/debug/debugger.prg +++ b/harbour/source/debug/debugger.prg @@ -1396,7 +1396,7 @@ LOCAL nlevel, nPos //a procedure with debug info ::aProcStack[i-nDebugLevel+1] := ::aCallStack[ nPos ] ELSE - ::aProcStack[i-nDebugLevel+1] := { PROCNAME( i ), ,,,, nLevel } + ::aProcStack[i-nDebugLevel+1] := { PROCNAME( i )+"("+NTRIM(PROCLINE(i))+")", ,,,, nLevel } ENDIF NEXT @@ -3152,7 +3152,6 @@ static function PathToArray( cList ) local cSep cSep := HB_OsPathListSeparator() - if ( cList <> NIL ) do while ( nPos := at( cSep, cList ) ) <> 0 diff --git a/harbour/source/rtl/Makefile b/harbour/source/rtl/Makefile index fd024dc66a..7019043a44 100644 --- a/harbour/source/rtl/Makefile +++ b/harbour/source/rtl/Makefile @@ -122,8 +122,8 @@ C_SOURCES=\ PRG_SOURCES=\ achoice.prg \ adir.prg \ - alert.prg \ altd.prg \ + alert.prg \ browdb.prg \ browdbx.prg \ browse.prg \ diff --git a/harbour/source/rtl/idle.c b/harbour/source/rtl/idle.c index 9f65c9ba82..bf971aa608 100644 --- a/harbour/source/rtl/idle.c +++ b/harbour/source/rtl/idle.c @@ -90,7 +90,7 @@ static USHORT s_uiIdleTask = 0; static USHORT s_uiIdleMaxTask = 0; /* flag to indicate GarbageCollection should be done in idle state. */ -BOOL hb_vm_bCollectGarbage = TRUE; +static BOOL hb_vm_bCollectGarbage = TRUE; void hb_releaseCPU( void ) { @@ -153,45 +153,35 @@ void hb_idleState( void ) { s_bIamIdle = TRUE; + hb_releaseCPU(); + if( hb_vm_bCollectGarbage ) { - hb_vm_bCollectGarbage = FALSE; hb_gcCollectAll(); - s_bIamIdle = FALSE; - return; + hb_vm_bCollectGarbage = FALSE; } if( s_pIdleTasks && s_uiIdleTask < s_uiIdleMaxTask ) { hb_vmEvalBlock( s_pIdleTasks[ s_uiIdleTask ] ); ++s_uiIdleTask; - s_bIamIdle = FALSE; - return; + if( hb_set.HB_SET_IDLEREPEAT && s_uiIdleTask == s_uiIdleMaxTask ) + { + s_uiIdleTask = 0; /* restart processing of idle tasks */ + hb_vm_bCollectGarbage = TRUE; + } } - - if( hb_set.HB_SET_IDLEREPEAT && s_uiIdleTask == s_uiIdleMaxTask ) - { - s_uiIdleTask = 0; - hb_vm_bCollectGarbage = TRUE; - - hb_releaseCPU(); - s_bIamIdle = FALSE; - return; - } - - hb_releaseCPU(); - s_bIamIdle = FALSE; } } void hb_idleReset( void ) { - if( s_uiIdleTask == s_uiIdleMaxTask ) + if( (! hb_set.HB_SET_IDLEREPEAT) && s_uiIdleTask == s_uiIdleMaxTask ) { s_uiIdleTask = 0; - hb_vm_bCollectGarbage = TRUE; } + hb_vm_bCollectGarbage = TRUE; } /* close all active background task on program exit */ @@ -205,6 +195,7 @@ void hb_idleShutDown( void ) } while( s_uiIdleMaxTask ); hb_xfree( s_pIdleTasks ); + s_uiIdleTask = 0; s_pIdleTasks = NULL; } } @@ -212,13 +203,8 @@ void hb_idleShutDown( void ) /* signal that the user code is in idle state */ HB_FUNC( HB_IDLESTATE ) { + hb_vm_bCollectGarbage = TRUE; hb_idleState(); - - if( s_uiIdleTask == s_uiIdleMaxTask ) - { - s_uiIdleTask = 0; - hb_vm_bCollectGarbage = TRUE; - } } /* add a new background task and return its handle */ @@ -267,6 +253,7 @@ HB_FUNC( HB_IDLEDEL ) if( ulID == ( ULONG ) pItem->item.asBlock.value ) { hb_itemClear( hb_itemReturn( pItem ) ); /* return a codeblock */ + hb_itemRelease( pItem ); --s_uiIdleMaxTask; if( s_uiIdleMaxTask ) @@ -277,10 +264,13 @@ HB_FUNC( HB_IDLEDEL ) sizeof( HB_ITEM_PTR ) * ( s_uiIdleMaxTask - iTask ) ); } s_pIdleTasks = ( HB_ITEM_PTR * ) hb_xrealloc( s_pIdleTasks, sizeof( HB_ITEM_PTR ) * s_uiIdleMaxTask ); + if( s_uiIdleTask >= s_uiIdleMaxTask ) + s_uiIdleTask = 0; } else { hb_xfree( s_pIdleTasks ); + s_uiIdleTask = 0; s_pIdleTasks = NULL; } bFound = TRUE; diff --git a/harbour/source/rtl/set.c b/harbour/source/rtl/set.c index 44ef80b773..ae9ad14094 100644 --- a/harbour/source/rtl/set.c +++ b/harbour/source/rtl/set.c @@ -916,7 +916,7 @@ void hb_setInitialize( void ) hb_set.HB_SET_CONSOLE = TRUE; hb_set.HB_SET_DATEFORMAT = ( char * ) hb_xgrab( 9 ); memcpy( hb_set.HB_SET_DATEFORMAT, "mm/dd/yy", 9 ); - hb_set.HB_SET_DEBUG = TRUE; + hb_set.HB_SET_DEBUG = FALSE; hb_set.HB_SET_DECIMALS = 2; hb_set.HB_SET_DEFAULT = ( char * ) hb_xgrab( 1 ); hb_set.HB_SET_DEFAULT[ 0 ] = '\0'; diff --git a/harbour/source/vm/macro.c b/harbour/source/vm/macro.c index 878e7f4058..1422d08a57 100644 --- a/harbour/source/vm/macro.c +++ b/harbour/source/vm/macro.c @@ -215,22 +215,32 @@ static void hb_macroEvaluate( HB_MACRO_PTR pMacro ) static void hb_macroSyntaxError( HB_MACRO_PTR pMacro ) { HB_ITEM_PTR pResult; - + HB_ITEM_PTR pError = NULL; + HB_TRACE(HB_TR_DEBUG, ("hb_macroSyntaxError(%p)", pMacro)); if( pMacro ) { HB_TRACE(HB_TR_DEBUG, ("hb_macroSyntaxError.(%s)", pMacro->string)); - hb_macroDelete( pMacro ); /* TODO: use pMacro->status for more detailed error messagess */ + pError = pMacro->pError; + hb_macroDelete( pMacro ); } - pResult = hb_errRT_BASE_Subst( EG_SYNTAX, 1449, NULL, "&", 0 ); - - if( pResult ) + if( pError ) { - hb_vmPush( pResult ); - hb_itemRelease( pResult ); + hb_errLaunch( pError ); + hb_errRelease( pError ); + } + else + { + pResult = hb_errRT_BASE_Subst( EG_SYNTAX, 1449, NULL, "&", 0 ); + + if( pResult ) + { + hb_vmPush( pResult ); + hb_itemRelease( pResult ); + } } } @@ -759,6 +769,16 @@ void hb_macroPushSymbol( HB_ITEM_PTR pItem ) /* NOTE: checking for valid function name (valid pointer) is done * in hb_vmDo() */ + if( pDynSym && ((pDynSym->pSymbol->pFunPtr == NULL) || (pDynSym->pSymbol->cScope & HB_FS_STATIC)) ) + { + /* static functions are not allowed in macro */ + HB_ITEM_PTR pError = hb_errRT_New( ES_ERROR, NULL, EG_NOFUNC, 1001, + NULL, szString, + 0, EF_NONE ); + hb_errLaunch( pError ); + hb_errRelease( pError ); + } + hb_vmPushSymbol( pDynSym->pSymbol ); /* push compiled symbol instead of a string */ if( bNewBuffer ) @@ -1112,7 +1132,6 @@ void hb_compGenPushSymbol( char * szSymbolName, BOOL bFunction, BOOL bAlias, HB_ { HB_DYNS_PTR pSym; - HB_SYMBOL_UNUSED( bFunction ); HB_SYMBOL_UNUSED( bAlias ); if( HB_MACRO_DATA->Flags & HB_MACRO_GEN_TYPE ) @@ -1131,7 +1150,23 @@ void hb_compGenPushSymbol( char * szSymbolName, BOOL bFunction, BOOL bAlias, HB_ } } else - pSym = hb_dynsymGet( szSymbolName ); + pSym = hb_dynsymGet( szSymbolName ); + + if( bFunction ) + { + if( pSym && ((pSym->pSymbol->pFunPtr == NULL) || (pSym->pSymbol->cScope & HB_FS_STATIC)) ) + { + /* static functions are not allowed in macro */ + HB_MACRO_DATA->status |= HB_MACRO_UNKN_SYM; + HB_MACRO_DATA->status &= ~HB_MACRO_CONT; /* don't run this pcode */ + if( !(HB_MACRO_DATA->Flags & HB_MACRO_GEN_TYPE) ) + { + HB_MACRO_DATA->pError = hb_errRT_New( ES_ERROR, NULL, EG_NOFUNC, 1001, + NULL, szSymbolName, + 0, EF_NONE ); + } + } + } hb_compGenPCode1( HB_P_MPUSHSYM, HB_MACRO_PARAM ); hb_compGenPCodeN( ( BYTE * ) &pSym, sizeof( pSym ), HB_MACRO_PARAM ); @@ -1390,12 +1425,12 @@ void hb_compGenPushFunCall( char * szFunName, HB_MACRO_DECL ) { /* Abbreviated function name was used - change it for whole name */ - hb_compGenPushSymbol( szFunction, FALSE, FALSE, HB_MACRO_PARAM ); + hb_compGenPushSymbol( szFunction, TRUE, FALSE, HB_MACRO_PARAM ); } else { HB_MACRO_DATA->status |= HB_MACRO_UDF; /* this is used in hb_macroGetType */ - hb_compGenPushSymbol( szFunName, FALSE, FALSE, HB_MACRO_PARAM ); + hb_compGenPushSymbol( szFunName, TRUE, FALSE, HB_MACRO_PARAM ); } }