You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Handle nested async for in for...
and Better async comprehension detection. Still more work is needed. See commented-out section in test/simple_source/bug37/02_async_for_generator.py
This commit is contained in:
@@ -210,41 +210,86 @@ class Python37BaseParser(PythonParser):
|
||||
|
||||
if self.version < 3.8:
|
||||
rules_str += """
|
||||
stmt ::= async_with_stmt SETUP_ASYNC_WITH
|
||||
async_with_stmt ::= expr
|
||||
stmt ::= async_with_stmt SETUP_ASYNC_WITH
|
||||
c_stmt ::= c_async_with_stmt SETUP_ASYNC_WITH
|
||||
async_with_stmt ::= expr
|
||||
async_with_pre
|
||||
POP_TOP
|
||||
suite_stmts_opt
|
||||
POP_BLOCK LOAD_CONST
|
||||
async_with_post
|
||||
c_async_with_stmt ::= expr
|
||||
async_with_pre
|
||||
POP_TOP
|
||||
c_suite_stmts_opt
|
||||
POP_BLOCK LOAD_CONST
|
||||
async_with_post
|
||||
async_with_stmt ::= expr
|
||||
async_with_pre
|
||||
POP_TOP
|
||||
suite_stmts_opt
|
||||
async_with_post
|
||||
c_async_with_stmt ::= expr
|
||||
async_with_pre
|
||||
POP_TOP
|
||||
c_suite_stmts_opt
|
||||
async_with_post
|
||||
async_with_as_stmt ::= expr
|
||||
async_with_pre
|
||||
store
|
||||
suite_stmts_opt
|
||||
POP_BLOCK LOAD_CONST
|
||||
async_with_post
|
||||
c_async_with_as_stmt ::= expr
|
||||
async_with_pre
|
||||
POP_TOP
|
||||
suite_stmts_opt
|
||||
store
|
||||
c_suite_stmts_opt
|
||||
POP_BLOCK LOAD_CONST
|
||||
async_with_post
|
||||
async_with_stmt ::= expr
|
||||
async_with_pre
|
||||
POP_TOP
|
||||
suite_stmts_opt
|
||||
async_with_post
|
||||
async_with_as_stmt ::= expr
|
||||
async_with_as_stmt ::= expr
|
||||
async_with_pre
|
||||
store
|
||||
suite_stmts_opt
|
||||
async_with_post
|
||||
c_async_with_as_stmt ::= expr
|
||||
async_with_pre
|
||||
store
|
||||
suite_stmts_opt
|
||||
POP_BLOCK LOAD_CONST
|
||||
async_with_post
|
||||
"""
|
||||
else:
|
||||
rules_str += """
|
||||
async_with_pre ::= BEFORE_ASYNC_WITH GET_AWAITABLE LOAD_CONST YIELD_FROM SETUP_ASYNC_WITH
|
||||
async_with_post ::= BEGIN_FINALLY COME_FROM_ASYNC_WITH
|
||||
WITH_CLEANUP_START GET_AWAITABLE LOAD_CONST YIELD_FROM
|
||||
WITH_CLEANUP_FINISH END_FINALLY
|
||||
async_with_stmt ::= expr
|
||||
async_with_pre ::= BEFORE_ASYNC_WITH GET_AWAITABLE LOAD_CONST YIELD_FROM SETUP_ASYNC_WITH
|
||||
async_with_post ::= BEGIN_FINALLY COME_FROM_ASYNC_WITH
|
||||
WITH_CLEANUP_START GET_AWAITABLE LOAD_CONST YIELD_FROM
|
||||
WITH_CLEANUP_FINISH END_FINALLY
|
||||
async_with_stmt ::= expr
|
||||
async_with_pre
|
||||
POP_TOP
|
||||
suite_stmts
|
||||
POP_TOP POP_BLOCK
|
||||
async_with_post
|
||||
c_async_with_stmt ::= expr
|
||||
async_with_pre
|
||||
POP_TOP
|
||||
c_suite_stmts
|
||||
POP_TOP POP_BLOCK
|
||||
async_with_post
|
||||
async_with_stmt ::= expr
|
||||
async_with_pre
|
||||
POP_TOP
|
||||
suite_stmts
|
||||
POP_BLOCK
|
||||
BEGIN_FINALLY
|
||||
WITH_CLEANUP_START GET_AWAITABLE LOAD_CONST YIELD_FROM
|
||||
WITH_CLEANUP_FINISH POP_FINALLY LOAD_CONST RETURN_VALUE
|
||||
COME_FROM_ASYNC_WITH
|
||||
WITH_CLEANUP_START GET_AWAITABLE LOAD_CONST YIELD_FROM
|
||||
WITH_CLEANUP_FINISH END_FINALLY
|
||||
c_async_with_stmt ::= expr
|
||||
async_with_pre
|
||||
POP_TOP
|
||||
suite_stmts
|
||||
POP_TOP POP_BLOCK
|
||||
async_with_post
|
||||
async_with_stmt ::= expr
|
||||
async_with_pre
|
||||
POP_TOP
|
||||
suite_stmts
|
||||
c_suite_stmts
|
||||
POP_BLOCK
|
||||
BEGIN_FINALLY
|
||||
WITH_CLEANUP_START GET_AWAITABLE LOAD_CONST YIELD_FROM
|
||||
@@ -252,15 +297,24 @@ class Python37BaseParser(PythonParser):
|
||||
COME_FROM_ASYNC_WITH
|
||||
WITH_CLEANUP_START GET_AWAITABLE LOAD_CONST YIELD_FROM
|
||||
WITH_CLEANUP_FINISH END_FINALLY
|
||||
async_with_as_stmt ::= expr
|
||||
async_with_pre
|
||||
store suite_stmts
|
||||
POP_TOP POP_BLOCK
|
||||
async_with_post
|
||||
async_with_as_stmt ::= expr
|
||||
async_with_pre
|
||||
store suite_stmts
|
||||
POP_BLOCK async_with_post
|
||||
async_with_as_stmt ::= expr
|
||||
async_with_pre
|
||||
store suite_stmts
|
||||
POP_TOP POP_BLOCK
|
||||
async_with_post
|
||||
c_async_with_as_stmt ::= expr
|
||||
async_with_pre
|
||||
store suite_stmts
|
||||
POP_TOP POP_BLOCK
|
||||
async_with_post
|
||||
async_with_as_stmt ::= expr
|
||||
async_with_pre
|
||||
store suite_stmts
|
||||
POP_BLOCK async_with_post
|
||||
c_async_with_as_stmt ::= expr
|
||||
async_with_pre
|
||||
store suite_stmts
|
||||
POP_BLOCK async_with_post
|
||||
"""
|
||||
self.addRule(rules_str, nop_func)
|
||||
|
||||
@@ -539,7 +593,7 @@ class Python37BaseParser(PythonParser):
|
||||
|
||||
stmt ::= genexpr_func_async
|
||||
|
||||
func_async_prefix ::= SETUP_EXCEPT GET_ANEXT LOAD_CONST YIELD_FROM
|
||||
func_async_prefix ::= _come_froms SETUP_EXCEPT GET_ANEXT LOAD_CONST YIELD_FROM
|
||||
func_async_middle ::= POP_BLOCK JUMP_FORWARD COME_FROM_EXCEPT
|
||||
DUP_TOP LOAD_GLOBAL COMPARE_OP POP_JUMP_IF_TRUE
|
||||
END_FINALLY COME_FROM
|
||||
@@ -548,22 +602,24 @@ class Python37BaseParser(PythonParser):
|
||||
JUMP_BACK COME_FROM
|
||||
POP_TOP POP_TOP POP_TOP POP_EXCEPT POP_TOP
|
||||
|
||||
expr ::= listcomp_async
|
||||
listcomp_async ::= LOAD_LISTCOMP LOAD_STR MAKE_FUNCTION_0
|
||||
expr ::= list_comp_async
|
||||
list_comp_async ::= LOAD_LISTCOMP LOAD_STR MAKE_FUNCTION_0
|
||||
expr GET_AITER CALL_FUNCTION_1
|
||||
GET_AWAITABLE LOAD_CONST
|
||||
YIELD_FROM
|
||||
|
||||
expr ::= listcomp_async
|
||||
listcomp_async ::= BUILD_LIST_0 LOAD_FAST func_async_prefix
|
||||
expr ::= list_comp_async
|
||||
list_afor2 ::= func_async_prefix
|
||||
store func_async_middle list_iter
|
||||
JUMP_BACK COME_FROM
|
||||
POP_TOP POP_TOP POP_TOP POP_EXCEPT POP_TOP
|
||||
|
||||
list_comp_async ::= BUILD_LIST_0 LOAD_FAST list_afor2
|
||||
get_aiter ::= LOAD_DEREF GET_AITER
|
||||
list_afor ::= get_aiter list_afor2
|
||||
list_iter ::= list_afor
|
||||
""",
|
||||
nop_func,
|
||||
)
|
||||
custom_ops_processed.add(opname)
|
||||
elif opname == "JUMP_IF_NOT_DEBUG":
|
||||
v = token.attr
|
||||
self.addRule(
|
||||
|
Reference in New Issue
Block a user