Merge pull request #184 from Aralox/Issue-183-support-unpack-empty
Support unpacking empty list.
This commit is contained in:
21
ASTree.cpp
21
ASTree.cpp
@@ -2243,10 +2243,23 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
|
||||
case Pyc::UNPACK_SEQUENCE_A:
|
||||
{
|
||||
unpack = operand;
|
||||
|
||||
ASTTuple::value_t vals;
|
||||
|
||||
stack.push(new ASTTuple(vals));
|
||||
if (unpack > 0) {
|
||||
ASTTuple::value_t vals;
|
||||
stack.push(new ASTTuple(vals));
|
||||
} else {
|
||||
// Unpack zero values and assign it to top of stack or for loop variable.
|
||||
// E.g. [] = TOS / for [] in X
|
||||
ASTTuple::value_t vals;
|
||||
auto tup = new ASTTuple(vals);
|
||||
if (curblock->blktype() == ASTBlock::BLK_FOR
|
||||
&& !curblock->inited()) {
|
||||
tup->setRequireParens(true);
|
||||
curblock.cast<ASTIterBlock>()->setIndex(tup);
|
||||
} else {
|
||||
curblock->append(new ASTStore(stack.top(), tup));
|
||||
stack.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Pyc::YIELD_FROM:
|
||||
|
BIN
tests/compiled/unpack_empty.2.7.pyc
Normal file
BIN
tests/compiled/unpack_empty.2.7.pyc
Normal file
Binary file not shown.
BIN
tests/compiled/unpack_empty.3.7.pyc
Normal file
BIN
tests/compiled/unpack_empty.3.7.pyc
Normal file
Binary file not shown.
5
tests/input/unpack_empty.py
Normal file
5
tests/input/unpack_empty.py
Normal file
@@ -0,0 +1,5 @@
|
||||
[] = c
|
||||
y = []
|
||||
for [] in x:
|
||||
BLOCK
|
||||
[] = []
|
7
tests/tokenized/unpack_empty.txt
Normal file
7
tests/tokenized/unpack_empty.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
( ) = c <EOL>
|
||||
y = [ ] <EOL>
|
||||
for ( ) in x : <EOL>
|
||||
<INDENT>
|
||||
BLOCK <EOL>
|
||||
<OUTDENT>
|
||||
( ) = [ ] <EOL>
|
Reference in New Issue
Block a user