From 3b7d43dcbc61f435cdba865ec1142779b5d5ce90 Mon Sep 17 00:00:00 2001 From: Ryszard Glab Date: Tue, 6 Apr 2004 13:24:11 +0000 Subject: [PATCH] 2004-04-06 15:40 UTC+0100 Ryszard Glab * include/hbapi.h * include/hbvm.h * source/vm/hvm.c * source/vm/macro.c * fixed bug introduced earlier by me in the macro compiler: PUBLIC ¯o works correctly now --- harbour/ChangeLog | 10 +++++++ harbour/include/hbapi.h | 1 + harbour/include/hbvm.h | 1 + harbour/source/vm/hvm.c | 63 ++++++++++++++++++++++++++++----------- harbour/source/vm/macro.c | 16 ++++------ 5 files changed, 62 insertions(+), 29 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index e5e08a3dd7..81b5c79182 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -7,6 +7,16 @@ For example: 2002-12-01 23:12 UTC+0100 Foo Bar */ + +2004-04-06 15:40 UTC+0100 Ryszard Glab + * include/hbapi.h + * include/hbvm.h + * source/vm/hvm.c + * source/vm/macro.c + * fixed bug introduced earlier by me in the macro compiler: + PUBLIC ¯o + works correctly now + 2004-04-03 01:46 UTC-0300 Luiz Rafael Culik(culikr@brturbo.com> * contrib/hbzlib/* ! updated to use the same core as xharbour do diff --git a/harbour/include/hbapi.h b/harbour/include/hbapi.h index 9a0c629003..cf7a074740 100644 --- a/harbour/include/hbapi.h +++ b/harbour/include/hbapi.h @@ -211,6 +211,7 @@ struct hb_struString struct hb_struSymbol { + BOOL macro; /* if symbol was pushed by the macro compiler */ LONG stackbase; USHORT lineno; USHORT paramcnt; diff --git a/harbour/include/hbvm.h b/harbour/include/hbvm.h index c51c4b8b22..055bfd9ceb 100644 --- a/harbour/include/hbvm.h +++ b/harbour/include/hbvm.h @@ -103,6 +103,7 @@ extern void hb_vmPushString( char * szText, ULONG length ); /* pushes a stri extern void hb_vmPushStringPcode( char * szText, ULONG length ); /* pushes a string from pcode on to the stack */ extern void hb_vmPushDate( long lDate ); /* pushes a long date onto the stack */ extern void hb_vmPushSymbol( PHB_SYMB pSym ); /* pushes a function pointer onto the stack */ +extern void hb_vmPushMacroSymbol( PHB_SYMB pSym ); /* pushes a symbol created by the macro compiler onto the stack */ extern void hb_vmPushPointer( void * ); /* push an item of HB_IT_POINTER type */ /* various flags for supported features diff --git a/harbour/source/vm/hvm.c b/harbour/source/vm/hvm.c index dbff267df9..ef4c576b86 100644 --- a/harbour/source/vm/hvm.c +++ b/harbour/source/vm/hvm.c @@ -3404,27 +3404,40 @@ void hb_vmDo( USHORT uiParams ) if( pFunc ) { - if( bProfiler && pSym->pDynSym ) { - pSym->pDynSym->ulRecurse++; - } - - if ( hb_bTracePrgCalls ) - HB_TRACE(HB_TR_ALWAYS, ("Calling: %s", pSym->szName)); - - pFunc(); - - if( bProfiler && pSym->pDynSym ) + if( pItem->item.asSymbol.macro && (pSym->cScope & HB_FS_STATIC) ) { - pSym->pDynSym->ulCalls++; /* profiler support */ - - /* Time spent has to be added only inside topmost call of a recursive function */ - if( pSym->pDynSym->ulRecurse == 1 ) { - pSym->pDynSym->ulTime += clock() - ulClock; /* profiler support */ - } + /* static functions are not allowed in macro + */ + HB_ITEM_PTR pError = hb_errRT_New( ES_ERROR, NULL, EG_NOFUNC, 1001, + NULL, pSym->szName, + 0, EF_NONE ); + hb_errLaunch( pError ); + hb_errRelease( pError ); } + else + { + if( bProfiler && pSym->pDynSym ) { + pSym->pDynSym->ulRecurse++; + } - if( bProfiler && pSym->pDynSym ) { - pSym->pDynSym->ulRecurse--; + if ( hb_bTracePrgCalls ) + HB_TRACE(HB_TR_ALWAYS, ("Calling: %s", pSym->szName)); + + pFunc(); + + if( bProfiler && pSym->pDynSym ) + { + pSym->pDynSym->ulCalls++; /* profiler support */ + + /* Time spent has to be added only inside topmost call of a recursive function */ + if( pSym->pDynSym->ulRecurse == 1 ) { + pSym->pDynSym->ulTime += clock() - ulClock; /* profiler support */ + } + } + + if( bProfiler && pSym->pDynSym ) { + pSym->pDynSym->ulRecurse--; + } } } else @@ -4154,6 +4167,20 @@ void hb_vmPushSymbol( PHB_SYMB pSym ) pStackTopItem->type = HB_IT_SYMBOL; pStackTopItem->item.asSymbol.value = pSym; pStackTopItem->item.asSymbol.stackbase = hb_stackTopOffset(); + pStackTopItem->item.asSymbol.macro = FALSE; + hb_stackPush(); +} + +void hb_vmPushMacroSymbol( PHB_SYMB pSym ) +{ + PHB_ITEM pStackTopItem = hb_stackTopItem(); + + HB_TRACE(HB_TR_DEBUG, ("hb_vmPushSymbol(%p)", pSym)); + + pStackTopItem->type = HB_IT_SYMBOL; + pStackTopItem->item.asSymbol.value = pSym; + pStackTopItem->item.asSymbol.stackbase = hb_stackTopOffset(); + pStackTopItem->item.asSymbol.macro = TRUE; hb_stackPush(); } diff --git a/harbour/source/vm/macro.c b/harbour/source/vm/macro.c index 169ad44a33..e35bc991b4 100644 --- a/harbour/source/vm/macro.c +++ b/harbour/source/vm/macro.c @@ -63,6 +63,8 @@ #include "hbpp.h" #endif +extern HB_FUNC( __MVPUBLIC ); + /* .and. & .or. expressions shortcuts - the expression optimiser needs * a global variable */ @@ -797,6 +799,8 @@ HB_MACRO_PTR hb_macroCompile( char * szString ) } /* This function handles a macro function calls, e.g. var :=¯o() + * and creating memvar variables using PUBLIC/PRIVATE command + * PUBLIC ¯o * * 'pItem' points to a ITEM that contains a string value which after * text substitution will return a function name @@ -822,17 +826,7 @@ void hb_macroPushSymbol( HB_ITEM_PTR pItem ) /* NOTE: checking for valid function name (valid pointer) is done * in hb_vmDo() */ - if( pDynSym && ((pDynSym->pSymbol->pFunPtr == NULL) || (pDynSym->pSymbol->cScope & HB_FS_STATIC)) ) - { - /* static functions are not allowed in macro */ - HB_ITEM_PTR pError = hb_errRT_New( ES_ERROR, NULL, EG_NOFUNC, 1001, - NULL, szString, - 0, EF_NONE ); - hb_errLaunch( pError ); - hb_errRelease( pError ); - } - - hb_vmPushSymbol( pDynSym->pSymbol ); /* push compiled symbol instead of a string */ + hb_vmPushMacroSymbol( pDynSym->pSymbol ); /* push compiled symbol instead of a string */ if( bNewBuffer ) hb_xfree( szString ); /* free space allocated in hb_macroTextSubst */