2001-07-16 02:45 UTC-0800 Ron Pinkas <ron@profit-master.com>

* source/vm/hvm.c
     * Few improvements to recent support for lists in macro expansion

   * source/vm/macro.c
     + Added preprocessing support to hb_macroGetValue()

   * source/compiler/harbour.sly
   * source/compiler/harbour.y
     + Added rules to support MacroVar and MacroExpr as a standalone Statement.
This commit is contained in:
Ron Pinkas
2001-07-16 09:41:28 +00:00
parent 005cee072c
commit 6c5369f4f8
5 changed files with 138 additions and 16 deletions

View File

@@ -1,3 +1,14 @@
2001-07-16 02:45 UTC-0800 Ron Pinkas <ron@profit-master.com>
* source/vm/hvm.c
* Few improvements to recent support for lists in macro expansion
* source/vm/macro.c
+ Added preprocessing support to hb_macroGetValue()
* source/compiler/harbour.sly
* source/compiler/harbour.y
+ Added rules to support MacroVar and MacroExpr as a standalone Statement.
2001-07-15 20:45 UTC-0800 Ron Pinkas <ron@profit-master.com>
* include/hbapi.h
+ Added member iListElements to HB_MACRO structure.

View File

@@ -337,6 +337,8 @@ Statement : ExecFlow CrlfStmnt { }
| FunCall CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); }
| AliasExpr CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); }
| ObjectMethod CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); }
| MacroVar CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); }
| MacroExpr CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); }
| PareExpList CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); }
| ExprPreOp CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); }
| ExprPostOp CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); }

View File

@@ -325,6 +325,8 @@ Statement : ExecFlow CrlfStmnt { }
| FunCall CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); }
| AliasExpr CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); }
| ObjectMethod CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); }
| MacroVar CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); }
| MacroExpr CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); }
| PareExpList CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); }
| ExprPreOp CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); }
| ExprPostOp CrlfStmnt { hb_compExprDelete( hb_compExprGenStatement( $1 ) ); }

View File

@@ -247,7 +247,7 @@ static LONG s_lRecoverBase;
#define HB_RECOVER_ADDRESS -3
#define HB_RECOVER_VALUE -4
int hb_vm_iFunCalls = 0, *hb_vm_aiMacroListParameters = NULL, hb_vm_iMacroListAllocated;
int hb_vm_iFunCalls = 0, *hb_vm_aiMacroListParameters = NULL, hb_vm_iMacroListAllocated = 0, hb_vm_iExtraParams;
/* Request for some action - stop processing of opcodes
*/
@@ -387,7 +387,10 @@ void hb_vmQuit( void )
{
HB_TRACE(HB_TR_DEBUG, ("hb_vmQuit()"));
hb_xfree( (void*) hb_vm_aiMacroListParameters );
if( hb_vm_aiMacroListParameters )
{
hb_xfree( (void*) hb_vm_aiMacroListParameters );
}
s_uiActionRequest = 0; /* EXIT procedures should be processed */
hb_vmDoExitFunctions(); /* process defined EXIT functions */
@@ -581,6 +584,13 @@ void hb_vmExecute( const BYTE * pCode, PHB_SYMB pSymbols )
/* Object */
case HB_P_MESSAGE:
if( hb_vm_iFunCalls >= hb_vm_iMacroListAllocated )
{
//printf( "\nRealloc! FunCalls: %i Allocated: %i \n", hb_vm_iFunCalls, hb_vm_iMacroListAllocated );
hb_vm_aiMacroListParameters = (int *) hb_xrealloc( (void*) hb_vm_aiMacroListParameters, sizeof( int ) * ( hb_vm_iMacroListAllocated += 16 ) );
}
hb_vm_aiMacroListParameters[ hb_vm_iFunCalls++ ] = 0;
hb_vmMessage( pSymbols + ( USHORT ) ( pCode[ w + 1 ] + ( pCode[ w + 2 ] * 256 ) ) );
w += 3;
break;
@@ -595,42 +605,102 @@ void hb_vmExecute( const BYTE * pCode, PHB_SYMB pSymbols )
/* Execution */
case HB_P_DO:
hb_vmDo( pCode[ w + 1 ] + ( pCode[ w + 2 ] * 256 ) + hb_vm_aiMacroListParameters[ hb_vm_iFunCalls - 1 ] );
if( hb_vm_iFunCalls )
{
hb_vm_iExtraParams = hb_vm_aiMacroListParameters[ --hb_vm_iFunCalls ];
}
else
{
hb_vm_iExtraParams = 0;
//printf( "\nOops!\n" );
}
hb_vmDo( pCode[ w + 1 ] + ( pCode[ w + 2 ] * 256 ) + hb_vm_iExtraParams );
w += 3;
break;
case HB_P_DOSHORT:
hb_vmDo( pCode[ w + 1 ] + hb_vm_aiMacroListParameters[ hb_vm_iFunCalls - 1 ] );
if( hb_vm_iFunCalls )
{
hb_vm_iExtraParams = hb_vm_aiMacroListParameters[ --hb_vm_iFunCalls ];
}
else
{
hb_vm_iExtraParams = 0;
//printf( "\nOops!\n" );
}
hb_vmDo( pCode[ w + 1 ] + hb_vm_iExtraParams );
w += 2;
break;
case HB_P_FUNCTION:
if( hb_vm_iFunCalls )
{
hb_vm_iExtraParams = hb_vm_aiMacroListParameters[ --hb_vm_iFunCalls ];
}
else
{
hb_vm_iExtraParams = 0;
//printf( "\nOops!\n" );
}
hb_itemClear( &hb_stack.Return );
hb_vmDo( pCode[ w + 1 ] + ( pCode[ w + 2 ] * 256 ) + hb_vm_aiMacroListParameters[ hb_vm_iFunCalls - 1 ] );
hb_vmDo( pCode[ w + 1 ] + ( pCode[ w + 2 ] * 256 ) + hb_vm_iExtraParams );
hb_itemCopy( hb_stackTopItem(), &hb_stack.Return );
hb_stackPush();
w += 3;
break;
case HB_P_FUNCTIONSHORT:
if( hb_vm_iFunCalls )
{
hb_vm_iExtraParams = hb_vm_aiMacroListParameters[ --hb_vm_iFunCalls ];
}
else
{
hb_vm_iExtraParams = 0;
//printf( "\nOops!\n" );
}
hb_itemClear( &hb_stack.Return );
hb_vmDo( pCode[ w + 1 ] + hb_vm_aiMacroListParameters[ hb_vm_iFunCalls - 1 ] );
hb_vmDo( pCode[ w + 1 ] + hb_vm_iExtraParams );
hb_itemCopy( hb_stackTopItem(), &hb_stack.Return );
hb_stackPush();
w += 2;
break;
case HB_P_SEND:
if( hb_vm_iFunCalls )
{
hb_vm_iExtraParams = hb_vm_aiMacroListParameters[ --hb_vm_iFunCalls ];
}
else
{
hb_vm_iExtraParams = 0;
//printf( "\nOops!\n" );
}
hb_itemClear( &hb_stack.Return );
hb_vmSend( pCode[ w + 1 ] + ( pCode[ w + 2 ] * 256 + hb_vm_aiMacroListParameters[ hb_vm_iFunCalls - 1 ] ) );
hb_vmSend( pCode[ w + 1 ] + ( pCode[ w + 2 ] * 256 + hb_vm_iExtraParams ) );
hb_itemCopy( hb_stackTopItem(), &hb_stack.Return );
hb_stackPush();
w += 3;
break;
case HB_P_SENDSHORT:
if( hb_vm_iFunCalls )
{
hb_vm_iExtraParams = hb_vm_aiMacroListParameters[ --hb_vm_iFunCalls ];
}
else
{
hb_vm_iExtraParams = 0;
//printf( "\nOops!\n" );
}
hb_itemClear( &hb_stack.Return );
hb_vmSend( pCode[ w + 1 ] + hb_vm_aiMacroListParameters[ hb_vm_iFunCalls - 1 ] );
hb_vmSend( pCode[ w + 1 ] + hb_vm_iExtraParams );
hb_itemCopy( hb_stackTopItem(), &hb_stack.Return );
hb_stackPush();
w += 2;
@@ -1024,8 +1094,9 @@ void hb_vmExecute( const BYTE * pCode, PHB_SYMB pSymbols )
break;
case HB_P_PUSHSYM:
if( hb_vm_iFunCalls > hb_vm_iMacroListAllocated )
if( hb_vm_iFunCalls >= hb_vm_iMacroListAllocated )
{
//printf( "\nRealloc! FunCalls: %i Allocated: %i \n", hb_vm_iFunCalls, hb_vm_iMacroListAllocated );
hb_vm_aiMacroListParameters = (int *) hb_xrealloc( (void*) hb_vm_aiMacroListParameters, sizeof( int ) * ( hb_vm_iMacroListAllocated += 16 ) );
}
hb_vm_aiMacroListParameters[ hb_vm_iFunCalls++ ] = 0;
@@ -1035,8 +1106,9 @@ void hb_vmExecute( const BYTE * pCode, PHB_SYMB pSymbols )
break;
case HB_P_PUSHSYMNEAR:
if( hb_vm_iFunCalls > hb_vm_iMacroListAllocated )
if( hb_vm_iFunCalls >= hb_vm_iMacroListAllocated )
{
//printf( "\nRealloc! FunCalls: %i Allocated: %i \n", hb_vm_iFunCalls, hb_vm_iMacroListAllocated );
hb_vm_aiMacroListParameters = (int *) hb_xrealloc( (void*) hb_vm_aiMacroListParameters, sizeof( int ) * ( hb_vm_iMacroListAllocated += 16 ) );
}
hb_vm_aiMacroListParameters[ hb_vm_iFunCalls++ ] = 0;
@@ -1244,8 +1316,9 @@ void hb_vmExecute( const BYTE * pCode, PHB_SYMB pSymbols )
case HB_P_MACROSYMBOL:
/* compile into a symbol name (used in function calls) */
if( hb_vm_iFunCalls > hb_vm_iMacroListAllocated )
if( hb_vm_iFunCalls >= hb_vm_iMacroListAllocated )
{
//printf( "\nRealloc! FunCalls: %i Allocated: %i \n", hb_vm_iFunCalls, hb_vm_iMacroListAllocated );
hb_vm_aiMacroListParameters = (int *) hb_xrealloc( (void*) hb_vm_aiMacroListParameters, sizeof( int ) * ( hb_vm_iMacroListAllocated += 16 ) );
}
hb_vm_aiMacroListParameters[ hb_vm_iFunCalls++ ] = 0;
@@ -1267,6 +1340,14 @@ void hb_vmExecute( const BYTE * pCode, PHB_SYMB pSymbols )
case HB_P_MMESSAGE:
{
HB_DYNS_PTR * pDynSym = ( HB_DYNS_PTR * ) ( pCode + w + 1 );
if( hb_vm_iFunCalls >= hb_vm_iMacroListAllocated )
{
//printf( "\nRealloc! FunCalls: %i Allocated: %i \n", hb_vm_iFunCalls, hb_vm_iMacroListAllocated );
hb_vm_aiMacroListParameters = (int *) hb_xrealloc( (void*) hb_vm_aiMacroListParameters, sizeof( int ) * ( hb_vm_iMacroListAllocated += 16 ) );
}
hb_vm_aiMacroListParameters[ hb_vm_iFunCalls++ ] = 0;
hb_vmMessage( ( *pDynSym )->pSymbol );
w += sizeof( HB_DYNS_PTR ) + 1;
break;
@@ -2859,8 +2940,6 @@ void hb_vmDo( USHORT uiParams )
HB_TRACE(HB_TR_DEBUG, ("hb_vmDo(%hu)", uiParams));
hb_vm_aiMacroListParameters[ --hb_vm_iFunCalls ] = 0;
hb_inkeyPoll(); /* Poll the console keyboard */
pItem = hb_stackNewFrame( &sStackState, uiParams );
@@ -2975,8 +3054,6 @@ void hb_vmSend( USHORT uiParams )
HB_TRACE(HB_TR_DEBUG, ("hb_vmSend(%hu)", uiParams));
hb_vm_aiMacroListParameters[ --hb_vm_iFunCalls ] = 0;
pItem = hb_stackNewFrame( &sStackState, uiParams ); /* procedure name */
pSym = pItem->item.asSymbol.value;
pSelf = hb_stackSelfItem(); /* NIL, OBJECT or BLOCK */

View File

@@ -433,15 +433,45 @@ void hb_macroGetValue( HB_ITEM_PTR pItem )
int iStatus;
char * szString = pItem->item.asString.value;
char * pText = ( char * ) hb_xgrab( HB_PP_STR_SIZE );
char * pOut = ( char * ) hb_xgrab( HB_PP_STR_SIZE );
char * ptr = pText;
int slen;
struMacro.Flags = HB_MACRO_GEN_PUSH;
struMacro.bShortCuts = hb_comp_bShortCuts;
struMacro.uiNameLen = HB_SYMBOL_NAME_LEN;
struMacro.status = HB_MACRO_CONT;
struMacro.iListElements = 0;
slen = HB_MIN( szString, HB_PP_STR_SIZE - 1 );
memcpy( pText, szString, slen );
pText[ slen ] = 0;
memset( pOut, 0, HB_PP_STR_SIZE );
HB_SKIPTABSPACES( ptr );
if( !hb_pp_topDefine )
{
hb_pp_Table();
}
hb_pp_ParseExpression( ptr, pOut );
szString = pText;
iStatus = hb_macroParse( &struMacro, szString );
hb_vm_aiMacroListParameters[ hb_vm_iFunCalls - 1 ] = struMacro.iListElements;
hb_xfree( pText );
hb_xfree( pOut );
if( hb_vm_iFunCalls )
{
hb_vm_aiMacroListParameters[ hb_vm_iFunCalls - 1 ] = struMacro.iListElements;
}
else
{
//printf( "Oops\n" );
}
hb_stackPop(); /* remove compiled string */
if( iStatus == HB_MACRO_OK && ( struMacro.status & HB_MACRO_CONT ) )