Skip to content

Commit

Permalink
Merge pull request zrax#201 from dotjrich/is-op
Browse files Browse the repository at this point in the history
Adds support for IS_OP opcode
  • Loading branch information
zrax committed Oct 10, 2021
2 parents fd69853 + 9fcf5bc commit 81f3e5f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ASTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,16 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
stack.push(new ASTBinary(left, right, ASTBinary::BIN_IP_MAT_MULTIPLY));
}
break;
case Pyc::IS_OP_A:
{
PycRef<ASTNode> right = stack.top();
stack.pop();
PycRef<ASTNode> left = stack.top();
stack.pop();
// The operand will be 0 for 'is' and 1 for 'is not'.
stack.push(new ASTCompare(left, right, operand ? ASTCompare::CMP_IS_NOT : ASTCompare::CMP_IS));
}
break;
case Pyc::JUMP_IF_FALSE_A:
case Pyc::JUMP_IF_TRUE_A:
case Pyc::JUMP_IF_FALSE_OR_POP_A:
Expand Down
Binary file added tests/compiled/is_op.3.9.pyc
Binary file not shown.
9 changes: 9 additions & 0 deletions tests/input/is_op.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
a = 10
b = 10

if a is b:
pass

if a is not b:
pass

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

0 comments on commit 81f3e5f

Please sign in to comment.