From 25f44aa07986716aa40b5779efc8c168fa0f10ca Mon Sep 17 00:00:00 2001 From: John Richards Date: Sun, 10 Oct 2021 00:40:39 -0400 Subject: [PATCH] Adds support for CONTAINS_OP opcode Mentioned in: - #190 - #191 - #195 --- ASTree.cpp | 10 ++++++++++ tests/compiled/contains_op.3.9.pyc | Bin 0 -> 166 bytes tests/input/contains_op.py | 8 ++++++++ tests/tokenized/contains_op.txt | 9 +++++++++ 4 files changed, 27 insertions(+) create mode 100644 tests/compiled/contains_op.3.9.pyc create mode 100644 tests/input/contains_op.py create mode 100644 tests/tokenized/contains_op.txt diff --git a/ASTree.cpp b/ASTree.cpp index a0c35939f..a04852c97 100644 --- a/ASTree.cpp +++ b/ASTree.cpp @@ -620,6 +620,16 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) stack.push(new ASTCompare(left, right, operand)); } break; + case Pyc::CONTAINS_OP_A: + { + PycRef right = stack.top(); + stack.pop(); + PycRef left = stack.top(); + stack.pop(); + // The operand will be 0 for 'in' and 1 for 'not in'. + stack.push(new ASTCompare(left, right, operand ? ASTCompare::CMP_NOT_IN : ASTCompare::CMP_IN)); + } + break; case Pyc::DELETE_ATTR_A: { PycRef name = stack.top(); diff --git a/tests/compiled/contains_op.3.9.pyc b/tests/compiled/contains_op.3.9.pyc new file mode 100644 index 0000000000000000000000000000000000000000..78b9c1811cd6b46e3dc4562022caa41b50f1d2e4 GIT binary patch literal 166 zcmYe~<>g`kf}-4{L^mM)7{oyaOhAqU5Em-|i4=w?hIED$#zl-#jHwK%jAaZ(B4C=a zNG63Tm_d{ICCD^Q<|0NQ^-=^x$N>pIO{QCniMJS&Rx%W^0r_C!7hiIIUP)qRUU7VW gfnGu7Ee@O9{FKt1R6CI7Vh$j|!pOnI!OX!30J1_JhyVZp literal 0 HcmV?d00001 diff --git a/tests/input/contains_op.py b/tests/input/contains_op.py new file mode 100644 index 000000000..c4b207abe --- /dev/null +++ b/tests/input/contains_op.py @@ -0,0 +1,8 @@ +a = 10 +b = [10, 20, 30] + +if a in b: + pass + +if a not in b: + pass diff --git a/tests/tokenized/contains_op.txt b/tests/tokenized/contains_op.txt new file mode 100644 index 000000000..f33e0931f --- /dev/null +++ b/tests/tokenized/contains_op.txt @@ -0,0 +1,9 @@ +a = 10 +b = [ 10 , 20 , 30 ] +if a in b : + +pass + +if a not in b : + +pass