You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
Python 3.0 set comprehensions
This commit is contained in:
@@ -38,6 +38,14 @@ class Python30Parser(Python31Parser):
|
|||||||
setupwithas ::= DUP_TOP LOAD_ATTR STORE_FAST LOAD_ATTR CALL_FUNCTION_0 setup_finally
|
setupwithas ::= DUP_TOP LOAD_ATTR STORE_FAST LOAD_ATTR CALL_FUNCTION_0 setup_finally
|
||||||
setup_finally ::= STORE_FAST SETUP_FINALLY LOAD_FAST DELETE_FAST
|
setup_finally ::= STORE_FAST SETUP_FINALLY LOAD_FAST DELETE_FAST
|
||||||
|
|
||||||
|
# Need to keep LOAD_FAST as index 1
|
||||||
|
set_comp_func_header ::= BUILD_SET_0 DUP_TOP STORE_FAST
|
||||||
|
set_comp_func ::= set_comp_func_header
|
||||||
|
LOAD_FAST FOR_ITER store comp_iter
|
||||||
|
JUMP_BACK POP_TOP JUMP_BACK RETURN_VALUE RETURN_LAST
|
||||||
|
comp_if ::= expr jmp_false comp_iter
|
||||||
|
comp_iter ::= expr expr SET_ADD
|
||||||
|
|
||||||
# In many ways 3.0 is like 2.6. The below rules in fact are the same or similar.
|
# In many ways 3.0 is like 2.6. The below rules in fact are the same or similar.
|
||||||
|
|
||||||
jmp_true ::= JUMP_IF_TRUE POP_TOP
|
jmp_true ::= JUMP_IF_TRUE POP_TOP
|
||||||
|
@@ -1052,7 +1052,7 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
ast = ast[0]
|
ast = ast[0]
|
||||||
|
|
||||||
store = None
|
store = None
|
||||||
if ast in ['set_comp_func', 'dict_comp_func']:
|
if ast in ['set_comp_func', 'dict_comp_func', 'set_comp_func_header']:
|
||||||
for k in ast:
|
for k in ast:
|
||||||
if k == 'comp_iter':
|
if k == 'comp_iter':
|
||||||
n = k
|
n = k
|
||||||
@@ -1078,7 +1078,13 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
|
|
||||||
have_not = False
|
have_not = False
|
||||||
while n in ('list_iter', 'comp_iter'):
|
while n in ('list_iter', 'comp_iter'):
|
||||||
n = n[0] # iterate one nesting deeper
|
# iterate one nesting deeper
|
||||||
|
if self.version == 3.0 and len(n) == 3:
|
||||||
|
assert n[0] == 'expr' and n[1] == 'expr'
|
||||||
|
n = n[1]
|
||||||
|
else:
|
||||||
|
n = n[0]
|
||||||
|
|
||||||
if n in ('list_for', 'comp_for'):
|
if n in ('list_for', 'comp_for'):
|
||||||
if n[2] == 'store':
|
if n[2] == 'store':
|
||||||
store = n[2]
|
store = n[2]
|
||||||
@@ -1094,7 +1100,9 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
|
|
||||||
# Python 2.7+ starts including set_comp_body
|
# Python 2.7+ starts including set_comp_body
|
||||||
# Python 3.5+ starts including set_comp_func
|
# Python 3.5+ starts including set_comp_func
|
||||||
assert n.kind in ('lc_body', 'comp_body', 'set_comp_func', 'set_comp_body'), ast
|
# Python 3.0 is yet another snowflake
|
||||||
|
if self.version != 3.0:
|
||||||
|
assert n.kind in ('lc_body', 'comp_body', 'set_comp_func', 'set_comp_body'), ast
|
||||||
assert store, "Couldn't find store in list/set comprehension"
|
assert store, "Couldn't find store in list/set comprehension"
|
||||||
|
|
||||||
# A problem created with later Python code generation is that there
|
# A problem created with later Python code generation is that there
|
||||||
@@ -1114,7 +1122,6 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
self.preorder(store)
|
self.preorder(store)
|
||||||
|
|
||||||
# FIXME this is all merely approximate
|
# FIXME this is all merely approximate
|
||||||
# from trepan.api import debug; debug()
|
|
||||||
self.write(' in ')
|
self.write(' in ')
|
||||||
self.preorder(node[-3])
|
self.preorder(node[-3])
|
||||||
|
|
||||||
@@ -1127,9 +1134,7 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
return
|
return
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if comp_store:
|
if if_node:
|
||||||
self.preorder(comp_for)
|
|
||||||
elif if_node:
|
|
||||||
self.write(' if ')
|
self.write(' if ')
|
||||||
if have_not:
|
if have_not:
|
||||||
self.write('not ')
|
self.write('not ')
|
||||||
|
Reference in New Issue
Block a user