You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Start to add 3.5+ await and async
This commit is contained in:
BIN
test/bytecode_3.5/03_async_await.pyc
Normal file
BIN
test/bytecode_3.5/03_async_await.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.6/03_async_await.pyc
Normal file
BIN
test/bytecode_3.6/03_async_await.pyc
Normal file
Binary file not shown.
3
test/simple_source/bug35/03_async_await.py
Normal file
3
test/simple_source/bug35/03_async_await.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Python 3.5+ async and await
|
||||||
|
async def foo():
|
||||||
|
await bar()
|
@@ -16,6 +16,10 @@ class Python35Parser(Python34Parser):
|
|||||||
|
|
||||||
def p_35on(self, args):
|
def p_35on(self, args):
|
||||||
"""
|
"""
|
||||||
|
# Python 3.5+ Await statement
|
||||||
|
sstmt ::= await_stmt
|
||||||
|
await_stmt ::= call_function GET_AWAITABLE LOAD_CONST YIELD_FROM POP_TOP
|
||||||
|
|
||||||
# Python 3.5+ has WITH_CLEANUP_START/FINISH
|
# Python 3.5+ has WITH_CLEANUP_START/FINISH
|
||||||
|
|
||||||
withstmt ::= expr SETUP_WITH exprlist suite_stmts_opt
|
withstmt ::= expr SETUP_WITH exprlist suite_stmts_opt
|
||||||
|
@@ -60,7 +60,7 @@ methods implement most of the below.
|
|||||||
%{...} evaluate ... in context of N
|
%{...} evaluate ... in context of N
|
||||||
%% literal '%'
|
%% literal '%'
|
||||||
%p evaluate N setting precedence
|
%p evaluate N setting precedence
|
||||||
|
n
|
||||||
|
|
||||||
* indicates an argument (A) required.
|
* indicates an argument (A) required.
|
||||||
|
|
||||||
@@ -73,6 +73,8 @@ import sys, re
|
|||||||
|
|
||||||
from uncompyle6 import PYTHON3
|
from uncompyle6 import PYTHON3
|
||||||
from xdis.code import iscode
|
from xdis.code import iscode
|
||||||
|
from xdis.util import COMPILER_FLAG_BIT
|
||||||
|
|
||||||
from uncompyle6.parser import get_python_parser
|
from uncompyle6.parser import get_python_parser
|
||||||
from uncompyle6.parsers.astnode import AST
|
from uncompyle6.parsers.astnode import AST
|
||||||
from spark_parser import GenericASTTraversal, DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
|
from spark_parser import GenericASTTraversal, DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
|
||||||
@@ -648,6 +650,19 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
'LOAD_CLASSDEREF': ( '%{pattr}', ),
|
'LOAD_CLASSDEREF': ( '%{pattr}', ),
|
||||||
})
|
})
|
||||||
if version >= 3.5:
|
if version >= 3.5:
|
||||||
|
TABLE_DIRECT.update({
|
||||||
|
'await_stmt': ( '%|await %c', 0),
|
||||||
|
})
|
||||||
|
def n_funcdef(node):
|
||||||
|
code_node = node[0][1]
|
||||||
|
if (code_node == 'LOAD_CONST' and iscode(code_node.attr)
|
||||||
|
and code_node.attr.co_flags & COMPILER_FLAG_BIT['COROUTINE']):
|
||||||
|
self.engine(('\n\n%|async def %c\n', -2), node)
|
||||||
|
else:
|
||||||
|
self.engine(('\n\n%|def %c\n', -2), node)
|
||||||
|
self.prune()
|
||||||
|
self.n_funcdef = n_funcdef
|
||||||
|
|
||||||
def n_unmapexpr(node):
|
def n_unmapexpr(node):
|
||||||
last_n = node[0][-1]
|
last_n = node[0][-1]
|
||||||
for n in node[0]:
|
for n in node[0]:
|
||||||
@@ -1895,7 +1910,6 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
beginning of this module for the how we interpret format specifications such as
|
beginning of this module for the how we interpret format specifications such as
|
||||||
%c, %C, and so on.
|
%c, %C, and so on.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# self.println("----> ", startnode.type)
|
# self.println("----> ", startnode.type)
|
||||||
fmt = entry[0]
|
fmt = entry[0]
|
||||||
arg = 1
|
arg = 1
|
||||||
|
Reference in New Issue
Block a user