Merge branch 'master' into python-3.3-to-3.5

This commit is contained in:
rocky
2022-11-05 00:27:57 -04:00
3 changed files with 21 additions and 9 deletions

View File

@@ -115,11 +115,13 @@ class Python30Parser(Python31Parser):
# From Python 2.6 # From Python 2.6
list_iter ::= list_if JUMP_BACK lc_body ::= LOAD_FAST expr LIST_APPEND
list_iter ::= list_if JUMP_BACK _come_froms POP_TOP lc_body ::= LOAD_NAME expr LIST_APPEND
lc_body ::= LOAD_NAME expr LIST_APPEND list_if ::= expr jmp_false_then list_iter
lc_body ::= LOAD_FAST expr LIST_APPEND list_if_not ::= expr jmp_true list_iter JUMP_BACK come_froms POP_TOP
list_if ::= expr jmp_false_then list_iter list_iter ::= list_if JUMP_BACK
list_iter ::= list_if JUMP_BACK _come_froms POP_TOP
############# #############
dict_comp_iter ::= expr expr ROT_TWO expr STORE_SUBSCR dict_comp_iter ::= expr expr ROT_TWO expr STORE_SUBSCR

View File

@@ -659,7 +659,10 @@ class ComprehensionMixin:
list_ifs.append(n) list_ifs.append(n)
else: else:
list_ifs.append([1]) list_ifs.append([1])
n = n[-2] if n[-1] == "come_from_opt" else n[-1] if self.version[:2] == (3, 0) and n[2] == "list_iter":
n = n[2]
else:
n = n[-2] if n[-1] == "come_from_opt" else n[-1]
pass pass
elif n == "list_if37": elif n == "list_if37":
list_ifs.append(n) list_ifs.append(n)

View File

@@ -32,6 +32,7 @@ from uncompyle6.semantics.helper import (
flatten_list, flatten_list,
) )
class NonterminalActions: class NonterminalActions:
""" """
Methods here all start with n_ and the remaining portion should be a nonterminal Methods here all start with n_ and the remaining portion should be a nonterminal
@@ -43,6 +44,12 @@ class NonterminalActions:
node is the subtree of the parse tree the that nonterminal name as the root. node is the subtree of the parse tree the that nonterminal name as the root.
""" """
def __init__(self):
# Precedence is used to determine when an expression needs
# parenthesis surrounding it. A high value indicates no
# parenthesis are needed.
self.prec = 1000
def n_alias(self, node): def n_alias(self, node):
if self.version <= (2, 1): if self.version <= (2, 1):
if len(node) == 2: if len(node) == 2:
@@ -65,6 +72,7 @@ class NonterminalActions:
else: else:
self.write(iname, " as ", sname) self.write(iname, " as ", sname)
self.prune() # stop recursing self.prune() # stop recursing
n_alias37 = n_alias n_alias37 = n_alias
def n_assign(self, node): def n_assign(self, node):
@@ -123,7 +131,6 @@ class NonterminalActions:
self.prec = p self.prec = p
self.prune() # stop recursing self.prune() # stop recursing
def n_build_slice3(self, node): def n_build_slice3(self, node):
p = self.prec p = self.prec
self.prec = 100 self.prec = 100
@@ -1055,7 +1062,7 @@ class NonterminalActions:
else: else:
self.n_expr(node) self.n_expr(node)
# Python 3.x can have be dead code as a result of its optimization? # Python 3.x can have dead code as a result of its optimization?
# So we'll add a # at the end of the return lambda so the rest is ignored # So we'll add a # at the end of the return lambda so the rest is ignored
def n_return_expr_lambda(self, node): def n_return_expr_lambda(self, node):
if 1 <= len(node) <= 2: if 1 <= len(node) <= 2:
@@ -1195,7 +1202,7 @@ class NonterminalActions:
self.write("...") self.write("...")
elif attr is None: elif attr is None:
# LOAD_CONST 'None' only occurs, when None is # LOAD_CONST 'None' only occurs, when None is
# implicit eg. in 'return' w/o params # implicit e.g. in 'return' w/o params
# pass # pass
self.write("None") self.write("None")
elif isinstance(data, tuple): elif isinstance(data, tuple):