From 12fcab20d5c6c988c4f35459437f252ce3315e5c Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 22 Apr 2000 16:38:48 +0000 Subject: [PATCH] 20000422-18:41 GMT+1 Victor Szakats --- harbour/ChangeLog | 23 +++++++++++ harbour/include/hbpcode.h | 2 + harbour/source/compiler/genc.c | 56 +++++++++++++++++++++++++- harbour/source/compiler/harbour.c | 10 ++++- harbour/source/compiler/hbusage.c | 2 +- harbour/source/vm/hvm.c | 67 ++++++++++++++----------------- 6 files changed, 118 insertions(+), 42 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index f522697913..42c78bd9f9 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,26 @@ +20000422-18:41 GMT+1 Victor Szakats + + * include/hbpcode.h + * source/compiler/harbour.c + * source/compiler/genc.c + * source/compiler/hvm.c + + HB_P_PUSHLOCALNEAR and HB_P_POPLOCALNEAR 2 byte pcodes added. + These are used when the referred local is the range of -128-127. + The code is more compact this way, since these pcodes will be used + in the wast majority of cases. + + * source/compiler/hvm.c + - Removed hb_vmPushByte(), replaced with hb_vmPushInteger(). + % Inlined the code for PUSHBYTE, PUSHINT, PUSHZERO, PUSHONE to make it + faster. hb_vmPushZero()/hb_vmPushOne() removed. + + * source/compiler/genc.c + % The static pcode array is now "const" + % It will now put 14 opcodes in each line instead of 8 in -gc0 mode. + + * source/compiler/hbusage.c + ! Typo. + 20000422-16:16 GMT+1 Victor Szakats * source/compiler/genc.c diff --git a/harbour/include/hbpcode.h b/harbour/include/hbpcode.h index ffd7f1c6cf..7036118653 100644 --- a/harbour/include/hbpcode.h +++ b/harbour/include/hbpcode.h @@ -113,6 +113,7 @@ typedef enum HB_P_POPALIASEDVAR, /* pops aliased variable (either a field or a memvar) */ HB_P_POPFIELD, /* pops unaliased field */ HB_P_POPLOCAL, /* pops the contains of the virtual machine stack onto a local variable */ + HB_P_POPLOCALNEAR, /* pops the contains of the virtual machine stack onto a local variable */ HB_P_POPMEMVAR, /* pops the contains of a memvar variable to the virtual machine stack */ HB_P_POPSTATIC, /* pops the contains of the virtual machine stack onto a static variable */ HB_P_POPVARIABLE, /* pops the contains of an undeclared variable from the virtual machine stack */ @@ -125,6 +126,7 @@ typedef enum HB_P_PUSHBYTE, /* places a 1 byte integer number on the virtual machine stack */ HB_P_PUSHINT, /* places an integer number on the virtual machine stack */ HB_P_PUSHLOCAL, /* pushes the contains of a local variable to the virtual machine stack */ + HB_P_PUSHLOCALNEAR, /* pushes the contains of a local variable to the virtual machine stack */ HB_P_PUSHLOCALREF, /* pushes a local variable by reference to the virtual machine stack */ HB_P_PUSHLONG, /* places an integer number on the virtual machine stack */ HB_P_PUSHMEMVAR, /* pushes the contains of a memvar variable to the virtual machine stack */ diff --git a/harbour/source/compiler/genc.c b/harbour/source/compiler/genc.c index e9aaf8b1a1..4868888624 100644 --- a/harbour/source/compiler/genc.c +++ b/harbour/source/compiler/genc.c @@ -189,7 +189,7 @@ void hb_compGenCCode( PHB_FNAME pFileName ) /* generates the C language ou else fprintf( yyc, "HB_FUNC( %s )", pFunc->szName ); - fprintf( yyc, "\n{\n static BYTE pcode[] =\n {\n" ); + fprintf( yyc, "\n{\n static const BYTE pcode[] =\n {\n" ); if( hb_comp_iGenCOutput == HB_COMPGENC_COMPACT ) hb_compGenCCompact( pFunc, yyc ); @@ -728,6 +728,32 @@ static void hb_compGenCReadable( PFUNCTION pFunc, FILE * yyc ) lPCodePos += 3; break; + case HB_P_POPLOCALNEAR: + fprintf( yyc, "\tHB_P_POPLOCALNEAR, %i,", + pFunc->pCode[ lPCodePos + 1 ] ); + if( bVerbose ) + { + SHORT wVar = ( SHORT ) pFunc->pCode[ lPCodePos + 1 ]; + /* Variable with negative order are local variables + * referenced in a codeblock -handle it with care + */ + + if( iNestedCodeblock ) + { + /* we are accesing variables within a codeblock */ + /* the names of codeblock variable are lost */ + if( wVar < 0 ) + fprintf( yyc, "\t/* localvar%i */", -wVar ); + else + fprintf( yyc, "\t/* codeblockvar%i */", wVar ); + } + else + fprintf( yyc, "\t/* %s */", hb_compVariableFind( pFunc->pLocals, wVar )->szName ); + } + fprintf( yyc, "\n" ); + lPCodePos += 2; + break; + case HB_P_POPMEMVAR: fprintf( yyc, "\tHB_P_POPMEMVAR, %i, %i,", pFunc->pCode[ lPCodePos + 1 ], @@ -915,6 +941,32 @@ static void hb_compGenCReadable( PFUNCTION pFunc, FILE * yyc ) lPCodePos += 3; break; + case HB_P_PUSHLOCALNEAR: + fprintf( yyc, "\tHB_P_PUSHLOCALNEAR, %i,", + pFunc->pCode[ lPCodePos + 1 ] ); + if( bVerbose ) + { + SHORT wVar = ( SHORT ) pFunc->pCode[ lPCodePos + 1 ]; + /* Variable with negative order are local variables + * referenced in a codeblock -handle it with care + */ + + if( iNestedCodeblock ) + { + /* we are accesing variables within a codeblock */ + /* the names of codeblock variable are lost */ + if( wVar < 0 ) + fprintf( yyc, "\t/* localvar%i */", -wVar ); + else + fprintf( yyc, "\t/* codeblockvar%i */", wVar ); + } + else + fprintf( yyc, "\t/* %s */", hb_compVariableFind( pFunc->pLocals, wVar )->szName ); + } + fprintf( yyc, "\n" ); + lPCodePos += 2; + break; + case HB_P_PUSHLOCALREF: fprintf( yyc, "\tHB_P_PUSHLOCALREF, %i, %i,", pFunc->pCode[ lPCodePos + 1 ], @@ -1182,7 +1234,7 @@ static void hb_compGenCCompact( PFUNCTION pFunc, FILE * yyc ) if( nChar > 1 ) fprintf( yyc, ", " ); - if( nChar == 9 ) + if( nChar == 15 ) { fprintf( yyc, "\n\t" ); nChar = 1; diff --git a/harbour/source/compiler/harbour.c b/harbour/source/compiler/harbour.c index 150420ceb5..97735dc337 100644 --- a/harbour/source/compiler/harbour.c +++ b/harbour/source/compiler/harbour.c @@ -1822,7 +1822,10 @@ void hb_compGenPopVar( char * szVarName ) /* generates the pcode to pop a value { /* local variable */ - hb_compGenPCode3( HB_P_POPLOCAL, HB_LOBYTE( iVar ), HB_HIBYTE( iVar ) ); + if( iVar >= -128 && iVar <= 127 ) + hb_compGenPCode2( HB_P_POPLOCALNEAR, iVar ); + else + hb_compGenPCode3( HB_P_POPLOCAL, HB_LOBYTE( iVar ), HB_HIBYTE( iVar ) ); } else { @@ -1975,7 +1978,10 @@ void hb_compGenPushVar( char * szVarName ) { /* local variable */ - hb_compGenPCode3( HB_P_PUSHLOCAL, HB_LOBYTE( iVar ), HB_HIBYTE( iVar ) ); + if( iVar >= -128 && iVar <= 127 ) + hb_compGenPCode2( HB_P_PUSHLOCALNEAR, iVar ); + else + hb_compGenPCode3( HB_P_PUSHLOCAL, HB_LOBYTE( iVar ), HB_HIBYTE( iVar ) ); } else { diff --git a/harbour/source/compiler/hbusage.c b/harbour/source/compiler/hbusage.c index f7ec2331ae..cb2abebd85 100644 --- a/harbour/source/compiler/hbusage.c +++ b/harbour/source/compiler/hbusage.c @@ -55,7 +55,7 @@ void hb_compPrintUsage( char * szSelf ) "\n %cgh output type: Harbour Portable Object (.hrb)", "\n %cgj output type: Java source (.java)", "\n %ci add #include file search path", - "\n %cj[0|1] Jump Optimizer 0=disabled 1=enabled (default)", + "\n %cj[0|1] Jump optimizer 0=disabled 1=enabled (default)", "\n %cl suppress line number information", /* TODO: "\n %cm compile module only", */ "\n %cn no implicit starting procedure", diff --git a/harbour/source/vm/hvm.c b/harbour/source/vm/hvm.c index 7fa12d7d2f..16e40d1c50 100644 --- a/harbour/source/vm/hvm.c +++ b/harbour/source/vm/hvm.c @@ -140,9 +140,6 @@ static void hb_vmPushAlias( void ); /* pushes the current workarea static void hb_vmPushAliasedField( PHB_SYMB ); /* pushes an aliased field on the eval stack */ static void hb_vmPushAliasedVar( PHB_SYMB ); /* pushes an aliased variable on the eval stack */ static void hb_vmPushBlock( BYTE * pCode, PHB_SYMB pSymbols ); /* creates a codeblock */ -static void hb_vmPushOne( void ); /* pushes a 1 onto the stack */ -static void hb_vmPushZero( void ); /* pushes a 0 onto the stack */ -static void hb_vmPushByte( BYTE bNumber ); /* pushes a 1 byte integer number onto the stack */ static void hb_vmPushDoubleConst( double dNumber, int iWidth, int iDec ); /* Pushes a double constant (pcode) */ static void hb_vmPushMacroBlock( BYTE * pCode, PHB_SYMB pSymbols ); /* creates a macro-compiled codeblock */ static void hb_vmPushLocal( SHORT iLocal ); /* pushes the containts of a local onto the stack */ @@ -859,12 +856,20 @@ void hb_vmExecute( BYTE * pCode, PHB_SYMB pSymbols ) break; case HB_P_ONE: - hb_vmPushOne(); + hb_stack.pPos->type = HB_IT_INTEGER; + hb_stack.pPos->item.asInteger.value = 1; + hb_stack.pPos->item.asInteger.length = 10; + hb_stackPush(); + HB_TRACE(HB_TR_INFO, ("(hb_vmPushOne)")); w++; break; case HB_P_ZERO: - hb_vmPushZero(); + hb_stack.pPos->type = HB_IT_INTEGER; + hb_stack.pPos->item.asInteger.value = 0; + hb_stack.pPos->item.asInteger.length = 10; + hb_stackPush(); + HB_TRACE(HB_TR_INFO, ("(hb_vmPushZero)")); w++; break; @@ -876,12 +881,20 @@ void hb_vmExecute( BYTE * pCode, PHB_SYMB pSymbols ) break; case HB_P_PUSHBYTE: - hb_vmPushByte( ( BYTE ) pCode[ w + 1 ] ); + hb_stack.pPos->type = HB_IT_INTEGER; + hb_stack.pPos->item.asInteger.value = ( int ) pCode[ w + 1 ]; + hb_stack.pPos->item.asInteger.length = 10; + hb_stackPush(); + HB_TRACE(HB_TR_INFO, ("(hb_vmPushInteger)")); w += 2; break; case HB_P_PUSHINT: - hb_vmPushInteger( pCode[ w + 1 ] + ( pCode[ w + 2 ] * 256 ) ); + hb_stack.pPos->type = HB_IT_INTEGER; + hb_stack.pPos->item.asInteger.value = pCode[ w + 1 ] + ( pCode[ w + 2 ] * 256 ); + hb_stack.pPos->item.asInteger.length = 10; + hb_stackPush(); + HB_TRACE(HB_TR_INFO, ("(hb_vmPushInteger)")); w += 3; break; @@ -957,6 +970,11 @@ void hb_vmExecute( BYTE * pCode, PHB_SYMB pSymbols ) w += 3; break; + case HB_P_PUSHLOCALNEAR: + hb_vmPushLocal( ( SHORT ) pCode[ w + 1 ] ); + w += 2; + break; + case HB_P_PUSHLOCALREF: hb_vmPushLocalByRef( pCode[ w + 1 ] + ( pCode[ w + 2 ] * 256 ) ); w += 3; @@ -1046,6 +1064,11 @@ void hb_vmExecute( BYTE * pCode, PHB_SYMB pSymbols ) w += 3; break; + case HB_P_POPLOCALNEAR: + hb_vmPopLocal( ( SHORT ) pCode[ w + 1 ] ); + w += 2; + break; + case HB_P_POPSTATIC: hb_vmPopStatic( pCode[ w + 1 ] + ( pCode[ w + 2 ] * 256 ) ); w += 3; @@ -2958,36 +2981,6 @@ void hb_vmPushNumber( double dNumber, int iDec ) hb_vmPushDouble( dNumber, hb_set.HB_SET_DECIMALS ); } -static void hb_vmPushOne( void ) -{ - HB_TRACE(HB_TR_DEBUG, ("hb_vmPushOne()")); - - hb_stack.pPos->type = HB_IT_INTEGER; - hb_stack.pPos->item.asInteger.value = ( int ) 1; - hb_stack.pPos->item.asInteger.length = 10; - hb_stackPush(); -} - -static void hb_vmPushZero( void ) -{ - HB_TRACE(HB_TR_DEBUG, ("hb_vmPushZero()")); - - hb_stack.pPos->type = HB_IT_INTEGER; - hb_stack.pPos->item.asInteger.value = ( int ) 0; - hb_stack.pPos->item.asInteger.length = 10; - hb_stackPush(); -} - -static void hb_vmPushByte( BYTE bNumber ) -{ - HB_TRACE(HB_TR_DEBUG, ("hb_vmPushByte(%i)", bNumber)); - - hb_stack.pPos->type = HB_IT_INTEGER; - hb_stack.pPos->item.asInteger.value = ( int ) bNumber; - hb_stack.pPos->item.asInteger.length = 10; - hb_stackPush(); -} - void hb_vmPushInteger( int iNumber ) { HB_TRACE(HB_TR_DEBUG, ("hb_vmPushInteger(%d)", iNumber));