Only initialize the async for once.

This commit is contained in:
Aralox
2020-10-22 09:11:51 +11:00
parent 5bdc0b5baf
commit e80aa996fa
4 changed files with 86 additions and 4 deletions

View File

@@ -732,14 +732,14 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
blocks.pop();
PycRef<ASTBlock> prev = curblock;
bool isAsyncFor = false;
bool isUninitAsyncFor = false;
if (blocks.top()->blktype() == ASTBlock::BLK_CONTAINER)
{
auto container = blocks.top();
blocks.pop();
auto asyncForBlock = blocks.top();
isAsyncFor = asyncForBlock->blktype() == ASTBlock::BLK_ASYNCFOR;
if (isAsyncFor)
isUninitAsyncFor = asyncForBlock->blktype() == ASTBlock::BLK_ASYNCFOR && !asyncForBlock->inited();
if (isUninitAsyncFor)
{
auto tryBlock = container->nodes().front().cast<ASTBlock>();
if (!tryBlock->nodes().empty() && tryBlock->blktype() == ASTBlock::BLK_TRY)
@@ -764,7 +764,7 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
}
}
if (!isAsyncFor) {
if (!isUninitAsyncFor) {
if (curblock->size() != 0) {
blocks.top()->append(curblock.cast<ASTNode>());
}

Binary file not shown.

View File

@@ -37,6 +37,35 @@ async def time_for_some_fun():
print('outside loop')
async def tryBlocks():
async for b in c:
stuff
await things(x)
try:
STUFF
except MyException:
running = False
BLOCK_AFTER
try:
async for b in c:
stuff
await things(x)
async for b2 in c2:
stuff2
await things2(x)
try:
STUFF2
except MyException2:
running2 = False
AFTER
try:
STUFF
except MyException:
running = False
except MyException2:
OUTEREXCEPT
print ('outside function')
# The following will LOAD_METHOD, not GET_AITER or GET_ANEXT.

View File

@@ -67,4 +67,57 @@ pass <EOL>
<OUTDENT>
print ( 'outside loop' ) <EOL>
<OUTDENT>
async def tryBlocks ( ) : <EOL>
<INDENT>
async for b in c : <EOL>
<INDENT>
stuff <EOL>
await things ( x ) <EOL>
try : <EOL>
<INDENT>
STUFF <EOL>
<OUTDENT>
except MyException : <EOL>
<INDENT>
running = False <EOL>
<OUTDENT>
BLOCK_AFTER <EOL>
<OUTDENT>
try : <EOL>
<INDENT>
async for b in c : <EOL>
<INDENT>
stuff <EOL>
await things ( x ) <EOL>
async for b2 in c2 : <EOL>
<INDENT>
stuff2 <EOL>
await things2 ( x ) <EOL>
try : <EOL>
<INDENT>
STUFF2 <EOL>
<OUTDENT>
except MyException2 : <EOL>
<INDENT>
running2 = False <EOL>
<OUTDENT>
AFTER <EOL>
<OUTDENT>
try : <EOL>
<INDENT>
STUFF <EOL>
<OUTDENT>
continue <EOL>
except MyException : <EOL>
<INDENT>
running = False <EOL>
continue <EOL>
<OUTDENT>
<OUTDENT>
<OUTDENT>
except MyException2 : <EOL>
<INDENT>
OUTEREXCEPT <EOL>
<OUTDENT>
<OUTDENT>
print ( 'outside function' ) <EOL>