Files
harbour-core/harbour/include/hbstack.h
Przemyslaw Czerpak 8bef490815 2006-08-19 01:10 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/hbapi.h
    * moved HB_STACK_STATE declaration from hbstack.h to hbapi.h
      it's covered by _HB_API_INTERNAL_ macro so it should not
      effect 3-rd party code
    * modified hb_struSymbol structure:
         LONG stackbase
      replaced by:
         PHB_STACK_STATE stackstate
      this modification allows to keepadditional information bound with
      function call stack accessible from different HVM modules.
      Now it's used by memvars code to keep/update PRIVATE variables
      stack pointers. I plan to store in HB_STACK_STATE structure
      information additional information for classes code like super
      casting or instance variables offsets in new OOP model I'm working on.
      It can be also used by debugger code to retrieve some informations
      about executed functions without active updating by main HVM loop.
    + added hb_memvarsClear() - cleanly clears all PRIVATE and PUBLIC
      variables
    + added hb_memvarUpdatePrivatesBase() - updates PRIVATE stack base
      offset so PRIVATE variables created in current function/procedure
      will not be removed when it returns
    - removed hb_memvarsRelease() and hb_memvarValueNew()

  * harbour/include/hbstack.h
    + added hb_stackClearMevarsBase() - helper function for hb_memvarsClear()
      clears PRIVATE stack offsets in executed functions
    * changed to static offset from int to long - in different places we
      were using int or long in HVM so I cleaned the HVM code to always
      operate on the same type

  * harbour/source/vm/estack.c
    * set/restore PRIVATE stack base offset in hb_stackNewFrame()/
      hb_stackOldFrame()
    * updated for new HB_IT_SYMBOL structure

  * harbour/source/vm/hvm.c
    ! removed setting/restoring PRIVATE stack base offset in hb_vmExecute()
      It make code like:
         eval(&("{||VAR:=1}"))
      Clipper compatible
    * updated for new HB_IT_SYMBOL structure
    * changed order of execution exit procedures for clean memvars removing
      and future destructors execution. I'll describe it better when I'll
      add destructors.

  * harbour/source/vm/memvars.c
    ! fixed CLEAR MEMORY - now this function should be safe in Harbour
      It's not exactly compatible with Clipper because I intentionally
      didn't replicated some Clipper bugs like possible memory corruption.
    + added hb_memvarsClear() - cleanly clears all PRIVATE and PUBLIC
      variables
    + added hb_memvarUpdatePrivatesBase() - updates PRIVATE stack base
      offset so PRIVATE variables created in current function/procedure
      will not be removed when it returns
    ! fixed releasing PUBLIC and PRIVATE variables which were passed by
      reference and are still active on HVM stack or in codeblocks as
      detached locals (see: hb_memvarDetachDynSym())
    * modified hb_memvarFindSymbol() to be more Clipper compatible
    % optimized hb_memvarRelease() to operate or PHB_DYNS instead of
      string comparison and not make linear dynamic symbol scan for
      PUBLIC or not existing symbols
    - removed hb_memvarReleasePublic()

  * harbour/include/hbvmpub.h
  * harbour/include/hbxvm.h
  * harbour/source/compiler/gencc.c
  * harbour/source/vm/classes.c
  * harbour/source/vm/debug.c
  * harbour/source/vm/itemapi.c
  * harbour/source/vm/pcount.c
  * harbour/source/vm/proc.c
  * harbour/source/vm/pvalue.c
    * updated for the above modifications

  * harbour/source/rtl/memvarbl.prg
  * harbour/source/rtl/menuto.prg
    * use __mvEXIST( cMemvar ) instead of __mvSCOPE( cMemvar ) > HB_MV_ERROR
      __mvEXIST() is much faster function

  * harbour/source/rtl/type.c
    * execute hb_memvarUpdatePrivatesBase() after macro type checking.
      This should not be necessary but we are not Clipper compatible here
      and this is work around for difference in our TYPE() implementation.
      Clipper for:
         ? TYPE("VAR:=1")
      create PUBLIC variable VAR when [x]Harbour PRIVATE one.
      Should we try to make it Clipper compatible?

   The above should fix problems reported with memvars. We are not 100%
   Clipper compatible but unlike in Clipper we cannot break VM internals
   using some operation on references to memvars and detached locals
   and/or RELEASE.../ CLEAR MEMORY. This modifications should be intensively
   tested. If you will find any problems with current code please inform me.
   I'd like to hear your opinions about memvars created by TYPE() (see above).
   Should we change it? It may not be very easy operation - we will have to
   change macro compiler and add new PCODE for that.
2006-08-18 23:12:38 +00:00

192 lines
9.0 KiB
C

/*
* $Id$
*/
/*
* Harbour Project source code:
* The eval stack
*
* Copyright 1999 Antonio Linares <alinares@fivetech.com>
* www - http://www.harbour-project.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
*
* As a special exception, the Harbour Project gives permission for
* additional uses of the text contained in its release of Harbour.
*
* The exception is that, if you link the Harbour libraries with other
* files to produce an executable, this does not by itself cause the
* resulting executable to be covered by the GNU General Public License.
* Your use of that executable is in no way restricted on account of
* linking the Harbour library code into it.
*
* This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public License.
*
* This exception applies only to the code released by the Harbour
* Project under the name Harbour. If you copy code from other
* Harbour Project or Free Software Foundation releases into a copy of
* Harbour, as the General Public License permits, the exception does
* not apply to the code that you add in this way. To avoid misleading
* anyone as to the status of such modified files, you must delete
* this exception notice from them.
*
* If you write modifications of your own for Harbour, it is your choice
* whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice.
*
*/
/* TOFIX: There are several things in this file which are not part of the
standard Harbour API, in other words these things are not
guaranteed to remain unchanged. To avoid confusion these should be
moved to somewhere else (like HBRTL.H). [vszakats] */
#ifndef HB_STACK_H_
#define HB_STACK_H_
#include "hbvmpub.h"
HB_EXTERN_BEGIN
#ifdef _HB_API_INTERNAL_
/* stack managed by the virtual machine */
typedef struct
{
PHB_ITEM * pItems; /* pointer to the stack items */
PHB_ITEM * pPos; /* pointer to the latest used item */
PHB_ITEM * pEnd; /* pointer to the end of stack items */
LONG wItems; /* total items that may be holded on the stack */
HB_ITEM Return; /* latest returned value */
PHB_ITEM * pBase; /* stack frame position for the current function call */
PHB_ITEM * pEvalBase; /* stack frame position for the evaluated codeblock */
LONG lStatics; /* statics base for the current function call */
LONG lWithObject; /* stack offset to base current WITH OBJECT item */
char szDate[ 9 ]; /* last returned date from _pards() yyyymmdd format */
} HB_STACK;
extern HB_STACK hb_stack;
#endif
extern HB_ITEM_PTR hb_stackItemFromTop( int nFromTop );
extern HB_ITEM_PTR hb_stackItemFromBase( int nFromBase );
extern LONG hb_stackTopOffset( void );
extern LONG hb_stackBaseOffset( void );
extern LONG hb_stackTotalItems( void );
extern HB_ITEM_PTR hb_stackBaseItem( void );
extern HB_ITEM_PTR hb_stackSelfItem( void );
extern HB_ITEM_PTR hb_stackItem( LONG iItemPos );
extern HB_ITEM_PTR hb_stackReturnItem( void );
extern char * hb_stackDateBuffer( void );
extern void hb_stackSetStaticsBase( LONG lBase );
extern LONG hb_stackGetStaticsBase( void );
extern PHB_ITEM ** hb_stackItemBasePtr( void );
extern PHB_ITEM hb_stackWithObjectItem( void );
extern LONG hb_stackWithObjectOffset( void );
extern void hb_stackWithObjectSetOffset( LONG );
extern void hb_stackDec( void ); /* pops an item from the stack without clearing it's contents */
extern void hb_stackPop( void ); /* pops an item from the stack */
extern void hb_stackPush( void ); /* pushes an item on to the stack */
extern HB_ITEM_PTR hb_stackAllocItem( void ); /* allocates new item on the top of stack, returns pointer to it */
extern void hb_stackPushReturn( void );
extern void hb_stackPopReturn( void );
extern void hb_stackRemove( LONG lUntilPos );
/* stack management functions */
extern int hb_stackCallDepth( void );
extern LONG hb_stackBaseProcOffset( int iLevel );
extern void hb_stackBaseProcInfo( char * szProcName, USHORT * puiProcLine ); /* get current .PRG function name and line number */
extern void hb_stackDispLocal( void ); /* show the types of the items on the stack for debugging purposes */
extern void hb_stackDispCall( void );
extern void hb_stackFree( void ); /* releases all memory used by the stack */
extern void hb_stackInit( void ); /* initializes the stack */
extern void hb_stackIncrease( void ); /* increase the stack size */
#ifdef _HB_API_INTERNAL_
extern void hb_stackDecrease( ULONG ulItems );
extern HB_ITEM_PTR hb_stackNewFrame( HB_STACK_STATE * pStack, USHORT uiParams );
extern void hb_stackOldFrame( HB_STACK_STATE * pStack );
extern void hb_stackClearMevarsBase( void );
#endif
#if defined(HB_STACK_MACROS)
#define hb_stackItemFromTop( n ) ( * ( hb_stack.pPos + ( int ) (n) ) )
#define hb_stackItemFromBase( n ) ( * ( hb_stack.pBase + ( int ) (n) + 1 ) )
#define hb_stackTopOffset( ) ( hb_stack.pPos - hb_stack.pItems )
#define hb_stackBaseOffset( ) ( hb_stack.pBase - hb_stack.pItems + 1 )
#define hb_stackTotalItems( ) ( hb_stack.wItems )
#define hb_stackBaseItem( ) ( * hb_stack.pBase )
#define hb_stackSelfItem( ) ( * ( hb_stack.pBase + 1 ) )
#define hb_stackItem( iItemPos ) ( * ( hb_stack.pItems + ( iItemPos ) ) )
#define hb_stackReturnItem( ) ( &hb_stack.Return )
#define hb_stackDateBuffer( ) ( hb_stack.szDate )
#define hb_stackGetStaticsBase( ) ( hb_stack.lStatics )
#define hb_stackSetStaticsBase( n ) do { hb_stack.lStatics = ( n ); } while ( 0 )
#define hb_stackItemBasePtr( ) ( &hb_stack.pItems )
#define hb_stackWithObjectItem( ) ( hb_stack.lWithObject ? * ( hb_stack.pItems + hb_stack.lWithObject ) : NULL )
#define hb_stackWithObjectOffset( ) ( hb_stack.lWithObject )
#define hb_stackWithObjectSetOffset( n ) do { hb_stack.lWithObject = ( n ); } while( 0 )
#define hb_stackAllocItem( ) ( ( ++hb_stack.pPos == hb_stack.pEnd ? \
hb_stackIncrease() : (void) 0 ), \
* ( hb_stack.pPos - 1 ) )
#define hb_stackDecrease( n ) do { \
if( ( hb_stack.pPos -= (n) ) < hb_stack.pItems ) \
hb_errInternal( HB_EI_STACKUFLOW, NULL, NULL, NULL ); \
} while ( 0 )
#define hb_stackDec( ) do { \
if( --hb_stack.pPos < hb_stack.pItems ) \
hb_errInternal( HB_EI_STACKUFLOW, NULL, NULL, NULL ); \
} while ( 0 )
#define hb_stackPop( ) do { \
if( --hb_stack.pPos < hb_stack.pItems ) \
hb_errInternal( HB_EI_STACKUFLOW, NULL, NULL, NULL ); \
if( HB_IS_COMPLEX( * hb_stack.pPos ) ) \
hb_itemClear( * hb_stack.pPos ); \
} while ( 0 )
#define hb_stackPush( ) do { \
if( ++hb_stack.pPos == hb_stack.pEnd ) \
hb_stackIncrease(); \
} while ( 0 )
#define hb_stackPopReturn( ) do { \
if( HB_IS_COMPLEX( &hb_stack.Return ) ) \
hb_itemClear( &hb_stack.Return ); \
if( --hb_stack.pPos < hb_stack.pItems ) \
hb_errInternal( HB_EI_STACKUFLOW, NULL, NULL, NULL ); \
hb_itemRawMove( &hb_stack.Return, * hb_stack.pPos ); \
} while ( 0 )
#define hb_stackPushReturn( ) do { \
hb_itemRawMove( * hb_stack.pPos, &hb_stack.Return ); \
if( ++hb_stack.pPos == hb_stack.pEnd ) \
hb_stackIncrease(); \
} while ( 0 )
#endif
HB_EXTERN_END
#endif /* HB_STACK_H_ */