From db23cdabe2cf7e1224b1aa42701578bb7895bf32 Mon Sep 17 00:00:00 2001 From: Ryszard Glab Date: Sun, 15 Aug 1999 16:54:51 +0000 Subject: [PATCH] ChangeLog 19990815-18:45 --- harbour/ChangeLog | 31 +++++++++++++ harbour/include/ctoharb.h | 7 --- harbour/include/extend.h | 2 +- harbour/include/hb_vmpub.h | 3 ++ harbour/source/compiler/harbour.y | 44 +++++++++--------- harbour/source/rtl/memvars.c | 50 +++++++++++++++++++- harbour/source/vm/dynsym.c | 10 ++++ harbour/source/vm/hvm.c | 74 ++++++++++++++++-------------- harbour/tests/working/adirtest.prg | 1 - 9 files changed, 156 insertions(+), 66 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index b38a4ecebc..0ae7a56aa3 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,34 @@ +19990815-18:45 GMT+2 Ryszard Glab + + *source/rtl/hvm.c + * added 'hb_vm' prefix to alias/field related functions + * some functions declared 'static' + + *include/ctoharb.h + - removed declarations of internal virtual machine functions + + *source/compiler/harbour.y + * changed an error description for incorrect use of PARAMETERS + statement + * added type casting to compile under C++ compilers + * static frame is correctly generated if static variable + is used in a codeblock only + + *include/extend.h + - removed obsolete declaration of hb_memvarNewSymbol() + + *include/hb_vmpub.h + + added definition of callback function HB_DYNS_FUNC used + to enumerate dynamic symbols + + *source/vm/dynsym.c + + new function hb_dynsymEval() that enumerates dynamic symbols + by calling specified HB_DYNS_FUNC * function + + *source/rtl/memvars.c + + added __MVCLEAR function to release all PRIVATE and PUBLIC + variables (this function is used in CLEAR MEMORY statement) + 19990815-19:59 GMT+3 Alexander Kresin * source/rtl/tbrowse.prg * tests/working/testbrw.prg diff --git a/harbour/include/ctoharb.h b/harbour/include/ctoharb.h index befad15b0f..8401e2668c 100644 --- a/harbour/include/ctoharb.h +++ b/harbour/include/ctoharb.h @@ -32,13 +32,6 @@ /* Harbour virtual machine functions */ extern void hb_vmExecute( BYTE * pCode, PHB_SYMB pSymbols ); /* invokes the virtual machine */ extern void hb_vmProcessSymbols( PHB_SYMB pSymbols, WORD wSymbols ); /* statics symbols initialization */ -#ifdef HARBOUR_OBJ_GENERATION -extern void hb_vmProcessObjSymbols ( void ); /* process Harbour generated OBJ symbols */ -#endif -extern void hb_vmDoInitStatics( void ); /* executes all _INITSTATICS functions */ -extern void hb_vmDoInitFunctions( int argc, char * argv[] ); /* executes all defined PRGs INIT functions */ -extern void hb_vmDoExitFunctions( void ); /* executes all defined PRGs EXIT functions */ -extern void hb_vmReleaseLocalSymbols( void ); /* releases the memory of the local symbols linked list */ /* PCode functions */ extern void hb_vmAnd( void ); /* performs the logical AND on the latest two values, removes them and leaves result on the stack */ diff --git a/harbour/include/extend.h b/harbour/include/extend.h index a098e349ad..2f2488b8b0 100644 --- a/harbour/include/extend.h +++ b/harbour/include/extend.h @@ -300,6 +300,7 @@ extern PHB_DYNS hb_dynsymNew( PHB_SYMB pSymbol ); /* creates a new dynamic symbo extern PHB_DYNS hb_dynsymFind( char * szName ); /* finds a dynamic symbol */ extern void hb_dynsymLog( void ); /* displays all dynamic symbols */ extern void hb_dynsymRelease( void ); /* releases the memory of the dynamic symbol table */ +extern void hb_dynsymEval( PHB_DYNS_FUNC ); /* enumerates all dynamic symbols */ /* Symbol management */ extern PHB_SYMB hb_symbolNew( char * szName ); @@ -322,7 +323,6 @@ extern void hb_memvarValueDecRef( HB_HANDLE ); extern void hb_memvarSetValue( PHB_SYMB, HB_ITEM_PTR ); extern void hb_memvarGetValue( HB_ITEM_PTR, PHB_SYMB ); extern void hb_memvarGetRefer( HB_ITEM_PTR, PHB_SYMB ); -extern void hb_memvarNewSymbol( PHB_SYMB ); extern ULONG hb_memvarGetPrivatesBase( void ); extern void hb_memvarSetPrivatesBase( ULONG ); diff --git a/harbour/include/hb_vmpub.h b/harbour/include/hb_vmpub.h index ed279c31a4..98d8867db0 100644 --- a/harbour/include/hb_vmpub.h +++ b/harbour/include/hb_vmpub.h @@ -60,6 +60,9 @@ typedef struct _HB_DYNS PHB_FUNC pFunPtr; /* Pointer to the function address */ } HB_DYNS, * PHB_DYNS, * HB_DYNS_PTR; +#define HB_DYNS_FUNC( hbfunc ) BOOL hbfunc( PHB_DYNS pDynSymbol ) +typedef HB_DYNS_FUNC( PHB_DYNS_FUNC ); + /* Harbour Functions scope (SYMBOLSCOPE) */ #define FS_PUBLIC ((SYMBOLSCOPE)0x00) #define FS_STATIC ((SYMBOLSCOPE)0x02) diff --git a/harbour/source/compiler/harbour.y b/harbour/source/compiler/harbour.y index 6d9da28fef..c11d043e07 100644 --- a/harbour/source/compiler/harbour.y +++ b/harbour/source/compiler/harbour.y @@ -313,7 +313,7 @@ char * _szCErrors[] = { "Statement not allowed outside of procedure or function" "Incorrect number of arguments: %s %s", "Invalid lvalue", "Invalid use of \'@\' (pass by reference): \'%s\'", - "PARAMETERS cannot be used with local parameters" + "Formal parameters already declared" }; /* Table with parse warnings */ @@ -981,9 +981,9 @@ VarDefs : LOCAL { iVarScope = VS_LOCAL; Line(); } VarList Crlf { cVarType = ' | STATIC { StaticDefStart() } VarList Crlf { StaticDefEnd( $3 ); } | PARAMETERS { if( functions.pLast->bFlags & FUN_USES_LOCAL_PARAMS ) GenError( _szCErrors, 'E', ERR_PARAMETERS_NOT_ALLOWED, NULL, NULL ); - else - functions.pLast->wParamNum=0; iVarScope = (VS_PRIVATE | VS_PARAMETER); } - MemvarList Crlf + else + functions.pLast->wParamNum=0; iVarScope = (VS_PRIVATE | VS_PARAMETER); } + MemvarList Crlf ; VarList : VarDef { $$ = 1; } @@ -1881,13 +1881,13 @@ void AddVar( char * szVarName ) break; case (VS_PARAMETER | VS_PRIVATE): { - BOOL bNewParameter = FALSE; + BOOL bNewParameter = FALSE; if( ++functions.pLast->wParamNum > functions.pLast->wParamCount ) - { - functions.pLast->wParamCount =functions.pLast->wParamNum; - bNewParameter = TRUE; - } + { + functions.pLast->wParamCount =functions.pLast->wParamNum; + bNewParameter = TRUE; + } pSym =GetSymbol( szVarName, &wPos ); /* check if symbol exists already */ if( ! pSym ) @@ -1896,15 +1896,15 @@ void AddVar( char * szVarName ) GenPCode3( HB_P_PARAMETER, LOBYTE(wPos), HIBYTE(wPos) ); GenPCode1( LOBYTE(functions.pLast->wParamNum) ); - /* Add this variable to the local variables list - this will - * allow to use the correct positions for real local variables. - * The name of variable have to be hidden because we should - * not find this name on the local variables list. - * We have to use the new structure because it is used in - * memvars list already. - */ - if( bNewParameter ) - { + /* Add this variable to the local variables list - this will + * allow to use the correct positions for real local variables. + * The name of variable have to be hidden because we should + * not find this name on the local variables list. + * We have to use the new structure because it is used in + * memvars list already. + */ + if( bNewParameter ) + { pVar = ( PVAR ) OurMalloc( sizeof( VAR ) ); pVar->szName = yy_strdup( szVarName ); pVar->szAlias = NULL; @@ -1974,7 +1974,7 @@ void AddVar( char * szVarName ) if( _bDebugInfo ) { GenPCode3( HB_P_LOCALNAME, LOBYTE( wLocal ), HIBYTE( wLocal ) ); - GenPCodeN( szVarName, strlen( szVarName ) ); + GenPCodeN( (BYTE *)szVarName, strlen( szVarName ) ); GenPCode1( 0 ); } } @@ -2329,9 +2329,9 @@ void FunDef( char * szFunName, SYMBOLSCOPE cScope, int iType ) if( _bDebugInfo ) { GenPCode1( HB_P_MODULENAME ); - GenPCodeN( files.pLast->szFileName, strlen( files.pLast->szFileName ) ); + GenPCodeN( (BYTE *)files.pLast->szFileName, strlen( files.pLast->szFileName ) ); GenPCode1( ':' ); - GenPCodeN( szFunName, strlen( szFunName ) ); + GenPCodeN( (BYTE *)szFunName, strlen( szFunName ) ); GenPCode1( 0 ); } } @@ -2702,7 +2702,6 @@ void GenCCode( char *szFileName, char *szName ) /* generates the C languag fprintf( yyc, " 0,\n" ); lPCodePos++; break; - break; case HB_P_MESSAGE: { @@ -4954,6 +4953,7 @@ void CodeBlockEnd() pFunc = pCodeblock->pOwner; while( pFunc->pOwner ) pFunc = pFunc->pOwner; + pFunc->bFlags |= ( pCodeblock->bFlags & FUN_USES_STATICS ); /* generate a proper codeblock frame with a codeblock size and with * a number of expected parameters diff --git a/harbour/source/rtl/memvars.c b/harbour/source/rtl/memvars.c index ff26030428..692eb3d610 100644 --- a/harbour/source/rtl/memvars.c +++ b/harbour/source/rtl/memvars.c @@ -552,6 +552,8 @@ static void hb_memvarReleaseWithMask( char *szMask, BOOL bInclude ) } } +/* This function checks the scope of passed variable + */ static int hb_memvarScope( char *szVarName, ULONG ulLength ) { int iMemvar = MV_ERROR; @@ -595,6 +597,18 @@ static int hb_memvarScope( char *szVarName, ULONG ulLength ) return iMemvar; } +static HB_DYNS_FUNC( hb_memvarClear ) +{ + if( pDynSymbol->hMemvar ) + { + _globalTable[ pDynSymbol->hMemvar ].counter = 1; + hb_memvarValueDecRef( pDynSymbol->hMemvar ); + pDynSymbol->hMemvar =0; + } + return TRUE; +} + + /* ************************************************************************** */ /* $DOC$ @@ -886,7 +900,7 @@ HARBOUR HB___MVRELEASE( void ) if( pMask->item.asString.value[ 0 ] == '*' ) bIncludeVar =TRUE; /* delete all memvar variables */ - hb_memvarReleaseWithMask( pMask->item.asString.value, bIncludeVar ); + hb_memvarReleaseWithMask( pMask->item.asString.value, bIncludeVar ); } } } @@ -965,3 +979,37 @@ HARBOUR HB___MVSCOPE( void ) } hb_retni( iMemvar ); } + + +/* $DOC$ + * $FUNCNAME$ + * __MVCLEAR() + * $CATEGORY$ + * Variable management + * $ONELINER$ + * This function releases all PRIVATE and PUBLIC variables + * $SYNTAX$ + * __MVCLEAR() + * $ARGUMENTS$ + * + * $RETURNS$ + * Nothing + * $DESCRIPTION$ + * This function releases all PRIVATE and PUBLIC variables. + * It is used to implement CLEAR MEMORY statement. + * The memory occupied by all visible variables are released - any + * attempt to access the variable will result in a runtime error. + * You have to reuse PRIVATE or PUBLIC statement to create again + * the variable that was cleared by this function. + * $STATUS$ + * + * $COMPLIANCE$ + * + * $SEEALSO$ + * + * $END$ + */ +HARBOUR HB___MVCLEAR( void ) +{ + hb_dynsymEval( hb_memvarClear ); +} diff --git a/harbour/source/vm/dynsym.c b/harbour/source/vm/dynsym.c index 4103f8c4bf..a6ff8f5c6f 100644 --- a/harbour/source/vm/dynsym.c +++ b/harbour/source/vm/dynsym.c @@ -188,6 +188,16 @@ PHB_DYNS hb_dynsymFind( char * szName ) return 0; } +void hb_dynsymEval( PHB_DYNS_FUNC pFunction ) +{ + BOOL bCont = TRUE; + WORD i; + + for( i=0; i < wDynSymbols && bCont; i++ ) + bCont =(pFunction)( pDynItems[ i ].pDynSym ); +} + + void hb_dynsymRelease( void ) { WORD w; diff --git a/harbour/source/vm/hvm.c b/harbour/source/vm/hvm.c index efe7b7f449..7160839a4e 100644 --- a/harbour/source/vm/hvm.c +++ b/harbour/source/vm/hvm.c @@ -73,15 +73,21 @@ HARBOUR HB_ERRORLEVEL( void ); HARBOUR HB_PCOUNT( void ); HARBOUR HB_PVALUE( void ); -static void AliasPop( void ); /* pops the workarea number form the eval stack */ -static void AliasPush( void ); /* pushes the current workarea number */ -static void AliasSwap( void ); /* swaps items on the eval stack and pops the workarea number */ -static void PopAliasedField( PHB_SYMB ); /* pops an aliased field from the eval stack*/ -static void PopField( PHB_SYMB ); /* pops an unaliased field from the eval stack */ -static void PushAliasedField( PHB_SYMB ); /* pushes an aliased field on the eval stack */ -static void PushField( PHB_SYMB ); /* pushes an unaliased field on the eval stack */ +static void hb_vmAliasPop( void ); /* pops the workarea number form the eval stack */ +static void hb_vmAliasPush( void ); /* pushes the current workarea number */ +static void hb_vmAliasSwap( void ); /* swaps items on the eval stack and pops the workarea number */ +static void hb_vmPopAliasedField( PHB_SYMB ); /* pops an aliased field from the eval stack*/ +static void hb_vmPopField( PHB_SYMB ); /* pops an unaliased field from the eval stack */ +static void hb_vmPushAliasedField( PHB_SYMB ); /* pushes an aliased field on the eval stack */ +static void hb_vmPushField( PHB_SYMB ); /* pushes an unaliased field on the eval stack */ + +static void hb_vmDoInitStatics( void ); /* executes all _INITSTATICS functions */ +static void hb_vmDoInitFunctions( int argc, char * argv[] ); /* executes all defined PRGs INIT functions */ +static void hb_vmDoExitFunctions( void ); /* executes all defined PRGs EXIT functions */ +static void hb_vmReleaseLocalSymbols( void ); /* releases the memory of the local symbols linked list */ #ifdef HARBOUR_OBJ_GENERATION +static void hb_vmProcessObjSymbols ( void ); /* process Harbour generated OBJ symbols */ typedef struct { @@ -426,19 +432,19 @@ void hb_vmExecute( BYTE * pCode, PHB_SYMB pSymbols ) break; case HB_P_POPALIAS: - AliasPop(); + hb_vmAliasPop(); w++; break; case HB_P_POPALIASEDFIELD: wParams = pCode[ w + 1 ] + ( pCode[ w + 2 ] * 256 ); - PopAliasedField( pSymbols + wParams ); + hb_vmPopAliasedField( pSymbols + wParams ); w += 3; break; case HB_P_POPFIELD: wParams = pCode[ w + 1 ] + ( pCode[ w + 2 ] * 256 ); - PopField( pSymbols + wParams ); + hb_vmPopField( pSymbols + wParams ); w += 3; break; @@ -464,13 +470,13 @@ void hb_vmExecute( BYTE * pCode, PHB_SYMB pSymbols ) break; case HB_P_PUSHALIAS: - AliasPush(); + hb_vmAliasPush(); w++; break; case HB_P_PUSHALIASEDFIELD: wParams = pCode[ w + 1 ] + ( pCode[ w + 2 ] * 256 ); - PushAliasedField( pSymbols + wParams ); + hb_vmPushAliasedField( pSymbols + wParams ); w += 3; break; @@ -492,7 +498,7 @@ void hb_vmExecute( BYTE * pCode, PHB_SYMB pSymbols ) case HB_P_PUSHFIELD: wParams = pCode[ w + 1 ] + ( pCode[ w + 2 ] * 256 ); - PushField( pSymbols + wParams ); + hb_vmPushField( pSymbols + wParams ); w += 3; break; @@ -561,7 +567,7 @@ void hb_vmExecute( BYTE * pCode, PHB_SYMB pSymbols ) break; case HB_P_SWAPALIAS: - AliasSwap(); + hb_vmAliasSwap(); w++; break; @@ -610,7 +616,7 @@ void hb_vmExecute( BYTE * pCode, PHB_SYMB pSymbols ) /* Pops the item from the eval stack and uses it to select the current * workarea */ -static void AliasPop( void ) +static void hb_vmAliasPop( void ) { PHB_ITEM pItem; @@ -620,7 +626,7 @@ static void AliasPop( void ) { case IT_INTEGER: /* Alias was used as integer value, for example: 4->field - * or it was saved on the stack using AliasPush() + * or it was saved on the stack using hb_vmAliasPush() * or was evaluated from an expression, (nWorkArea)->field */ /* TODO: synchronize it with RDD API @@ -653,12 +659,12 @@ static void AliasPop( void ) break; } - HB_DEBUG( "AliasPop\n" ); + HB_DEBUG( "hb_vmAliasPop\n" ); } /* pushes current workarea number on the eval stack */ -static void AliasPush( void ) +static void hb_vmAliasPush( void ) { stack.pPos->type = IT_INTEGER; /* TODO: synchronize it with RDD API @@ -667,13 +673,13 @@ static void AliasPush( void ) stack.pPos->item.asInteger.length = 10; stack.pPos->item.asInteger.decimal = 0; hb_stackPush(); - HB_DEBUG( "AliasPush\n" ); + HB_DEBUG( "hb_vmAliasPush\n" ); } /* Swaps two last items on the eval stack - the last item after swaping * is popped as current workarea number */ -static void AliasSwap( void ) +static void hb_vmAliasSwap( void ) { HB_ITEM_PTR pItem = stack.pPos -1; HB_ITEM_PTR pWorkArea = stack.pPos -2; @@ -685,7 +691,7 @@ static void AliasSwap( void ) pItem->type =IT_NIL; hb_stackDec(); - HB_DEBUG( "AliasSwap\n" ); + HB_DEBUG( "hb_vmAliasSwap\n" ); } @@ -1566,13 +1572,13 @@ long hb_vmPopDate( void ) } } -static void PopAliasedField( PHB_SYMB pSym ) +static void hb_vmPopAliasedField( PHB_SYMB pSym ) { HB_SYMBOL_UNUSED( pSym ); /* TODO: pop the proper value */ hb_stackPop(); /* field */ hb_stackPop(); /* alias */ - HB_DEBUG( "PopAliasedField\n" ); + HB_DEBUG( "hb_vmPopAliasedField\n" ); } double hb_vmPopDouble( WORD *pwDec ) @@ -1607,12 +1613,12 @@ double hb_vmPopDouble( WORD *pwDec ) return d; } -static void PopField( PHB_SYMB pSym ) +static void hb_vmPopField( PHB_SYMB pSym ) { HB_SYMBOL_UNUSED( pSym ); /* TODO: pop the proper value */ hb_stackPop(); - HB_DEBUG( "PopField\n" ); + HB_DEBUG( "hb_vmPopField\n" ); } void hb_vmPopLocal( SHORT iLocal ) @@ -1728,7 +1734,7 @@ void hb_vmPower( void ) hb_vmPushNumber( pow( d1, d2 ), hb_set.HB_SET_DECIMALS ); } -static void PushAliasedField( PHB_SYMB pSym ) +static void hb_vmPushAliasedField( PHB_SYMB pSym ) { HB_SYMBOL_UNUSED( pSym ); /* TODO: push the proper value */ @@ -1737,7 +1743,7 @@ static void PushAliasedField( PHB_SYMB pSym ) stack.pPos->item.asInteger.length = 10; stack.pPos->item.asInteger.decimal = 0; hb_stackPush(); - HB_DEBUG( "PushAliasedField\n" ); + HB_DEBUG( "hb_vmPushAliasedField\n" ); } void hb_vmPushLogical( BOOL bValue ) @@ -1748,7 +1754,7 @@ void hb_vmPushLogical( BOOL bValue ) HB_DEBUG( "hb_vmPushLogical\n" ); } -static void PushField( PHB_SYMB pSym ) +static void hb_vmPushField( PHB_SYMB pSym ) { HB_SYMBOL_UNUSED( pSym ); /* TODO: push the proper value */ @@ -1757,7 +1763,7 @@ static void PushField( PHB_SYMB pSym ) stack.pPos->item.asInteger.length = 10; stack.pPos->item.asInteger.decimal = 0; hb_stackPush(); - HB_DEBUG( "PushField\n" ); + HB_DEBUG( "hb_vmPushField\n" ); } void hb_vmPushLocal( SHORT iLocal ) @@ -2162,7 +2168,7 @@ void hb_vmProcessSymbols( PHB_SYMB pModuleSymbols, WORD wModuleSymbols ) /* modu } #ifdef HARBOUR_OBJ_GENERATION -void hb_vmProcessObjSymbols( void ) +static void hb_vmProcessObjSymbols( void ) { POBJSYMBOLS pObjSymbols = ( POBJSYMBOLS ) &HB_FIRSTSYMBOL; @@ -2180,7 +2186,7 @@ void hb_vmProcessObjSymbols( void ) } #endif -void hb_vmReleaseLocalSymbols( void ) +static void hb_vmReleaseLocalSymbols( void ) { PSYMBOLS pDestroy; @@ -2197,7 +2203,7 @@ void hb_vmReleaseLocalSymbols( void ) * this function. These two bits cannot be marked at the same * time for normal user defined functions. */ -void hb_vmDoInitStatics( void ) +static void hb_vmDoInitStatics( void ) { PSYMBOLS pLastSymbols = pSymbols; WORD w; @@ -2227,7 +2233,7 @@ void hb_vmDoInitStatics( void ) } while( pLastSymbols ); } -void hb_vmDoExitFunctions( void ) +static void hb_vmDoExitFunctions( void ) { PSYMBOLS pLastSymbols = pSymbols; WORD w; @@ -2251,7 +2257,7 @@ void hb_vmDoExitFunctions( void ) } while( pLastSymbols ); } -void hb_vmDoInitFunctions( int argc, char * argv[] ) +static void hb_vmDoInitFunctions( int argc, char * argv[] ) { PSYMBOLS pLastSymbols = pSymbols; WORD w; diff --git a/harbour/tests/working/adirtest.prg b/harbour/tests/working/adirtest.prg index ae15cef13e..233c06c8be 100644 --- a/harbour/tests/working/adirtest.prg +++ b/harbour/tests/working/adirtest.prg @@ -14,7 +14,6 @@ FUNCTION Main() STATIC FUNCTION TestIt( cSpec ) LOCAL a := ADIR( cSpec ) - LOCAL a1 := Array(a) LOCAL a2 := 10 LOCAL a3 := Array(a - 1)