3.0 list comprehensions

This commit is contained in:
rocky 2018-06-09 23:14:04 -04:00
parent 67910e7d8e
commit 0353b74a7a
3 changed files with 11 additions and 2 deletions

Binary file not shown.

View File

@ -43,8 +43,16 @@ class Python30Parser(Python31Parser):
set_comp_func ::= set_comp_func_header
LOAD_FAST FOR_ITER store comp_iter
JUMP_BACK POP_TOP JUMP_BACK RETURN_VALUE RETURN_LAST
list_comp_header ::= BUILD_LIST_0 DUP_TOP STORE_FAST
list_comp ::= list_comp_header
LOAD_FAST FOR_ITER store comp_iter
JUMP_BACK
comp_if ::= expr jmp_false comp_iter
comp_iter ::= expr expr SET_ADD
comp_iter ::= expr expr LIST_APPEND
# In many ways 3.0 is like 2.6. The below rules in fact are the same or similar.

View File

@ -1052,7 +1052,8 @@ class SourceWalker(GenericASTTraversal, object):
ast = ast[0]
store = None
if ast in ['set_comp_func', 'dict_comp_func', 'set_comp_func_header']:
if ast in ['set_comp_func', 'dict_comp_func',
'list_comp', 'set_comp_func_header']:
for k in ast:
if k == 'comp_iter':
n = k
@ -1125,7 +1126,7 @@ class SourceWalker(GenericASTTraversal, object):
self.write(' in ')
self.preorder(node[-3])
if ast == 'list_comp':
if ast == 'list_comp' and self.version != 3.0:
list_iter = ast[1]
assert list_iter == 'list_iter'
if list_iter == 'list_for':