From ce6081dbbd588fb111754f3c2c1c93d2421c6ee6 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Tue, 8 Jun 2021 12:58:09 +0200 Subject: 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 --- lexer.h | 28 ++++++++++++++-------------- vm.c | 3 ++- vm.h | 30 ++++++++++++++++-------------- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/lexer.h b/lexer.h index 9f26beb..e1a30ed 100644 --- a/lexer.h +++ b/lexer.h @@ -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, diff --git a/vm.c b/vm.c index 8a503a0..1dfeba4 100644 --- a/vm.c +++ b/vm.c @@ -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)) { diff --git a/vm.h b/vm.h index c0d81d9..4e8d428 100644 --- a/vm.h +++ b/vm.h @@ -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) \ -- cgit v1.2.3