From 6f912ba2bd7dd0265ab9b474a82cdaef24973de1 Mon Sep 17 00:00:00 2001 From: Ron Pinkas Date: Fri, 20 Jul 2001 03:32:06 +0000 Subject: [PATCH] 2001-07-19 20:30 UTC-0800 Ron Pinkas * include/hbapi.h + Added #define HB_MAX_MACRO_ARGS 16 * source/vm/hvm.c * source/vm/macro.c + Added support for nested HB_P_MACROPUSHARG * contrib/dot/pp.prg - Removed bSplit in PP_PreProLine(). Instead added logic to split the line unless line is a directive. --- harbour/ChangeLog | 11 +++++++ harbour/contrib/dot/pp.prg | 18 +++++------ harbour/include/hbapi.h | 2 ++ harbour/source/vm/hvm.c | 64 ++++++++++++++++++++++++-------------- harbour/source/vm/macro.c | 11 +++++-- 5 files changed, 69 insertions(+), 37 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 40d80c8886..6c607b6384 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,14 @@ +2001-07-19 20:30 UTC-0800 Ron Pinkas + * include/hbapi.h + + Added #define HB_MAX_MACRO_ARGS 16 + + * source/vm/hvm.c + * source/vm/macro.c + + Added support for nested HB_P_MACROPUSHARG + + * contrib/dot/pp.prg + - Removed bSplit in PP_PreProLine(). Instead added logic to split the line unless line is a directive. + 2001-07-19 21:30 GMT -3 Luiz Rafael Culik *utils/hbmake/hbmake.prg *Small changes needed to be more compatible with Gcc under OS/2 diff --git a/harbour/contrib/dot/pp.prg b/harbour/contrib/dot/pp.prg index 68861fc5e9..f55f49ee9e 100644 --- a/harbour/contrib/dot/pp.prg +++ b/harbour/contrib/dot/pp.prg @@ -2228,7 +2228,7 @@ FUNCTION PP_PreProFile( sSource, sPPOExt, bBlanks ) FWrite( hPP, CRLF ) ENDIF ELSE - sLine := PP_PreProLine( sLine, nLine, sPath + sSource, .F. ) + sLine := PP_PreProLine( sLine, nLine, sPath + sSource ) IF bBlanks .OR. ! ( sLine == '' ) FWrite( hPP, sLine + CRLF ) ENDIF @@ -2266,7 +2266,7 @@ FUNCTION PP_PreProFile( sSource, sPPOExt, bBlanks ) FWrite( hPP, CRLF ) ENDIF ELSE - sLine := PP_PreProLine( sLine, nLine, sPath + sSource, .F. ) + sLine := PP_PreProLine( sLine, nLine, sPath + sSource ) IF bBlanks .OR. ! ( sLine == '' ) FWrite( hPP, sLine + CRLF ) ENDIF @@ -2429,7 +2429,7 @@ FUNCTION PP_PreProFile( sSource, sPPOExt, bBlanks ) ENDIF ELSE //sLine += sRight - sLine := PP_PreProLine( sLine, nLine, sPath + sSource, .F. ) + sLine := PP_PreProLine( sLine, nLine, sPath + sSource ) IF bBlanks .OR. ! ( sLine == '' ) FWrite( hPP, sLine + CRLF ) ENDIF @@ -2452,7 +2452,7 @@ FUNCTION PP_PreProFile( sSource, sPPOExt, bBlanks ) FWrite( hPP, CRLF ) ENDIF ELSE - sLine := PP_PreProLine( sLine, nLine, sPath + sSource, .F. ) + sLine := PP_PreProLine( sLine, nLine, sPath + sSource ) IF bBlanks .OR. ! ( sLine == '' ) FWrite( hPP, sLine + CRLF ) ENDIF @@ -2514,7 +2514,7 @@ FUNCTION PP_PreProFile( sSource, sPPOExt, bBlanks ) FWrite( hPP, sLine ) ENDIF ELSE - sLine := PP_PreProLine( sLine, nLine, sPath + sSource, .F. ) + sLine := PP_PreProLine( sLine, nLine, sPath + sSource ) IF bBlanks .OR. ! ( sLine == '' ) FWrite( hPP, sLine ) ENDIF @@ -2537,7 +2537,7 @@ RETURN .T. //--------------------------------------------------------------// -FUNCTION PP_PreProLine( sLine, nLine, sSource, bSplit ) +FUNCTION PP_PreProLine( sLine, nLine, sSource ) LOCAL nPendingLines := 0, aPendingLines := {} @@ -2551,11 +2551,7 @@ FUNCTION PP_PreProLine( sLine, nLine, sSource, bSplit ) LOCAL sBackupLine LOCAL sSkipped - IF bSplit == NIL - bSplit := .T. - ENDIF - - IF bSplit + IF Left( LTrim( sLine ), 1 ) != '#' nPosition := 0 WHILE ( nNewLineAt := nAtSkipStr( ';', sLine ) ) > 0 nPendingLines++ diff --git a/harbour/include/hbapi.h b/harbour/include/hbapi.h index 366bc87efb..fa25c4ac83 100644 --- a/harbour/include/hbapi.h +++ b/harbour/include/hbapi.h @@ -64,6 +64,8 @@ extern "C" { #endif +#define HB_MAX_MACRO_ARGS 16 + /* items types and type checking macros */ #define HB_IT_NIL ( ( USHORT ) 0x0000 ) #define HB_IT_POINTER ( ( USHORT ) 0x0001 ) diff --git a/harbour/source/vm/hvm.c b/harbour/source/vm/hvm.c index 84128552be..a0ea0721fc 100644 --- a/harbour/source/vm/hvm.c +++ b/harbour/source/vm/hvm.c @@ -253,8 +253,8 @@ static LONG s_lRecoverBase; #define HB_RECOVER_ADDRESS -3 #define HB_RECOVER_VALUE -4 -int hb_vm_iExtraParams = 0; -PHB_SYMB hb_vm_pExtraParamsSymbol = NULL; +int hb_vm_aiExtraParams[HB_MAX_MACRO_ARGS], hb_vm_iExtraParamsIndex = 0; +PHB_SYMB hb_vm_apExtraParamsSymbol[HB_MAX_MACRO_ARGS]; /* Request for some action - stop processing of opcodes */ @@ -1236,24 +1236,44 @@ void hb_vmExecute( const BYTE * pCode, PHB_SYMB pSymbols ) /* the topmost element on the stack contains a macro * string for compilation */ - if( pCode[ w + 1 ] == HB_P_PUSHSYMNEAR ) - { - hb_vm_pExtraParamsSymbol = pSymbols + ( USHORT ) ( pCode[ w + 2 ] ); - w += 3; - } - else if( pCode[ w + 1 ] == HB_P_MPUSHSYM ) - { - HB_DYNS_PTR *pDynSym = ( HB_DYNS_PTR * ) ( pCode + w + 2 ); + hb_macroGetValue( hb_stackItemFromTop( -1 ), TRUE ); + w++; - hb_vm_pExtraParamsSymbol = ( *pDynSym )->pSymbol; - w += sizeof( HB_DYNS_PTR ) + 2; + if( hb_vm_iExtraParamsIndex && hb_vm_apExtraParamsSymbol[hb_vm_iExtraParamsIndex - 1] == NULL ) + { + if( pCode[w] == HB_P_PUSHSYMNEAR ) + { + hb_vm_apExtraParamsSymbol[hb_vm_iExtraParamsIndex - 1] = pSymbols + ( USHORT ) ( pCode[w + 1] ); + w += 2; + } + else if( pCode[w] == HB_P_MPUSHSYM ) + { + HB_DYNS_PTR *pDynSym = ( HB_DYNS_PTR * ) ( pCode + w + 1 ); + + hb_vm_apExtraParamsSymbol[hb_vm_iExtraParamsIndex - 1] = ( *pDynSym )->pSymbol; + w += sizeof( HB_DYNS_PTR ) + 1; + } + else + { + hb_vm_apExtraParamsSymbol[hb_vm_iExtraParamsIndex - 1] = pSymbols + ( USHORT ) ( pCode[w + 1] + ( pCode[w + 2] * 256 ) ); + w += 3; + } } else { - hb_vm_pExtraParamsSymbol = pSymbols + ( USHORT ) ( pCode[ w + 2 ] + ( pCode[ w + 3 ] * 256 ) ); - w += 4; + if( pCode[w] == HB_P_PUSHSYMNEAR ) + { + w += 2; + } + else if( pCode[w] == HB_P_MPUSHSYM ) + { + w += sizeof( HB_DYNS_PTR ) + 1; + } + else + { + w += 3; + } } - hb_macroGetValue( hb_stackItemFromTop( -1 ), TRUE ); break; case HB_P_MACROPUSHALIASED: @@ -2875,13 +2895,11 @@ void hb_vmDo( USHORT uiParams ) HB_TRACE(HB_TR_DEBUG, ("hb_vmDo(%hu)", uiParams)); /* - printf( "\nItems: %i Params: %i Extra %i\n", hb_stack.pPos - hb_stack.pBase, uiParams, hb_vm_iExtraParams ); + printf( "\nItems: %i Params: %i Extra %i\n", hb_stack.pPos - hb_stack.pBase, uiParams, hb_vm_aiExtraParams[hb_vm_iExtraParamsIndex - 1] ); */ - if( hb_vm_iExtraParams && ( ( hb_stack.pPos - hb_stack.pBase ) >= ( uiParams + hb_vm_iExtraParams + 2 ) ) && HB_IS_SYMBOL( pItem = hb_stackItemFromTop( -( uiParams + hb_vm_iExtraParams + 2 ) ) ) && pItem->item.asSymbol.value == hb_vm_pExtraParamsSymbol ) + if( hb_vm_iExtraParamsIndex && HB_IS_SYMBOL( pItem = hb_stackItemFromTop( -( uiParams + hb_vm_aiExtraParams[hb_vm_iExtraParamsIndex - 1] + 2 ) ) ) && pItem->item.asSymbol.value == hb_vm_apExtraParamsSymbol[hb_vm_iExtraParamsIndex - 1] ) { - uiParams += hb_vm_iExtraParams; - hb_vm_iExtraParams = 0; - hb_vm_pExtraParamsSymbol = NULL; + uiParams += hb_vm_aiExtraParams[--hb_vm_iExtraParamsIndex]; } if( bProfiler ) @@ -3007,11 +3025,9 @@ void hb_vmSend( USHORT uiParams ) HB_TRACE(HB_TR_DEBUG, ("hb_vmSend(%hu)", uiParams)); - if( hb_vm_iExtraParams && ( hb_stack.pPos - hb_stack.pBase >= ( uiParams + hb_vm_iExtraParams + 2 ) ) && HB_IS_SYMBOL( pItem = hb_stackItemFromTop( -( uiParams + hb_vm_iExtraParams + 2 ) ) ) && pItem->item.asSymbol.value == hb_vm_pExtraParamsSymbol ) + if( hb_vm_iExtraParamsIndex && HB_IS_SYMBOL( pItem = hb_stackItemFromTop( -( uiParams + hb_vm_aiExtraParams[hb_vm_iExtraParamsIndex - 1] + 2 ) ) ) && pItem->item.asSymbol.value == hb_vm_apExtraParamsSymbol[hb_vm_iExtraParamsIndex - 1] ) { - uiParams += hb_vm_iExtraParams; - hb_vm_iExtraParams = 0; - hb_vm_pExtraParamsSymbol = NULL; + uiParams += hb_vm_aiExtraParams[--hb_vm_iExtraParamsIndex]; } if( bProfiler ) diff --git a/harbour/source/vm/macro.c b/harbour/source/vm/macro.c index 31d92f3911..23ddf76047 100644 --- a/harbour/source/vm/macro.c +++ b/harbour/source/vm/macro.c @@ -427,7 +427,8 @@ char * hb_macroTextSubst( char * szString, ULONG *pulStringLen ) */ void hb_macroGetValue( HB_ITEM_PTR pItem, BOOL bArg ) { - extern int hb_vm_iExtraParams; + extern int hb_vm_aiExtraParams[HB_MAX_MACRO_ARGS], hb_vm_iExtraParamsIndex; + extern PHB_SYMB hb_vm_apExtraParamsSymbol[HB_MAX_MACRO_ARGS]; HB_TRACE(HB_TR_DEBUG, ("hb_macroGetValue(%p)", pItem)); @@ -469,6 +470,11 @@ void hb_macroGetValue( HB_ITEM_PTR pItem, BOOL bArg ) iStatus = hb_macroParse( &struMacro, szString ); + if( bArg && hb_vm_iExtraParamsIndex == HB_MAX_MACRO_ARGS ) + { + hb_macroSyntaxError( &struMacro ); + } + #ifdef HB_MACRO_STATEMENTS hb_xfree( pText ); hb_xfree( pOut ); @@ -481,7 +487,8 @@ void hb_macroGetValue( HB_ITEM_PTR pItem, BOOL bArg ) if( bArg && struMacro.iListElements > 0 ) { - hb_vm_iExtraParams += struMacro.iListElements; + hb_vm_aiExtraParams[hb_vm_iExtraParamsIndex] = struMacro.iListElements; + hb_vm_apExtraParamsSymbol[hb_vm_iExtraParamsIndex++] = NULL; } } else