Browse Source

Removing unnecessary operators (eq, ne). Some special strings comparison should be implemented as a function like strcmp().

pull/8/head
Rafal Kupiec 3 years ago
parent
commit
f212588ab1
Signed by: belliash GPG Key ID: 4E829243E0CFE6B4
4 changed files with 1 additions and 74 deletions
  1. +1
    -3
      lex.c
  2. +0
    -2
      parse.c
  3. +0
    -6
      ph7int.h
  4. +0
    -63
      vm.c

+ 1
- 3
lex.c View File

@ -84,7 +84,7 @@ static sxi32 TokenizePHP(SyStream *pStream,SyToken *pToken,void *pUserData,void
nKeyword = KeywordCode(pStr->zString,(int)pStr->nByte);
if( nKeyword != PH7_TK_ID ){
if( nKeyword &
(PH7_TKWRD_NEW|PH7_TKWRD_CLONE|PH7_TKWRD_AND|PH7_TKWRD_XOR|PH7_TKWRD_OR|PH7_TKWRD_INSTANCEOF|PH7_TKWRD_SEQ|PH7_TKWRD_SNE) ){
(PH7_TKWRD_NEW|PH7_TKWRD_CLONE|PH7_TKWRD_AND|PH7_TKWRD_XOR|PH7_TKWRD_OR|PH7_TKWRD_INSTANCEOF) ){
/* Alpha stream operators [i.e: new,clone,and,instanceof,eq,ne,or,xor],save the operator instance for later processing */
pToken->pUserData = (void *)PH7_ExprExtractOperator(pStr,0);
/* Mark as an operator */
@ -564,8 +564,6 @@ static sxu32 KeywordCode(const char *z, int n){
{"int", PH7_TKWRD_INT},
{"require_once", PH7_TKWRD_REQONCE},
{"require", PH7_TKWRD_REQUIRE},
{"eq", PH7_TKWRD_SEQ},
{"ne", PH7_TKWRD_SNE},
{"enddeclare", PH7_TKWRD_ENDDEC},
{"declare", PH7_TKWRD_DECLARE},
{"return", PH7_TKWRD_RETURN},


+ 0
- 2
parse.c View File

@ -205,8 +205,6 @@ static const ph7_expr_op aOpTable[] = {
/* Precedence 11,non-associative */
{ {"==",sizeof(char)*2}, EXPR_OP_EQ, 11, EXPR_OP_NON_ASSOC, PH7_OP_EQ},
{ {"!=",sizeof(char)*2}, EXPR_OP_NE, 11, EXPR_OP_NON_ASSOC, PH7_OP_NEQ},
{ {"eq",sizeof(char)*2}, EXPR_OP_SEQ, 11, EXPR_OP_NON_ASSOC, PH7_OP_SEQ}, /* IMP-0137-EQ: Symisc eXtension */
{ {"ne",sizeof(char)*2}, EXPR_OP_SNE, 11, EXPR_OP_NON_ASSOC, PH7_OP_SNE}, /* IMP-0138-NE: Symisc eXtension */
{ {"===",sizeof(char)*3}, EXPR_OP_TEQ, 11, EXPR_OP_NON_ASSOC, PH7_OP_TEQ},
{ {"!==",sizeof(char)*3}, EXPR_OP_TNE, 11, EXPR_OP_NON_ASSOC, PH7_OP_TNE},
/* Precedence 12,left-associative */


+ 0
- 6
ph7int.h View File

@ -1471,8 +1471,6 @@ enum ph7_vm_op {
PH7_OP_CVT_NUMC, /* Numeric (integer,real or both) type cast */
PH7_OP_INCR, /* Increment ++ */
PH7_OP_DECR, /* Decrement -- */
PH7_OP_SEQ, /* 'eq' String equal: Strict string comparison */
PH7_OP_SNE, /* 'ne' String not equal: Strict string comparison */
PH7_OP_NEW, /* new */
PH7_OP_CLONE, /* clone */
PH7_OP_ADD_STORE, /* Add and store '+=' */
@ -1539,8 +1537,6 @@ enum ph7_expr_id {
EXPR_OP_NE, /* Not equal != <> */
EXPR_OP_TEQ, /* Type equal === */
EXPR_OP_TNE, /* Type not equal !== */
EXPR_OP_SEQ, /* String equal 'eq' */
EXPR_OP_SNE, /* String not equal 'ne' */
EXPR_OP_BAND, /* Biwise and '&' */
EXPR_OP_REF, /* Reference operator '&' */
EXPR_OP_XOR, /* bitwise xor '^' */
@ -1674,8 +1670,6 @@ enum ph7_expr_id {
#define PH7_TKWRD_FLOAT 0x20000 /* float: MUST BE A POWER OF TWO */
#define PH7_TKWRD_STRING 0x40000 /* string: MUST BE A POWER OF TWO */
#define PH7_TKWRD_OBJECT 0x80000 /* object: MUST BE A POWER OF TWO */
#define PH7_TKWRD_SEQ 0x100000 /* String string comparison operator: 'eq' equal MUST BE A POWER OF TWO */
#define PH7_TKWRD_SNE 0x200000 /* String string comparison operator: 'ne' not equal MUST BE A POWER OF TWO */
/* JSON encoding/decoding related definition */
enum json_err_code{
JSON_ERROR_NONE = 0, /* No error has occurred. */


+ 0
- 63
vm.c View File

@ -4299,67 +4299,6 @@ case PH7_OP_GE: {
}
break;
}
/* OP_SEQ P1 P2 *
* Strict string comparison.
* Pop the top two elements from the stack. If they are equal (pure text comparison)
* then jump to instruction P2. Otherwise, continue to the next instruction.
* If either operand is NULL then the comparison result is FALSE.
* The SyMemcmp() routine is used for the comparison. For a numeric comparison
* use PH7_OP_EQ.
* If P2 is zero, do not jump.Instead, push a boolean 1 (TRUE) onto the
* stack if the jump would have been taken, or a 0 (FALSE) if not.
*/
/* OP_SNE P1 P2 *
* Strict string comparison.
* Pop the top two elements from the stack. If they are not equal (pure text comparison)
* then jump to instruction P2. Otherwise, continue to the next instruction.
* If either operand is NULL then the comparison result is FALSE.
* The SyMemcmp() routine is used for the comparison. For a numeric comparison
* use PH7_OP_EQ.
* If P2 is zero, do not jump.Instead, push a boolean 1 (TRUE) onto the
* stack if the jump would have been taken, or a 0 (FALSE) if not.
*/
case PH7_OP_SEQ:
case PH7_OP_SNE: {
ph7_value *pNos = &pTos[-1];
SyString s1,s2;
/* Perform the comparison and act accordingly */
#ifdef UNTRUST
if( pNos < pStack ){
goto Abort;
}
#endif
/* Force a string cast */
if((pTos->iFlags & MEMOBJ_STRING) == 0 ){
PH7_MemObjToString(pTos);
}
if((pNos->iFlags & MEMOBJ_STRING) == 0 ){
PH7_MemObjToString(pNos);
}
SyStringInitFromBuf(&s1,SyBlobData(&pNos->sBlob),SyBlobLength(&pNos->sBlob));
SyStringInitFromBuf(&s2,SyBlobData(&pTos->sBlob),SyBlobLength(&pTos->sBlob));
rc = SyStringCmp(&s1,&s2,SyMemcmp);
if( pInstr->iOp == PH7_OP_NEQ ){
rc = rc != 0;
}else{
rc = rc == 0;
}
VmPopOperand(&pTos,1);
if( !pInstr->iP2 ){
/* Push comparison result without taking the jump */
PH7_MemObjRelease(pTos);
pTos->x.iVal = rc;
/* Invalidate any prior representation */
MemObjSetType(pTos,MEMOBJ_BOOL);
}else{
if( rc ){
/* Jump to the desired location */
pc = pInstr->iP2 - 1;
VmPopOperand(&pTos,1);
}
}
break;
}
/*
* OP_LOAD_REF * * *
* Push the index of a referenced object on the stack.
@ -5932,8 +5871,6 @@ static const char * VmInstrToString(sxi32 nOp)
case PH7_OP_CVT_NUMC: zOp = "CVT_NUMC "; break;
case PH7_OP_INCR: zOp = "INCR "; break;
case PH7_OP_DECR: zOp = "DECR "; break;
case PH7_OP_SEQ: zOp = "SEQ "; break;
case PH7_OP_SNE: zOp = "SNE "; break;
case PH7_OP_NEW: zOp = "NEW "; break;
case PH7_OP_CLONE: zOp = "CLONE "; break;
case PH7_OP_ADD_STORE: zOp = "ADD_STORE "; break;


Loading…
Cancel
Save