Need to back off set_comp change a little...

There was set_comp already. So what had been setcomp_func is now
merely set_comp_func rather than set_comp. Small improvement but
in the right direction, still
This commit is contained in:
rocky
2018-03-05 11:41:21 -05:00
parent 9f66694056
commit 61534ceed5
4 changed files with 19 additions and 19 deletions

View File

@@ -19,7 +19,7 @@ class Python27Parser(Python2Parser):
lc_body ::= expr LIST_APPEND
for_iter ::= GET_ITER COME_FROM FOR_ITER
stmt ::= set_comp
stmt ::= set_comp_func
# Dictionary and set comprehensions were added in Python 2.7
@@ -30,8 +30,8 @@ class Python27Parser(Python2Parser):
dict_comp_func ::= BUILD_MAP_0 LOAD_FAST FOR_ITER store
comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST
set_comp ::= BUILD_SET_0 LOAD_FAST FOR_ITER store comp_iter
JUMP_BACK RETURN_VALUE RETURN_LAST
set_comp_func ::= BUILD_SET_0 LOAD_FAST FOR_ITER store comp_iter
JUMP_BACK RETURN_VALUE RETURN_LAST
comp_body ::= dict_comp_body
comp_body ::= set_comp_body

View File

@@ -61,13 +61,13 @@ class Python3Parser(PythonParser):
jb_or_c ::= JUMP_BACK
jb_or_c ::= CONTINUE
stmt ::= set_comp
stmt ::= set_comp_func
set_comp ::= BUILD_SET_0 LOAD_FAST FOR_ITER store comp_iter
JUMP_BACK RETURN_VALUE RETURN_LAST
set_comp_func ::= BUILD_SET_0 LOAD_FAST FOR_ITER store comp_iter
JUMP_BACK RETURN_VALUE RETURN_LAST
set_comp ::= BUILD_SET_0 LOAD_FAST FOR_ITER store comp_iter
COME_FROM JUMP_BACK RETURN_VALUE RETURN_LAST
set_comp_func ::= BUILD_SET_0 LOAD_FAST FOR_ITER store comp_iter
COME_FROM JUMP_BACK RETURN_VALUE RETURN_LAST
comp_body ::= dict_comp_body
comp_body ::= set_comp_body

View File

@@ -676,7 +676,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
# skip over stmt return ret_expr
ast = ast[0][0][0]
store = None
if ast in ['set_comp', 'dictcomp_func']:
if ast in ['set_comp_func', 'dict_comp_func']:
# Offset 0: BUILD_SET should have the span
# of '{'
self.gen_source(ast, code_name, {})
@@ -721,8 +721,8 @@ class FragmentsWalker(pysource.SourceWalker, object):
pass
# Python 2.7+ starts including set_comp_body
# Python 3.5+ starts including set_comp
assert n.kind in ('lc_body', 'comp_body', 'set_comp', 'set_comp_body'), ast
# Python 3.5+ starts including set_comp_func
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"
old_name = self.name
@@ -849,7 +849,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
self.set_pos_info(node, start, len(self.f.getvalue()))
self.prune()
def n_set_comp_expr(self, node):
def n_set_comp(self, node):
start = len(self.f.getvalue())
self.write('{')
if node[0] in ['LOAD_SETCOMP', 'LOAD_DICTCOMP']:
@@ -865,8 +865,8 @@ class FragmentsWalker(pysource.SourceWalker, object):
self.prune()
# FIXME: Not sure if below is general. Also, add dict_comp_func.
# 'set_comp': ("%|lambda %c: {%c for %c in %c%c}\n", 1, 3, 3, 1, 4)
def n_set_comp(self, node):
# 'set_comp_func': ("%|lambda %c: {%c for %c in %c%c}\n", 1, 3, 3, 1, 4)
def n_set_comp_func(self, node):
setcomp_start = len(self.f.getvalue())
self.write(self.indent, "lambda ")
param_node = node[1]

View File

@@ -1262,7 +1262,7 @@ class SourceWalker(GenericASTTraversal, object):
self.write(')')
self.prune()
def n_set_comp_expr(self, node):
def n_set_comp(self, node):
self.write('{')
if node[0] in ['LOAD_SETCOMP', 'LOAD_DICTCOMP']:
self.comprehension_walk3(node, 1, 0)
@@ -1272,7 +1272,7 @@ class SourceWalker(GenericASTTraversal, object):
self.comprehension_walk(node, iter_index=4)
self.write('}')
self.prune()
n_dict_comp = n_set_comp_expr
n_dict_comp = n_set_comp
def comprehension_walk3(self, node, iter_index, code_index=-5):
"""Non-closure-based comprehensions the way they are done in Python3.
@@ -1297,7 +1297,7 @@ class SourceWalker(GenericASTTraversal, object):
ast = ast[0]
store = None
if ast in ['set_comp', 'dict_comp_func']:
if ast in ['set_comp_func', 'dict_comp_func']:
for k in ast:
if k == 'comp_iter':
n = k
@@ -1338,8 +1338,8 @@ class SourceWalker(GenericASTTraversal, object):
pass
# Python 2.7+ starts including set_comp_body
# Python 3.5+ starts including set_comp
assert n.kind in ('lc_body', 'comp_body', 'set_comp', 'set_comp_body'), ast
# Python 3.5+ starts including set_comp_func
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"
# A problem created with later Python code generation is that there