From 4eaf6a71179ef079f481c7276adb8dab8b1e8712 Mon Sep 17 00:00:00 2001 From: belliash Date: Thu, 11 Apr 2019 06:25:20 +0200 Subject: [PATCH] AerScript is strict type hinting language, thus OP_TEQ & OP_TNE are not needed here. --- engine/parser.c | 2 -- engine/vm.c | 72 ------------------------------------------- include/ph7int.h | 4 --- tests/luhn_verify.aer | 2 +- 4 files changed, 1 insertion(+), 79 deletions(-) diff --git a/engine/parser.c b/engine/parser.c index ef69bcd..b6e8aac 100644 --- a/engine/parser.c +++ b/engine/parser.c @@ -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}, - { {"===", 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 */ { {"&", sizeof(char)}, EXPR_OP_BAND, 12, EXPR_OP_ASSOC_LEFT, PH7_OP_BAND}, /* Binary operators */ diff --git a/engine/vm.c b/engine/vm.c index e782d6f..1ba3b26 100644 --- a/engine/vm.c +++ b/engine/vm.c @@ -3717,72 +3717,6 @@ static sxi32 VmByteCodeExec( } break; } - /* OP_TEQ P1 P2 * - * - * Pop the top two elements from the stack. If they have the same type and are equal - * then jump to instruction P2. Otherwise, continue to the next instruction. - * 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_TEQ: { - ph7_value *pNos = &pTos[-1]; - /* Perform the comparison and act accordingly */ -#ifdef UNTRUST - if(pNos < pStack) { - goto Abort; - } -#endif - rc = PH7_MemObjCmp(pNos, pTos, TRUE, 0) == 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_TNE P1 P2 * - * - * Pop the top two elements from the stack.If they are not equal an they are not - * of the same type, then jump to instruction P2. Otherwise, continue to the next - * instruction. - * 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_TNE: { - ph7_value *pNos = &pTos[-1]; - /* Perform the comparison and act accordingly */ -#ifdef UNTRUST - if(pNos < pStack) { - goto Abort; - } -#endif - rc = PH7_MemObjCmp(pNos, pTos, TRUE, 0) != 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_LT P1 P2 P3 * * Pop the top two elements from the stack. If the second element (the top of stack) @@ -5499,12 +5433,6 @@ static const char *VmInstrToString(sxi32 nOp) { case PH7_OP_NEQ: zOp = "NEQ"; break; - case PH7_OP_TEQ: - zOp = "TEQ"; - break; - case PH7_OP_TNE: - zOp = "TNE"; - break; case PH7_OP_BAND: zOp = "BITAND"; break; diff --git a/include/ph7int.h b/include/ph7int.h index 269bf8a..0ae77a0 100644 --- a/include/ph7int.h +++ b/include/ph7int.h @@ -1419,8 +1419,6 @@ enum ph7_vm_op { PH7_OP_GE, /* Greater or equal '>=' */ PH7_OP_EQ, /* Equal '==' */ PH7_OP_NEQ, /* Not equal '!=' */ - PH7_OP_TEQ, /* Type equal '===' */ - PH7_OP_TNE, /* Type not equal '!==' */ PH7_OP_BAND, /* Bitwise and '&' */ PH7_OP_BXOR, /* Bitwise xor '^' */ PH7_OP_BOR, /* Bitwise or '|' */ @@ -1498,8 +1496,6 @@ enum ph7_expr_id { EXPR_OP_GE, /* Greater equal */ EXPR_OP_EQ, /* Equal == */ EXPR_OP_NE, /* Not equal != <> */ - EXPR_OP_TEQ, /* Type equal === */ - EXPR_OP_TNE, /* Type not equal !== */ EXPR_OP_BAND, /* Bitwise and '&' */ EXPR_OP_REF, /* Reference operator '&' */ EXPR_OP_XOR, /* bitwise xor '^' */ diff --git a/tests/luhn_verify.aer b/tests/luhn_verify.aer index 9dfe02b..861d927 100644 --- a/tests/luhn_verify.aer +++ b/tests/luhn_verify.aer @@ -19,7 +19,7 @@ class Luhn { for(int $i = 0; $i < $len; $i++) { $sum += $i & 1 ? $revNumber[$i] * 2 : $revNumber[$i]; } - return array_sum(str_split($sum)) % 10 === 0; + return array_sum(str_split($sum)) % 10 == 0; } }