diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 9ecb282600..388f5a9ee2 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,27 @@ +19990716-06:45 GMT+1 Ryszard Glab + + *source/compiler/harbour.y + * corrected generation of proper static frame for functions + (the values of static variables defined in different modules + are no longer overlapped) + + *tests/broken/statics1.prg + *tests/broken/statics2.prg + -moved to tests/working directory + + *config/dos/watcom.cf + * corrected to support HB_*_COMPILE variables + + *config/global.cf + *config/rules.cf + * removed duplicated definition of HB variable + * HB_*_COMPILE variables are defined now before architecture + and compiler specific config file is included (it allows to change + these variables for specific architecture/compiler requirements) + + *doc/codebloc.txt + + added description of an incompatibility with Clipper + 19990715-23:40 CET Eddie Runia * tests/working/arrays.prg; tests/working/dosshell.prg; diff --git a/harbour/config/dos/watcom.cf b/harbour/config/dos/watcom.cf index 7658fd2371..8bbc3e5c20 100644 --- a/harbour/config/dos/watcom.cf +++ b/harbour/config/dos/watcom.cf @@ -26,20 +26,25 @@ $(COMSPEC) /E:2048 /Cecho FILE $(file) >> __link__.tmp endef +#Note: The empty line directly before 'endef' HAVE TO exist! +define link_lib +$(COMSPEC) /E:2048 /Cecho LIB $(lib) >> __link__.tmp + +endef define link_exe_file $(COMSPEC) /E:2048 /Cecho $(LDFLAGS) NAME $@ > __link__.tmp $(foreach file, $^, $(link_file)) -$(COMSPEC) /E:2048 /Cecho $(LINKLIBS) >> __link__.tmp +$(foreach lib, $(LINKLIBS), $(link_lib)) -$(LD) @__link__.tmp endef LD = wlink LDFLAGS = debug all OP osn=DOS4G OP stack=65536 ifeq ($(HB_LIB_COMPILE),) -LINKLIBS = $(foreach lib, $(LIBS), LIB $(subst /,\,$(TOP)$(ROOT)source/$(lib)/$(ARCH)/$(lib))) +LINKLIBS := $(foreach lib, $(LIBS), $(subst /,\,$(TOP)$(ROOT)source/$(lib)/$(ARCH)/$(lib))) else -LINKLIBS := LIBP $(subst /,\,$(HB_LIB_COMPILE)) $(foreach lib, $(LIBS), LIB $(lib)) +LINKLIBS := $(foreach lib, $(LIBS), $(subst /,\,$(HB_LIB_COMPILE)/$(lib))) endif LD_RULE = $(link_exe_file) @@ -60,3 +65,5 @@ ARFLAGS = AR_RULE = $(create_library) include $(TOP)$(ROOT)config/rules.cf + +HB := $(subst /,\\,$(HB)) diff --git a/harbour/config/global.cf b/harbour/config/global.cf index 80dd3fe63c..d364b18d4b 100644 --- a/harbour/config/global.cf +++ b/harbour/config/global.cf @@ -5,12 +5,6 @@ GRANDP = ../../ ARCH := $(HB_ARCHITECTURE)/$(HB_COMPILER) -include $(TOP)$(ROOT)config/$(ARCH).cf - -# -# How to run Harbour. -# - ifeq ($(HB_BIN_COMPILE),) HB_BIN_COMPILE := $(TOP)$(ROOT)source/compiler/$(ARCH) endif @@ -20,14 +14,7 @@ HB_INC_COMPILE := $(TOP)$(ROOT)include endif ifeq ($(HB_LIB_COMPILE),) -HB_LIB_COMPILE := +HB_LIB_COMPILE := endif -HB := $(notdir $(HB_BIN_COMPILE)) -ifneq ($(HB),) -# there is no slash at the end -HB := $(HB_BIN_COMPILE)/ -endif -HB := $(HB)harbour$(EXE_EXT) - -HB_FLAGS = -n -q -I$(TOP) -I$(HB_INC_COMPILE) +include $(TOP)$(ROOT)config/$(ARCH).cf diff --git a/harbour/config/rules.cf b/harbour/config/rules.cf index f7d79ca4b4..d371b79880 100644 --- a/harbour/config/rules.cf +++ b/harbour/config/rules.cf @@ -10,6 +10,9 @@ YACC_FLAGS = -d LEX = flex LEX_FLAGS = -i -8 +# +# How to run Harbour. +# HB := $(notdir $(HB_BIN_COMPILE)) ifneq ($(HB),) # there is no slash at the end diff --git a/harbour/doc/codebloc.txt b/harbour/doc/codebloc.txt index 7250f37b42..b5ad77ac47 100644 --- a/harbour/doc/codebloc.txt +++ b/harbour/doc/codebloc.txt @@ -40,6 +40,8 @@ will be accessed from an outside of a function where it is created. Incompatbility with the Clipper. + +1) Detached locals passed by reference There is a little difference between the handling of variables passed by the reference in a codeblock. The following code explains it (thanks to David G. Holm) @@ -72,3 +74,34 @@ From Main: 42 In Harbour it produces (it is the correct output, IMHO) From MakeBlock: 42 From Main: 42 + +2) Scope of undeclared variables + Consider the following code: + +PROCEDURE MAIN() +LOCAL cb + cb :=Detach() + ? EVAL( cb, 10 ) + +RETURN + +FUNCTION Detach() +LOCAL b:={|x| x+a} +LOCAL a:=0 +RETURN b + + In Clipper the 'a' variable in a codeblock has the *local* scope however in +Harbour the 'a' variable has the *private* scope. As a result, in Clipper +this code will print 10 and in Harbour it will raise 'argument error' in +'+' operation. + This will be true also when the 'a' variable will be declared as PRIVATE + +PROCEDURE MAIN() +LOCAL cb +PRIVATE a + cb :=Detach() + ? EVAL( cb, 10) +RETURN + +The above code also prints 10 in Clipper (even if compiled with -a or -v +switches) diff --git a/harbour/source/compiler/harbour.y b/harbour/source/compiler/harbour.y index 65c24fdd56..84d1886bc4 100644 --- a/harbour/source/compiler/harbour.y +++ b/harbour/source/compiler/harbour.y @@ -1040,8 +1040,8 @@ WhileStatements : Statement | WhileStatements Statement { Line(); } ; -EndWhile : END - | ENDDO +EndWhile : END + | ENDDO ; ForNext : FOR IDENTIFIER ForAssign Expression { PopId( $2 ); $$ = functions.pLast->lPCodePos; ++_wForCounter; LoopStart(); } @@ -1084,10 +1084,10 @@ RecoverSeq : /* no recover */ | RecoverUsing Crlf Statements ; -RecoverEmpty : RECOVER +RecoverEmpty : RECOVER ; -RecoverUsing : RECOVER USING IDENTIFIER +RecoverUsing : RECOVER USING IDENTIFIER ; DoProc : DO IDENTIFIER { PushSymbol( $2, 1 ); PushNil(); Do( 0 ); } @@ -2136,7 +2136,7 @@ void GenCCode( char *szFileName, char *szName ) /* generates the C languag } /* fprintf( yyc, " };\n\n" ); */ fprintf( yyc, "\nHB_INIT_SYMBOLS_END( %s__InitSymbols );\n", symbols.pFirst->szName ); - fprintf( yyc, "#if ! defined(__GNUC__)\n#pragma startup %s__InitSymbols\n#endif\n", symbols.pFirst->szName ); + fprintf( yyc, "#if ! defined(__GNUC__)\n#pragma startup %s__InitSymbols\n#endif\n\n\n", symbols.pFirst->szName ); /* Generate functions data */ @@ -3254,7 +3254,7 @@ void LineBody( void ) /* generates the pcode with the currently compiled source GenError( _szCErrors, 'E', ERR_OUTSIDE, NULL, NULL ); } } - + functions.pLast->bFlags |= FUN_STATEMENTS; if( _iLineNumbers ) GenPCode3( HB_P_LINE, LOBYTE( iLine ), HIBYTE( iLine ) ); @@ -3366,7 +3366,10 @@ void PopId( char * szVarName ) /* generates the pcode to pop a value from the vi { iVar = GetStaticVarPos( szVarName ); if( iVar ) + { GenPCode3( HB_P_POPSTATIC, LOBYTE( iVar ), HIBYTE( iVar ) ); + functions.pLast->bFlags |= FUN_USES_STATICS; + } else { MemvarPCode( HB_P_POPMEMVAR, szVarName ); @@ -3444,7 +3447,10 @@ void PushId( char * szVarName ) /* generates the pcode to push a variable value { iVar = GetStaticVarPos( szVarName ); if( iVar ) + { GenPCode3( HB_P_PUSHSTATIC, LOBYTE( iVar ), HIBYTE( iVar ) ); + functions.pLast->bFlags |= FUN_USES_STATICS; + } else { MemvarPCode( HB_P_PUSHMEMVAR, szVarName ); @@ -3483,7 +3489,10 @@ void PushIdByRef( char * szVarName ) /* generates the pcode to push a variable b { iVar = GetStaticVarPos( szVarName ); if( iVar ) + { GenPCode3( HB_P_PUSHSTATICREF, LOBYTE( iVar ), HIBYTE( iVar ) ); + functions.pLast->bFlags |= FUN_USES_STATICS; + } else { MemvarPCode( HB_P_PUSHMEMVARREF, szVarName ); diff --git a/harbour/tests/broken/statics1.prg b/harbour/tests/working/statics1.prg similarity index 100% rename from harbour/tests/broken/statics1.prg rename to harbour/tests/working/statics1.prg diff --git a/harbour/tests/broken/statics2.prg b/harbour/tests/working/statics2.prg similarity index 91% rename from harbour/tests/broken/statics2.prg rename to harbour/tests/working/statics2.prg index 967ac30387..166537ac79 100644 --- a/harbour/tests/broken/statics2.prg +++ b/harbour/tests/working/statics2.prg @@ -19,6 +19,7 @@ function Test() uB := "b" QOut( ' uA := "a"' ) QOut( ' uB := "b"' ) + QOut( " uA, uB =>", uA, ",", uB ) QOut( "" ) return nil