diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 35de826b72..8423a6ce86 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,7 +1,22 @@ +20000413-01:30 GMT-8 Ron Pinkas + + * source/include/hbpcode.h + + Added HB_P_JUMPFAR, HB_P_JUMPFARFALSE, and HB_P_JUMPFARTRUE + + * source/compiler/hvm.c + + Added support for HB_P_JUMPFAR, HB_P_JUMPFARFALSE, and HB_P_JUMPFARTRUE to support longer than 2^15 jumps. + + * source/compiler/harbour.c + * Enhanced hb_compGenJump(), hb_compGenJumpFalse(), hb_compGenJumpTrue(), hb_compGenJumpHere() and hb_compGenJumpThere() + to utilize HB_P_JUMPFAR, HB_P_JUMPFARFALSE, and HB_P_JUMPFARTRUE to support longer than 2^15 jumps. + + * source/compiler/genc.c + + Added support for HB_P_JUMPFAR, HB_P_JUMPFARFALSE, and HB_P_JUMPFARTRUE to support longer than 2^15 jumps. + 20000413-04:42 GMT+1 Victor Szakats * source/common/hbtrace.c - ! Fixed a previous optimization attempt, which caused hb_tr_level() to + ! Fixed a previous optimization attempt, which caused hb_tr_level() to reinit itself on every call. (10% speedup for HBTEST /ALL) * makefile.* @@ -12,7 +27,7 @@ * source/vm/extend.c * include/hbapi.h % Experimental HB_EXTEND_API_MACROS macro added, which (if defined) will - convert hb_pcount() and hb_ret*() Extend API function calls into + convert hb_pcount() and hb_ret*() Extend API function calls into Item API calls and direct item accesses. So that it should be faster and also a bit larger (~3K larger Harbour exes for BCC55) @@ -39,7 +54,7 @@ * source/vm/extend.c * contrib/rdd_ads/ads1.c * source/rdd/dbf1.c - * Day/Month/Year parameters reordered to Year/Month/Day to match + * Day/Month/Year parameters reordered to Year/Month/Day to match international conventions. (hb_retd(), hb_dateDOW(), hb_dateEncode(), hb_dateDecode(), hb_dateStrPut(), hb_dateStrGet()) @@ -97,7 +112,7 @@ *doc/en/rddord.txt +Doc for INDEXEXT() and INDEXKEY() *doc/en/rddmisc.txt - *Changed doc for lastrec function() + *Changed doc for lastrec function() 20000412-01:17 GMT+1 Victor Szakats @@ -125,7 +140,7 @@ renamed. One strcpy() removed. Buffer overflow checked. It should be much faster now. ! hb_gtGetColorStr() fixed so that it will now put both + and * to the - first half of the colorspec. This is ugly but that's what CA-Cl*pper + first half of the colorspec. This is ugly but that's what CA-Cl*pper does. 20000411-21:08 GMT+1 Victor Szakats diff --git a/harbour/include/hbpcode.h b/harbour/include/hbpcode.h index e37d0e9796..062cff8289 100644 --- a/harbour/include/hbpcode.h +++ b/harbour/include/hbpcode.h @@ -62,8 +62,11 @@ typedef enum HB_P_INC, /* increments the latest value on the virtual machine stack */ HB_P_INSTRING, /* checks if the second latest value on the stack is a substring of the latest one */ HB_P_JUMP, /* jumps to a relative offset */ + HB_P_JUMPFAR, /* jumps to a relative offset */ HB_P_JUMPFALSE, /* checks a logic expression of the stack and jumps to a relative offset */ + HB_P_JUMPFARFALSE, /* checks a logic expression of the stack and jumps to a relative offset */ HB_P_JUMPTRUE, /* checks a logic expression of the stack and jumps to a relative offset */ + HB_P_JUMPFARTRUE, /* checks a logic expression of the stack and jumps to a relative offset */ HB_P_LESSEQUAL, /* checks if the second latest value on the stack is less equal that the latest one, leaves the result only */ HB_P_LESS, /* checks if the second latest value on the stack is less that the lastest one */ HB_P_LINE, /* currently compiled source code line number */ diff --git a/harbour/source/compiler/genc.c b/harbour/source/compiler/genc.c index 90c22c02e2..278f09a3a7 100644 --- a/harbour/source/compiler/genc.c +++ b/harbour/source/compiler/genc.c @@ -191,9 +191,9 @@ void hb_compGenCCode( PHB_FNAME pFileName ) /* generates the C language ou fprintf( yyc, "HARBOUR hb_INITSTATICS( void )" ); /* NOTE: hb_ intentionally in lower case */ else fprintf( yyc, "HB_FUNC( %s )", pFunc->szName ); - + fprintf( yyc, "\n{\n static BYTE pcode[] =\n {\n" ); - + bEndProcRequired = TRUE; lPCodePos = 0; while( lPCodePos < pFunc->lPCodePos ) @@ -369,6 +369,21 @@ void hb_compGenCCode( PHB_FNAME pFileName ) /* generates the C language ou lPCodePos += 3; break; + case HB_P_JUMPFAR: + /* if( 1 ) ( lPCodePos + 3 ) < pFunc->lPCodePos ) */ + { + SHORT sPos; + sPos = pFunc->pCode[ lPCodePos + 1 ] + pFunc->pCode[ lPCodePos + 2 ] * 256 + pFunc->pCode[ lPCodePos + 3 ] * 65536; + fprintf( yyc, "\tHB_P_JUMPFAR, %i, %i, %i,", + pFunc->pCode[ lPCodePos + 1 ], + pFunc->pCode[ lPCodePos + 2 ], + pFunc->pCode[ lPCodePos + 3 ] ); + if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %i (abs: %05li) */", sPos, lPCodePos + ( sPos ? sPos : 4 ) ); + fprintf( yyc, "\n" ); + } + lPCodePos += 4; + break; + case HB_P_JUMPFALSE: w = pFunc->pCode[ lPCodePos + 1 ] + pFunc->pCode[ lPCodePos + 2 ] * 256; fprintf( yyc, "\tHB_P_JUMPFALSE, %i, %i,", @@ -379,6 +394,18 @@ void hb_compGenCCode( PHB_FNAME pFileName ) /* generates the C language ou lPCodePos += 3; break; + case HB_P_JUMPFARFALSE: + w = pFunc->pCode[ lPCodePos + 1 ] + pFunc->pCode[ lPCodePos + 2 ] * 256 + pFunc->pCode[ lPCodePos + 3 ] * 65536; + fprintf( yyc, "\tHB_P_JUMPFARFALSE, %i, %i, %i,", + pFunc->pCode[ lPCodePos + 1 ], + pFunc->pCode[ lPCodePos + 2 ], + pFunc->pCode[ lPCodePos + 3 ] ); + if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %i (abs: %05li) */", w, lPCodePos + ( w ? w : 4 ) ); + fprintf( yyc, "\n" ); + lPCodePos += 4; + break; + + case HB_P_JUMPTRUE: w = pFunc->pCode[ lPCodePos + 1 ] + pFunc->pCode[ lPCodePos + 2 ] * 256; fprintf( yyc, "\tHB_P_JUMPTRUE, %i, %i,", @@ -389,6 +416,17 @@ void hb_compGenCCode( PHB_FNAME pFileName ) /* generates the C language ou lPCodePos += 3; break; + case HB_P_JUMPFARTRUE: + w = pFunc->pCode[ lPCodePos + 1 ] + pFunc->pCode[ lPCodePos + 2 ] * 256 + pFunc->pCode[ lPCodePos + 3 ] * 65536; + fprintf( yyc, "\tHB_P_JUMPFARTRUE, %i, %i, %i,", + pFunc->pCode[ lPCodePos + 1 ], + pFunc->pCode[ lPCodePos + 2 ], + pFunc->pCode[ lPCodePos + 3 ] ); + if( hb_comp_bGenCVerbose ) fprintf( yyc, "\t/* %i (abs: %05li) */", w, lPCodePos + ( w ? w : 4 ) ); + fprintf( yyc, "\n" ); + lPCodePos += 4; + break; + case HB_P_LESS: fprintf( yyc, "\tHB_P_LESS,\n" ); lPCodePos++; diff --git a/harbour/source/compiler/harbour.c b/harbour/source/compiler/harbour.c index 65ebb0d5a0..bf76587236 100644 --- a/harbour/source/compiler/harbour.c +++ b/harbour/source/compiler/harbour.c @@ -1244,26 +1244,62 @@ USHORT hb_compFunctionGetPos( char * szFunctionName ) /* return 0 if not found o ULONG hb_compGenJump( LONG lOffset ) { - /* TODO: We need a longer offset (longer then two bytes) - */ - if( lOffset < ( LONG ) SHRT_MIN || lOffset > ( LONG ) SHRT_MAX ) + int iBytes; + + /* Just a place holder so it might be a far jump...*/ + if ( lOffset == 0 ) + { + hb_compGenPCode3( HB_P_JUMPFAR, 0, 0 ); + hb_compGenPCode1( 0 ); + iBytes = 3; + } + else if ( lOffset >= SHRT_MIN && lOffset <= SHRT_MAX ) + { + hb_compGenPCode3( HB_P_JUMP, HB_LOBYTE( lOffset ), HB_HIBYTE( lOffset ) ); + iBytes = 2; + } + else if ( lOffset >= (-8388608L) && lOffset <= 8388607L ) + { + hb_compGenPCode3( HB_P_JUMPFAR, HB_LOBYTE( lOffset ), HB_HIBYTE( lOffset ) ); + hb_compGenPCode1( ( BYTE ) ( ( ( USHORT ) ( lOffset ) >> 16 ) & 0xFF ) ); + iBytes = 3; + } + else + { hb_compGenError( hb_comp_szErrors, 'F', HB_COMP_ERR_JUMP_TOO_LONG, NULL, NULL ); + } - hb_compGenPCode3( HB_P_JUMP, HB_LOBYTE( lOffset ), HB_HIBYTE( lOffset ) ); - - return hb_comp_functions.pLast->lPCodePos - 2; + return hb_comp_functions.pLast->lPCodePos - iBytes; } ULONG hb_compGenJumpFalse( LONG lOffset ) { - /* TODO: We need a longer offset (longer then two bytes) - */ - if( lOffset < ( LONG ) SHRT_MIN || lOffset > ( LONG ) SHRT_MAX ) + int iBytes; + + /* Just a place holder so it might be a far jump...*/ + if ( lOffset == 0 ) + { + hb_compGenPCode3( HB_P_JUMPFARFALSE, 0, 0 ); + hb_compGenPCode1( 0 ); + iBytes = 3; + } + else if ( lOffset >= SHRT_MIN && lOffset <= SHRT_MAX ) + { + hb_compGenPCode3( HB_P_JUMPFALSE, HB_LOBYTE( lOffset ), HB_HIBYTE( lOffset ) ); + iBytes = 2; + } + else if ( lOffset >= (-8388608L) && lOffset <= 8388607L ) + { + hb_compGenPCode3( HB_P_JUMPFARFALSE, HB_LOBYTE( lOffset ), HB_HIBYTE( lOffset ) ); + hb_compGenPCode1( ( BYTE ) ( ( ( USHORT ) ( lOffset ) >> 16 ) & 0xFF ) ); + iBytes = 3; + } + else + { hb_compGenError( hb_comp_szErrors, 'F', HB_COMP_ERR_JUMP_TOO_LONG, NULL, NULL ); + } - hb_compGenPCode3( HB_P_JUMPFALSE, HB_LOBYTE( lOffset ), HB_HIBYTE( lOffset ) ); - - return hb_comp_functions.pLast->lPCodePos - 2; + return hb_comp_functions.pLast->lPCodePos - iBytes; } void hb_compGenJumpThere( ULONG ulFrom, ULONG ulTo ) @@ -1271,13 +1307,21 @@ void hb_compGenJumpThere( ULONG ulFrom, ULONG ulTo ) BYTE * pCode = hb_comp_functions.pLast->pCode; LONG lOffset = ulTo - ulFrom + 1; - /* TODO: We need a longer offset (longer then two bytes) - */ - if( lOffset < ( LONG ) SHRT_MIN || lOffset > ( LONG ) SHRT_MAX ) + if ( lOffset >= SHRT_MIN && lOffset <= SHRT_MAX ) + { + pCode[ ( ULONG ) ulFrom ] = HB_LOBYTE( lOffset ); + pCode[ ( ULONG ) ulFrom + 1 ] = HB_HIBYTE( lOffset ); + } + else if ( lOffset >= (-8388608L) && lOffset <= 8388607L ) + { + pCode[ ( ULONG ) ulFrom ] = HB_LOBYTE( lOffset ); + pCode[ ( ULONG ) ulFrom + 1 ] = HB_HIBYTE( lOffset ); + pCode[ ( ULONG ) ulFrom + 2 ] = ( BYTE ) ( ( ( USHORT ) ( lOffset ) >> 16 ) & 0xFF ); + } + else + { hb_compGenError( hb_comp_szErrors, 'F', HB_COMP_ERR_JUMP_TOO_LONG, NULL, NULL ); - - pCode[ ( ULONG ) ulFrom ] = HB_LOBYTE( lOffset ); - pCode[ ( ULONG ) ulFrom + 1 ] = HB_HIBYTE( lOffset ); + } } void hb_compGenJumpHere( ULONG ulOffset ) @@ -1287,13 +1331,32 @@ void hb_compGenJumpHere( ULONG ulOffset ) ULONG hb_compGenJumpTrue( LONG lOffset ) { - /* TODO: We need a longer offset (longer then two bytes) - */ - if( lOffset < ( LONG ) SHRT_MIN || lOffset > ( LONG ) SHRT_MAX ) - hb_compGenError( hb_comp_szErrors, 'F', HB_COMP_ERR_JUMP_TOO_LONG, NULL, NULL ); - hb_compGenPCode3( HB_P_JUMPTRUE, HB_LOBYTE( lOffset ), HB_HIBYTE( lOffset ) ); + int iBytes; - return hb_comp_functions.pLast->lPCodePos - 2; + /* Just a place holder so it might be a far jump...*/ + if ( lOffset == 0 ) + { + hb_compGenPCode3( HB_P_JUMPFARTRUE, 0, 0 ); + hb_compGenPCode1( 0 ); + iBytes = 3; + } + if ( lOffset >= SHRT_MIN && lOffset <= SHRT_MAX ) + { + hb_compGenPCode3( HB_P_JUMPTRUE, HB_LOBYTE( lOffset ), HB_HIBYTE( lOffset ) ); + iBytes = 2; + } + else if ( lOffset >= (-8388608L) && lOffset <= 8388607L ) + { + hb_compGenPCode3( HB_P_JUMPFARTRUE, HB_LOBYTE( lOffset ), HB_HIBYTE( lOffset ) ); + hb_compGenPCode1( ( BYTE ) ( ( ( USHORT ) ( lOffset ) >> 16 ) & 0xFF ) ); + iBytes = 3; + } + else + { + hb_compGenError( hb_comp_szErrors, 'F', HB_COMP_ERR_JUMP_TOO_LONG, NULL, NULL ); + } + + return hb_comp_functions.pLast->lPCodePos - iBytes; } diff --git a/harbour/source/vm/hvm.c b/harbour/source/vm/hvm.c index 7213030555..7a53a0d104 100644 --- a/harbour/source/vm/hvm.c +++ b/harbour/source/vm/hvm.c @@ -708,6 +708,14 @@ void hb_vmExecute( BYTE * pCode, PHB_SYMB pSymbols ) w += 3; break; + case HB_P_JUMPFAR: + uiParams = pCode[ w + 1 ] + ( pCode[ w + 2 ] * 256 ) + ( pCode[ w + 3 ] * 65536 ); + if( uiParams ) + w += uiParams; + else + w += 4; + break; + case HB_P_JUMPFALSE: if( ! hb_vmPopLogical() ) w += pCode[ w + 1 ] + ( pCode[ w + 2 ] * 256 ); @@ -715,6 +723,13 @@ void hb_vmExecute( BYTE * pCode, PHB_SYMB pSymbols ) w += 3; break; + case HB_P_JUMPFARFALSE: + if( ! hb_vmPopLogical() ) + w += pCode[ w + 1 ] + ( pCode[ w + 2 ] * 256 ) + ( pCode[ w + 3 ] * 65536 ); + else + w += 4; + break; + case HB_P_JUMPTRUE: if( hb_vmPopLogical() ) w += pCode[ w + 1 ] + ( pCode[ w + 2 ] * 256 ); @@ -722,6 +737,13 @@ void hb_vmExecute( BYTE * pCode, PHB_SYMB pSymbols ) w += 3; break; + case HB_P_JUMPFARTRUE: + if( hb_vmPopLogical() ) + w += pCode[ w + 1 ] + ( pCode[ w + 2 ] * 256 ) + ( pCode[ w + 3 ] * 65536 ); + else + w += 4; + break; + /* Push */ case HB_P_TRUE: @@ -3811,7 +3833,7 @@ static void hb_vmDoInitFunctions( void ) } /* NOTE: We should make sure that these get linked. - Don't make this function static, because it's not called from + Don't make this function static, because it's not called from this file. */ void hb_vmForceLink( void ) {