Adds support for CONTAINS_OP opcode

Mentioned in:
- #190
- #191
- #195
This commit is contained in:
John Richards
2021-10-10 00:40:39 -04:00
parent 81f3e5f84b
commit 25f44aa079
4 changed files with 27 additions and 0 deletions

View File

@@ -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();

Binary file not shown.

View File

@@ -0,0 +1,8 @@
a = 10
b = [10, 20, 30]
if a in b:
pass
if a not in b:
pass

View File

@@ -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>