2012-05-17 18:12 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)

* harbour/include/hbstack.h
  * harbour/src/vm/codebloc.c
  * harbour/src/vm/estack.c
  * harbour/src/vm/hvm.c
    % split hb_stackLocalVariable( int * ) macro and function into
      two different actions:
         hb_stackLocalVariable( int )     // access/assign local var
         hb_stackLocalVariableAt( int * ) // create reference to local var
This commit is contained in:
Przemyslaw Czerpak
2012-05-17 16:12:48 +00:00
parent 993c53c7b0
commit 10b6fb7489
5 changed files with 62 additions and 20 deletions

View File

@@ -16,6 +16,16 @@
The license applies to all entries newer than 2009-04-28.
*/
2012-05-17 18:12 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)
* harbour/include/hbstack.h
* harbour/src/vm/codebloc.c
* harbour/src/vm/estack.c
* harbour/src/vm/hvm.c
% split hb_stackLocalVariable( int * ) macro and function into
two different actions:
hb_stackLocalVariable( int ) // access/assign local var
hb_stackLocalVariableAt( int * ) // create reference to local var
2012-05-16 12:24 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com)
* contrib/hbqt/qtcore/hbqt.h
* contrib/hbqt/qtcore/hbqt_pointer.cpp

View File

@@ -327,7 +327,8 @@ extern HB_ITEM_PTR hb_stackNewFrame( PHB_STACK_STATE pFrame, HB_USHORT uiParams
extern void hb_stackOldFrame( PHB_STACK_STATE pFrame );
extern void hb_stackClearMemvarsBase( void );
extern HB_ITEM_PTR hb_stackLocalVariable( int * piFromBase );
extern HB_ITEM_PTR hb_stackLocalVariable( int iLocal );
extern HB_ITEM_PTR hb_stackLocalVariableAt( int * piFromBase );
extern PHB_ITEM ** hb_stackItemBasePtr( void );
extern HB_EXPORT HB_ISIZ hb_stackGetRecoverBase( void );
@@ -480,8 +481,15 @@ extern void hb_stackUpdateAllocator( void *, PHB_ALLOCUPDT_FUNC, int );
hb_stackIncrease(); \
} while ( 0 )
#define hb_stackLocalVariable( p ) ( ( ( ( *hb_stack.pBase )->item.asSymbol.paramcnt > \
( * hb_stack.pBase )->item.asSymbol.paramdeclcnt ) && \
#define hb_stackLocalVariable( i ) ( hb_stack.pBase[ ( i ) + 1 + \
( ( ( *hb_stack.pBase )->item.asSymbol.paramcnt > \
( *hb_stack.pBase )->item.asSymbol.paramdeclcnt && \
( i ) > ( * hb_stack.pBase )->item.asSymbol.paramdeclcnt ) ? \
( * hb_stack.pBase )->item.asSymbol.paramcnt - \
( * hb_stack.pBase )->item.asSymbol.paramdeclcnt : 0 ) ] )
#define hb_stackLocalVariableAt( p )( ( ( ( *hb_stack.pBase )->item.asSymbol.paramcnt > \
( *hb_stack.pBase )->item.asSymbol.paramdeclcnt ) && \
( * (p) ) > ( * hb_stack.pBase )->item.asSymbol.paramdeclcnt ) ? \
( * ( hb_stack.pBase + ( int ) ( * (p) += \
( * hb_stack.pBase )->item.asSymbol.paramcnt - \

View File

@@ -202,7 +202,7 @@ HB_CODEBLOCK_PTR hb_codeblockNew( const HB_BYTE * pBuffer,
* to implement some kind of semaphores here.
*/
int iLocal = HB_PCODE_MKUSHORT( pLocalPosTable );
pLocal = hb_stackLocalVariable( &iLocal );
pLocal = hb_stackLocalVariable( iLocal );
pLocalPosTable += 2;
pLocal = hb_memvarDetachLocal( pLocal );

View File

@@ -865,7 +865,31 @@ HB_ITEM_PTR hb_stackItemFromBase( int iFromBase )
}
#undef hb_stackLocalVariable
HB_ITEM_PTR hb_stackLocalVariable( int * piFromBase )
HB_ITEM_PTR hb_stackLocalVariable( int iLocal )
{
HB_STACK_TLS_PRELOAD
HB_ITEM_PTR pBase = *hb_stack.pBase;
/*
if( iLocal <= 0 )
hb_errInternal( HB_EI_STACKUFLOW, NULL, NULL, NULL );
*/
if( pBase->item.asSymbol.paramcnt > pBase->item.asSymbol.paramdeclcnt )
{
/* function with variable number of parameters:
* FUNCTION foo( a,b,c,...)
* LOCAL x,y,z
* number of passed parameters is bigger then number of declared
* parameters - skip additional parameters only for local variables
*/
if( iLocal > pBase->item.asSymbol.paramdeclcnt )
iLocal += pBase->item.asSymbol.paramcnt - pBase->item.asSymbol.paramdeclcnt;
}
return * ( hb_stack.pBase + iLocal + 1 );
}
#undef hb_stackLocalVariableAt
HB_ITEM_PTR hb_stackLocalVariableAt( int * piFromBase )
{
HB_STACK_TLS_PRELOAD
HB_ITEM_PTR pBase = *hb_stack.pBase;

View File

@@ -2765,7 +2765,7 @@ void hb_vmExecute( const HB_BYTE * pCode, PHB_SYMB pSymbols )
int iLocal = pCode[ 1 ];
HB_TRACE( HB_TR_DEBUG, ("HB_P_LOCALNEARADDINT") );
hb_vmAddInt( hb_stackLocalVariable( &iLocal ),
hb_vmAddInt( hb_stackLocalVariable( iLocal ),
HB_PCODE_MKSHORT( &pCode[ 2 ] ) );
pCode += 4;
break;
@@ -2776,7 +2776,7 @@ void hb_vmExecute( const HB_BYTE * pCode, PHB_SYMB pSymbols )
int iLocal = HB_PCODE_MKUSHORT( &pCode[ 1 ] );
HB_TRACE( HB_TR_DEBUG, ("HB_P_LOCALADDINT") );
hb_vmAddInt( hb_stackLocalVariable( &iLocal ),
hb_vmAddInt( hb_stackLocalVariable( iLocal ),
HB_PCODE_MKSHORT( &pCode[ 3 ] ) );
pCode += 5;
break;
@@ -2785,7 +2785,7 @@ void hb_vmExecute( const HB_BYTE * pCode, PHB_SYMB pSymbols )
case HB_P_LOCALINC:
{
int iLocal = HB_PCODE_MKUSHORT( &pCode[ 1 ] );
PHB_ITEM pLocal = hb_stackLocalVariable( &iLocal );
PHB_ITEM pLocal = hb_stackLocalVariable( iLocal );
hb_vmInc( HB_IS_BYREF( pLocal ) ? hb_itemUnRef( pLocal ) : pLocal );
pCode += 3;
break;
@@ -2794,7 +2794,7 @@ void hb_vmExecute( const HB_BYTE * pCode, PHB_SYMB pSymbols )
case HB_P_LOCALDEC:
{
int iLocal = HB_PCODE_MKUSHORT( &pCode[ 1 ] );
PHB_ITEM pLocal = hb_stackLocalVariable( &iLocal );
PHB_ITEM pLocal = hb_stackLocalVariable( iLocal );
hb_vmDec( HB_IS_BYREF( pLocal ) ? hb_itemUnRef( pLocal ) : pLocal );
pCode += 3;
break;
@@ -2803,7 +2803,7 @@ void hb_vmExecute( const HB_BYTE * pCode, PHB_SYMB pSymbols )
case HB_P_LOCALINCPUSH:
{
int iLocal = HB_PCODE_MKUSHORT( &pCode[ 1 ] );
PHB_ITEM pLocal = hb_stackLocalVariable( &iLocal );
PHB_ITEM pLocal = hb_stackLocalVariable( iLocal );
if( HB_IS_BYREF( pLocal ) )
pLocal = hb_itemUnRef( pLocal );
hb_vmInc( pLocal );
@@ -7062,7 +7062,7 @@ static void hb_vmPushLocal( int iLocal )
if( iLocal >= 0 )
{
/* local variable or local parameter */
pLocal = hb_stackLocalVariable( &iLocal );
pLocal = hb_stackLocalVariable( iLocal );
}
else
{
@@ -7087,7 +7087,7 @@ static void hb_vmPushLocalByRef( int iLocal )
/* we store its stack offset instead of a pointer to support a dynamic stack */
if( iLocal >= 0 )
{
PHB_ITEM pLocal = hb_stackLocalVariable( &iLocal );
PHB_ITEM pLocal = hb_stackLocalVariableAt( &iLocal );
if( HB_IS_BYREF( pLocal ) && !HB_IS_ENUM( pLocal ) )
{
hb_itemCopy( pTop, pLocal );
@@ -7345,7 +7345,7 @@ static void hb_vmPopLocal( int iLocal )
if( iLocal >= 0 )
{
/* local variable or local parameter */
pLocal = hb_stackLocalVariable( &iLocal );
pLocal = hb_stackLocalVariable( iLocal );
}
else
{
@@ -9423,7 +9423,7 @@ static PHB_ITEM hb_xvmLocalPtr( int iLocal )
if( iLocal >= 0 )
{
/* local variable or local parameter */
return hb_stackLocalVariable( &iLocal );
return hb_stackLocalVariable( iLocal );
}
else
{
@@ -9721,7 +9721,7 @@ void hb_xvmLocalSetInt( int iLocal, HB_LONG lValue )
if( iLocal >= 0 )
{
/* local variable or local parameter */
pLocal = hb_stackLocalVariable( &iLocal );
pLocal = hb_stackLocalVariable( iLocal );
if( HB_IS_BYREF( pLocal ) )
pLocal = hb_itemUnRef( pLocal );
}
@@ -9752,7 +9752,7 @@ HB_BOOL hb_xvmLocalAddInt( int iLocal, HB_LONG lAdd )
HB_TRACE(HB_TR_DEBUG, ("hb_xvmLocalAddInt(%d,%ld)", iLocal, lAdd));
hb_vmAddInt( hb_stackLocalVariable( &iLocal ), lAdd );
hb_vmAddInt( hb_stackLocalVariable( iLocal ), lAdd );
HB_XVM_RETURN
}
@@ -9764,7 +9764,7 @@ HB_BOOL hb_xvmLocalInc( int iLocal )
HB_TRACE(HB_TR_DEBUG, ("hb_xvmLocalInc(%d)", iLocal));
pLocal = hb_stackLocalVariable( &iLocal );
pLocal = hb_stackLocalVariable( iLocal );
hb_vmInc( HB_IS_BYREF( pLocal ) ? hb_itemUnRef( pLocal ) : pLocal );
HB_XVM_RETURN
@@ -9777,7 +9777,7 @@ HB_BOOL hb_xvmLocalDec( int iLocal )
HB_TRACE(HB_TR_DEBUG, ("hb_xvmLocalDec(%d)", iLocal));
pLocal = hb_stackLocalVariable( &iLocal );
pLocal = hb_stackLocalVariable( iLocal );
hb_vmDec( HB_IS_BYREF( pLocal ) ? hb_itemUnRef( pLocal ) : pLocal );
HB_XVM_RETURN
@@ -9790,7 +9790,7 @@ HB_BOOL hb_xvmLocalIncPush( int iLocal )
HB_TRACE(HB_TR_DEBUG, ("hb_xvmLocalInc(%d)", iLocal));
pLocal = hb_stackLocalVariable( &iLocal );
pLocal = hb_stackLocalVariable( iLocal );
if( HB_IS_BYREF( pLocal ) )
pLocal = hb_itemUnRef( pLocal );
hb_vmInc( pLocal );
@@ -9806,7 +9806,7 @@ HB_BOOL hb_xvmLocalAdd( int iLocal )
HB_TRACE(HB_TR_DEBUG, ("hb_xvmLocalAdd(%d)", iLocal));
pLocal = hb_stackLocalVariable( &iLocal );
pLocal = hb_stackLocalVariable( iLocal );
if( HB_IS_BYREF( pLocal ) )
pLocal = hb_itemUnRef( pLocal );
hb_vmPlus( pLocal, hb_stackItemFromTop( -2 ), hb_stackItemFromTop( -1 ) );