Merge pull request #203 from dotjrich/contains-op

Adds support for CONTAINS_OP opcode
This commit is contained in:
Michael Hansen
2021-10-09 22:06:45 -07:00
committed by GitHub
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>