diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 06549145b0..a531a7b295 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,26 @@ +19990519-02:45 Ryszard Glab + +* source/compiler/harbour.y + - added support for INCLUDE environment variable + - corrected looking for unmatched ENDIF/ELSE//ELSEIF + - added '-t' option = alternative initialization of symbol table + When this option is used then the Harbour generates C code for a function + __InitSymbols that have to be called in order to properly + initialize the global symbol table. You should use this option if you + want to generate the C code output and your C compiler doesn't allow + to call any function before the 'main'. + +* surce/vm/initsymb.c + - added new file that registers a symbols table with runtime support + functions. This file can be edited to add calls for application specific + functions that registers local symbols tables used in application modules. + The Harbour compiler can create __InitSymbols functions + when you use '-t' option. + +* source/vm/hvm.c + - added call for InitSymbolTable function that registers symbol table + with runtime support Harbour functions. + 19990518-19:30 David G. Holm * source/rtl/environ.c - Enhanced Harbour OS function to return both OS and Version @@ -311,10 +334,43 @@ NB! Not needed for 32-bit compilers. Tue May 11 18:53:43 1999 Gonzalo A. Diethelm +<<<<<<< ChangeLog +======= * Makefile: Added obj to the list of directories. +>>>>>>> 1.78 +<<<<<<< ChangeLog + * Makefile: + Added obj to the list of directories. + + * source/Makefile: + Added rdd to the list of directories. + + * source/rtl/Makefile: + Added gtapi.c to the list of C sources. + + * source/rtl/gtapi.c: + Got rid of two warnings with gcc. + + * source/rtl/environ.c: + Made sure it compiles with gcc. + There was a missing #endif. + + * source/tools/stringp.prg: + * tests/working/debugtst.prg: + Replaced Debug() with HBDebug(), otherwise the generated C source + collides with the macro DEBUG. + + * source/vm/hvm.c: + Corrected a comment. + + * source/rdd/Makefile: + * obj/Makefile: + Added these two Makefiles. + +======= * source/Makefile: Added rdd to the list of directories. @@ -340,6 +396,7 @@ Tue May 11 18:53:43 1999 Gonzalo A. Diethelm * obj/Makefile: Added these two Makefiles. +>>>>>>> 1.78 19990511-19:20 Eddie Runia * source/rtl/classes.c (Default) parameter self added to INLINE methods diff --git a/harbour/source/compiler/harbour.l b/harbour/source/compiler/harbour.l index 1cbfe74f1a..189ddad6c4 100644 --- a/harbour/source/compiler/harbour.l +++ b/harbour/source/compiler/harbour.l @@ -395,7 +395,7 @@ Separator {SpaceTab}|{Comment}|{LineCont} %} "endif"|"endi" { /* ENDIF can be used in one context only */ if( _wIfCounter == 0 ) - GenError( ERR_ENDIF, NULL, NULL ); + GenError( ERR_ENDIF, NULL, NULL ); return ENDIF; } "endc"("ase"|"as"|"a")? { /* ENDCASE can be used in one context only */ diff --git a/harbour/source/compiler/harbour.y b/harbour/source/compiler/harbour.y index f6cdb72325..7f8211e3a7 100644 --- a/harbour/source/compiler/harbour.y +++ b/harbour/source/compiler/harbour.y @@ -131,6 +131,7 @@ static void __yy_memcpy( char * from, char * to, int count ); /* Bison prototype /* production related functions */ PFUNCTION AddFunCall( char * szFuntionName ); void AddExtern( char * szExternName ); /* defines a new extern name */ +void AddSearchPath( char *, PATHNAMES * * ); /* add pathname to a search list */ void AddVar( char * szVarName ); /* add a new param, local, static variable to a function definition or a public or private */ PCOMSYMBOL AddSymbol( char * szSymbolName ); void CheckDuplVars( PVAR pVars, char * szVarName, int iVarScope ); /*checks for duplicate variables definitions */ @@ -352,6 +353,7 @@ int _iSyntaxCheckOnly = 0; /* syntax check only */ int _iLanguage = LANG_C; /* default Harbour generated output language */ int _iRestrictSymbolLength = 0; /* generate 10 chars max symbols length */ int _iShortCuts = 1; /* .and. & .or. expressions shortcuts */ +short int _iAltSymbolTableInit = 0; /* alternative method of symbol table initialization */ WORD _wSeqCounter = 0; WORD _wForCounter = 0; WORD _wIfCounter = 0; @@ -791,8 +793,9 @@ IfEndif : IfBegin EndIf { JumpHere( $1 ); } | IfBegin IfElseIf IfElse EndIf { JumpHere( $1 ); FixElseIfs( $2 ); } ; -IfBegin : IF Expression Crlf { $$ = JumpFalse( 0 ); ++_wIfCounter; } IfStats - { $$ = Jump( 0 ); JumpHere( $4 ); } +IfBegin : IF Expression { ++_wIfCounter; } Crlf { $$ = JumpFalse( 0 ); } + IfStats + { $$ = Jump( 0 ); JumpHere( $5 ); } ; IfElse : ELSE Crlf IfStats @@ -1054,23 +1057,7 @@ int harbour_main( int argc, char * argv[] ) case 'i': case 'I': - { - PATHNAMES *pPath = _pIncludePath; - - if( pPath ) - { - while( pPath->pNext ) - pPath =pPath->pNext; - pPath->pNext =(PATHNAMES *)OurMalloc( sizeof(PATHNAMES) ); - pPath =pPath->pNext; - } - else - { - _pIncludePath = pPath =(PATHNAMES *)OurMalloc( sizeof(PATHNAMES) ); - } - pPath->pNext = NULL; - pPath->szPath = argv[ iArg ]+2; - } + AddSearchPath( argv[ iArg ]+2, &_pIncludePath ); break; case 'l': @@ -1098,6 +1085,11 @@ int harbour_main( int argc, char * argv[] ) _iSyntaxCheckOnly = 1; break; + case 't': + case 'T': + _iAltSymbolTableInit = 1; + break; + case 'y': case 'Y': yydebug = TRUE; @@ -1152,6 +1144,22 @@ int harbour_main( int argc, char * argv[] ) if( Include( szFileName, NULL ) ) { + char * szInclude = getenv( "INCLUDE" ); + + if( szInclude ) + { + char * pPath; + char * pDelim; + + pPath = szInclude = strdup( szInclude ); + while( (pDelim = strchr( pPath, ';' )) != NULL ) + { + *pDelim ='\0'; + AddSearchPath( pPath, &_pIncludePath ); + pPath =pDelim + 1; + } + } + FunDef( strupr( strdup( pFileName->name ) ), FS_PUBLIC, FUN_PROCEDURE ); yyparse(); FixReturns(); /* fix all previous function returns offsets */ @@ -1260,6 +1268,7 @@ void PrintUsage( char * szSelf ) "\t/o\tobject file drive and/or path\n" "\t/q\t\tquiet\n" "\t/s\t\tsyntax check only\n" + "\t/t\t\talternative method of symbol table initialization\n" "\t/y\t\ttrace lex & yacc activity\n" "\t/z\t\tsupress .and. & .or. shortcutting\n" "\t/10\t\trestrict symbol length to 10 characters\n" @@ -1384,6 +1393,29 @@ char *MakeFilename( char *szFileName, FILENAME *pFileName ) return szFileName; } +/* + * Function that adds specified path to the list of pathnames to search + */ +void AddSearchPath( char *szPath, PATHNAMES * *pSearchList ) +{ + PATHNAMES *pPath = *pSearchList; + + if( pPath ) + { + while( pPath->pNext ) + pPath =pPath->pNext; + pPath->pNext =(PATHNAMES *)OurMalloc( sizeof(PATHNAMES) ); + pPath =pPath->pNext; + } + else + { + *pSearchList =pPath =(PATHNAMES *)OurMalloc( sizeof(PATHNAMES) ); + } + pPath->pNext = NULL; + pPath->szPath = szPath; +} + + PFUNCTION AddFunCall( char * szFunctionName ) { PFUNCTION pFunc = ( PFUNCTION ) OurMalloc( sizeof( _FUNC ) ); @@ -1797,9 +1829,11 @@ void GenCCode( char *szFileName, char *szName ) /* generates the C languag if( ! _iStartProc ) pSym = pSym->pNext; /* starting procedure is always the first symbol */ + wSym = 0; /* syymbols counter */ while( pSym ) { fprintf( yyc, "{ \"%s\", ", pSym->szName ); + ++wSym; if( pSym->cScope & FS_STATIC ) fprintf( yyc, "FS_STATIC" ); @@ -1835,7 +1869,15 @@ void GenCCode( char *szFileName, char *szName ) /* generates the C languag } fprintf( yyc, " };\n\n" ); - fprintf( yyc, "#include \n\n" ); + if( _iAltSymbolTableInit ) + { + fprintf( yyc, "void ProcessSymbols( SYMBOL *, WORD );\n" ); + fprintf( yyc, "/* Add a local symbol table to the global one\n*/\n" ); + fprintf( yyc, "void %s__InitSymbols( void )\n{\n" + " ProcessSymbols( symbols, %i );\n}\n\n", symbols.pFirst->szName, wSym ); + } + else + fprintf( yyc, "#include \n\n" ); /* Generate functions data */ diff --git a/harbour/source/vm/Makefile b/harbour/source/vm/Makefile index adc3c651a0..813e6b83b1 100644 --- a/harbour/source/vm/Makefile +++ b/harbour/source/vm/Makefile @@ -7,6 +7,7 @@ ROOT = ../../ C_SOURCES=\ dynsym.c \ hvm.c \ + initsymb.c \ LIB=vm diff --git a/harbour/source/vm/hvm.c b/harbour/source/vm/hvm.c index 8c881dcbdc..c381e65ed8 100644 --- a/harbour/source/vm/hvm.c +++ b/harbour/source/vm/hvm.c @@ -1,4 +1,7 @@ -/* The Harbour virtual machine */ +/* $Id$ + * + * The Harbour virtual machine + */ /* Please note the following comments we may use everywhere TODO: something should be added here @@ -117,6 +120,8 @@ void CodeblockEvaluate( PCODEBLOCK ); void CodeblockCopy( PITEM, PITEM ); void CodeblockDetach( PCODEBLOCK ); +void InitSymbolTable( void ); /* initialization of runtime support symbols */ + static void ForceLink( void ); ULONG hb_isMessage( PITEM, char * ); @@ -185,6 +190,10 @@ BYTE bErrorLevel = 0; /* application exit errorlevel */ #ifdef OBJ_GENERATION ProcessObjSymbols(); /* initialize Harbour generated OBJs symbols */ #endif + + /* Initialize symbol table with runtime support functions */ + InitSymbolTable(); + DoInitFunctions( argc, argv ); /* process defined INIT functions */ #ifdef HARBOUR_MAIN diff --git a/harbour/source/vm/initsymb.c b/harbour/source/vm/initsymb.c new file mode 100644 index 0000000000..51bb08cff2 --- /dev/null +++ b/harbour/source/vm/initsymb.c @@ -0,0 +1,128 @@ +/* $Id$ + * + * Initiialization of runtime support symbols + */ +#include "hbsetup.h" +#include "extend.h" +#include "types.h" + +void ProcessSymbols( SYMBOL *, WORD ); + +HARBOUR AADD( void ); +HARBOUR ABS( void ); +HARBOUR ASC( void ); +HARBOUR AT( void ); +HARBOUR CHR( void ); +HARBOUR CTOD( void ); +HARBOUR DAY( void ); +HARBOUR DTOC( void ); +HARBOUR DTOS( void ); +HARBOUR EMPTY( void ); +HARBOUR EXP( void ); +HARBOUR INT( void ); +HARBOUR LEFT( void ); +HARBOUR LEN( void ); +HARBOUR LOG( void ); +HARBOUR LOWER( void ); +HARBOUR LTRIM( void ); +HARBOUR MAX( void ); +HARBOUR MIN( void ); +HARBOUR MONTH( void ); +HARBOUR PCOUNT( void ); +HARBOUR REPLICATE( void ); +HARBOUR RTRIM( void ); +HARBOUR SPACE( void ); +HARBOUR SQRT( void ); +HARBOUR STR( void ); +HARBOUR STR( void ); +HARBOUR SUBSTR( void ); +HARBOUR TIME( void ); +HARBOUR TRANSFORM( void ); +HARBOUR TRIM( void ); +HARBOUR UPPER( void ); +HARBOUR VAL( void ); +HARBOUR YEAR( void ); + + +static SYMBOL symbols[] = { + { "AADD" , FS_PUBLIC, AADD , 0 }, + { "ABS" , FS_PUBLIC, ABS , 0 }, + { "ASC" , FS_PUBLIC, ASC , 0 }, + { "AT" , FS_PUBLIC, AT , 0 }, + { "BOF" , FS_PUBLIC, NULL , 0 }, + { "BREAK" , FS_PUBLIC, NULL , 0 }, + { "CDOW" , FS_PUBLIC, NULL , 0 }, + { "CHR" , FS_PUBLIC, CHR , 0 }, + { "CMONTH" , FS_PUBLIC, NULL , 0 }, + { "COL" , FS_PUBLIC, NULL , 0 }, + { "CTOD" , FS_PUBLIC, CTOD , 0 }, + { "DATE" , FS_PUBLIC, NULL , 0 }, + { "DAY" , FS_PUBLIC, DAY , 0 }, + { "DELETED" , FS_PUBLIC, NULL , 0 }, + { "DEVPOS" , FS_PUBLIC, NULL , 0 }, + { "DO" , FS_PUBLIC, NULL , 0 }, + { "DOW" , FS_PUBLIC, NULL , 0 }, + { "DTOC" , FS_PUBLIC, DTOC , 0 }, + { "DTOS" , FS_PUBLIC, DTOS , 0 }, + { "EMPTY" , FS_PUBLIC, EMPTY , 0 }, + { "EOF" , FS_PUBLIC, NULL , 0 }, + { "EXP" , FS_PUBLIC, EXP , 0 }, + { "FCOUNT" , FS_PUBLIC, NULL , 0 }, + { "FIELDNAME" , FS_PUBLIC, NULL , 0 }, + { "FLOCK" , FS_PUBLIC, NULL , 0 }, + { "FOUND" , FS_PUBLIC, NULL , 0 }, + { "INKEY" , FS_PUBLIC, NULL , 0 }, + { "INT" , FS_PUBLIC, INT , 0 }, + { "LASTREC" , FS_PUBLIC, NULL , 0 }, + { "LEFT" , FS_PUBLIC, LEFT , 0 }, + { "LEN" , FS_PUBLIC, LEN , 0 }, + { "LOCK" , FS_PUBLIC, NULL , 0 }, + { "LOG" , FS_PUBLIC, LOG , 0 }, + { "LOWER" , FS_PUBLIC, LOWER , 0 }, + { "LTRIM" , FS_PUBLIC, LTRIM , 0 }, + { "MAX" , FS_PUBLIC, MAX , 0 }, + { "MIN" , FS_PUBLIC, MIN , 0 }, + { "MONTH" , FS_PUBLIC, MONTH , 0 }, + { "PCOL" , FS_PUBLIC, NULL , 0 }, + { "PCOUNT" , FS_PUBLIC, PCOUNT , 0 }, + { "PROW" , FS_PUBLIC, NULL , 0 }, + { "QSELF" , FS_PUBLIC, NULL , 0 }, + { "RECCOUNT" , FS_PUBLIC, NULL , 0 }, + { "RECNO" , FS_PUBLIC, NULL , 0 }, + { "REPLICATE" , FS_PUBLIC, REPLICATE , 0 }, + { "RLOCK" , FS_PUBLIC, NULL , 0 }, + { "ROUND" , FS_PUBLIC, NULL , 0 }, + { "ROW" , FS_PUBLIC, NULL , 0 }, + { "RTRIM" , FS_PUBLIC, RTRIM , 0 }, + { "SECONDS" , FS_PUBLIC, NULL , 0 }, + { "SELECT" , FS_PUBLIC, NULL , 0 }, + { "SETPOS" , FS_PUBLIC, NULL , 0 }, + { "SPACE" , FS_PUBLIC, SPACE , 0 }, + { "SQRT" , FS_PUBLIC, SQRT , 0 }, + { "STR" , FS_PUBLIC, STR , 0 }, + { "SUBSTR" , FS_PUBLIC, SUBSTR , 0 }, + { "TIME" , FS_PUBLIC, TIME , 0 }, + { "TRANSFORM" , FS_PUBLIC, TRANSFORM , 0 }, + { "TRIM" , FS_PUBLIC, TRIM , 0 }, + { "TYPE" , FS_PUBLIC, NULL , 0 }, + { "UPPER" , FS_PUBLIC, UPPER , 0 }, + { "VAL" , FS_PUBLIC, VAL , 0 }, + { "WORD" , FS_PUBLIC, NULL , 0 }, + { "YEAR" , FS_PUBLIC, YEAR , 0 } + }; + +/* + * Registers runtime support functions symbols + */ +void InitSymbolTable( void ) +{ + /* + * Place here your __InitSymbols functions + */ + + + /* + * The system symbol table with runtime functions HAVE TO be called last + */ + ProcessSymbols( symbols, sizeof(symbols)/sizeof( SYMBOL ) ); +} diff --git a/harbour/source/vm/makefile.dos b/harbour/source/vm/makefile.dos index bdfb23feba..eb378fb10a 100644 --- a/harbour/source/vm/makefile.dos +++ b/harbour/source/vm/makefile.dos @@ -3,7 +3,7 @@ # include ..\..\makedos.env -OBJECTS=hvm.o dynsym.o +OBJECTS=hvm.o dynsym.o initsymb.o all: $(HARBOURLIB) diff --git a/harbour/source/vm/makefile.wat b/harbour/source/vm/makefile.wat index 9e8c935a27..f5a41d6eba 100644 --- a/harbour/source/vm/makefile.wat +++ b/harbour/source/vm/makefile.wat @@ -5,7 +5,7 @@ TARGET=$(HARBOURLIB) -OBJECTS=hvm.obj dynsym.obj +OBJECTS=hvm.obj dynsym.obj initsymb.obj all : $(TARGET)