Skip to content

Commit

Permalink
Adds support for CONTAINS_OP opcode
Browse files Browse the repository at this point in the history
Mentioned in:
- zrax#190
- zrax#191
- zrax#195
  • Loading branch information
dotjrich committed Oct 10, 2021
1 parent 81f3e5f commit 25f44aa
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ASTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,16 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
stack.push(new ASTCompare(left, right, operand));
}
break;
case Pyc::CONTAINS_OP_A:
{
PycRef<ASTNode> right = stack.top();
stack.pop();
PycRef<ASTNode> 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<ASTNode> name = stack.top();
Expand Down
Binary file added tests/compiled/contains_op.3.9.pyc
Binary file not shown.
8 changes: 8 additions & 0 deletions tests/input/contains_op.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
a = 10
b = [10, 20, 30]

if a in b:
pass

if a not in b:
pass
9 changes: 9 additions & 0 deletions tests/tokenized/contains_op.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
a = 10 <EOL>
b = [ 10 , 20 , 30 ] <EOL>
if a in b : <EOL>
<INDENT>
pass <EOL>
<OUTDENT>
if a not in b : <EOL>
<INDENT>
pass <EOL>

0 comments on commit 25f44aa

Please sign in to comment.