From 588f24c87210436f3551dc5808d773b0331d5c96 Mon Sep 17 00:00:00 2001 From: John Richards Date: Thu, 7 Oct 2021 20:29:18 -0400 Subject: [PATCH] Adds support for IS_OP opcode Mentioned in: - #190 - #191 - #195 --- ASTree.cpp | 11 +++++++++++ tests/compiled/is_op.3.9.pyc | Bin 0 -> 139 bytes tests/input/is_op.py | 9 +++++++++ tests/tokenized/is_op.txt | 9 +++++++++ 4 files changed, 29 insertions(+) create mode 100644 tests/compiled/is_op.3.9.pyc create mode 100644 tests/input/is_op.py create mode 100644 tests/tokenized/is_op.txt diff --git a/ASTree.cpp b/ASTree.cpp index c92480e..d6ee5c6 100644 --- a/ASTree.cpp +++ b/ASTree.cpp @@ -1104,6 +1104,17 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) stack.push(new ASTBinary(left, right, ASTBinary::BIN_IP_MAT_MULTIPLY)); } break; + case Pyc::IS_OP_A: + { + PycRef right = stack.top(); + stack.pop(); + PycRef left = stack.top(); + stack.pop(); + // The operand will be 0 for 'is' and 1 for 'is not'. + // Map those back to the appropriate values in ASTCompare::op_str() + stack.push(new ASTCompare(left, right, operand ? 9 : 8)); + } + break; case Pyc::JUMP_IF_FALSE_A: case Pyc::JUMP_IF_TRUE_A: case Pyc::JUMP_IF_FALSE_OR_POP_A: diff --git a/tests/compiled/is_op.3.9.pyc b/tests/compiled/is_op.3.9.pyc new file mode 100644 index 0000000000000000000000000000000000000000..964fb30d17f91c0fd31b69b47ae5df6056fc1f49 GIT binary patch literal 139 zcmYe~<>g`kf~o!SiMBxcF^Gc +b = 10 +if a is b : + +pass + +if a is not b : + +pass