diff options
author | Jo-Philipp Wich <jo@mein.io> | 2021-06-08 12:58:09 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2021-06-08 13:54:50 +0200 |
commit | ce6081dbbd588fb111754f3c2c1c93d2421c6ee6 (patch) | |
tree | 30d469066e6053128cc60dbae0b6160131d4518a | |
parent | a363e9c5e848ad21908b66d59433ab07dffbc7f1 (diff) |
lexer, vm: reorder token and instruction numbers
Ensure that relational operators in the lexer token and vm instruction
lists are both ordered in the same way according to the general operator
precedence of the grammar.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r-- | lexer.h | 28 | ||||
-rw-r--r-- | vm.c | 3 | ||||
-rw-r--r-- | vm.h | 30 |
3 files changed, 32 insertions, 29 deletions
@@ -29,17 +29,17 @@ typedef enum { TK_IF, TK_ELSE, TK_COMMA, - TK_ASBAND, - TK_ASBXOR, - TK_ASBOR, - TK_ASLEFT, - TK_ASRIGHT, + TK_ASSIGN, + TK_ASADD, + TK_ASSUB, TK_ASMUL, TK_ASDIV, TK_ASMOD, - TK_ASADD, - TK_ASSUB, - TK_ASSIGN, + TK_ASLEFT, + TK_ASRIGHT, + TK_ASBAND, + TK_ASBXOR, + TK_ASBOR, TK_QMARK, TK_COLON, TK_OR, @@ -47,10 +47,10 @@ typedef enum { TK_BOR, TK_BXOR, TK_BAND, - TK_EQ, - TK_NE, TK_EQS, TK_NES, + TK_EQ, + TK_NE, TK_LT, TK_LE, TK_GT, @@ -67,13 +67,15 @@ typedef enum { TK_COMPL, TK_INC, TK_DEC, - TK_LPAREN, + TK_DOT, TK_LBRACK, + TK_RBRACK, + TK_LPAREN, + TK_RPAREN, TK_TEXT, TK_LBRACE, TK_RBRACE, TK_SCOL, - TK_RPAREN, TK_ENDIF, TK_ELIF, TK_WHILE, @@ -94,8 +96,6 @@ typedef enum { TK_CONTINUE, TK_LOCAL, TK_ARROW, - TK_DOT, - TK_RBRACK, TK_TRUE, TK_FALSE, TK_NUMBER, @@ -1230,7 +1230,8 @@ uc_vm_value_arith(uc_vm *vm, enum insn_type operation, uc_value_t *value, uc_val int64_t n1, n2; double d1, d2; - if (operation > I_MOD) + if (operation == I_LSHIFT || operation == I_RSHIFT || + operation == I_BAND || operation == I_BXOR || operation == I_BOR) return uc_vm_value_bitop(vm, operation, value, operand); if (operation == I_ADD && (ucv_type(value) == UC_STRING || ucv_type(operand) == UC_STRING)) { @@ -56,27 +56,29 @@ __insn(MARR) \ __insn(NOBJ) \ __insn(SOBJ) \ __insn(MOBJ) \ -__insn(PLUS) \ -__insn(MINUS) \ -__insn(ADD) \ -__insn(SUB) \ -__insn(MUL) \ -__insn(DIV) \ -__insn(MOD) \ -__insn(LSHIFT) \ -__insn(RSHIFT) \ -__insn(BAND) \ -__insn(BXOR) \ __insn(BOR) \ -__insn(COMPL) \ -__insn(EQ) \ -__insn(NE) \ +__insn(BXOR) \ +__insn(BAND) \ __insn(EQS) \ __insn(NES) \ +__insn(EQ) \ +__insn(NE) \ __insn(LT) \ +__insn(LE) \ __insn(GT) \ +__insn(GE) \ __insn(IN) \ +__insn(LSHIFT) \ +__insn(RSHIFT) \ +__insn(ADD) \ +__insn(SUB) \ +__insn(MUL) \ +__insn(DIV) \ +__insn(MOD) \ __insn(NOT) \ +__insn(COMPL) \ +__insn(PLUS) \ +__insn(MINUS) \ __insn(JMP) \ __insn(JMPZ) \ __insn(COPY) \ |