return_lambda -> return_expr_lambda

Except those places in 2.6ish code where it is simple a fancy RETURN_VALUE
This commit is contained in:
rocky
2022-01-01 21:45:51 -05:00
parent 51e32b88a4
commit 3d5b6f4654
7 changed files with 35 additions and 21 deletions

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2015-2021 Rocky Bernstein
# Copyright (c) 2015-2022 Rocky Bernstein
# Copyright (c) 2005 by Dan Pascu <dan@windowmaker.org>
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
# Copyright (c) 1999 John Aycock
@@ -577,10 +577,10 @@ class PythonParser(GenericASTBuilder):
ret_expr_or_cond ::= ret_expr
ret_expr_or_cond ::= if_exp_ret
stmt ::= return_lambda
stmt ::= return_expr_lambda
return_lambda ::= ret_expr RETURN_VALUE_LAMBDA LAMBDA_MARKER
return_lambda ::= ret_expr RETURN_VALUE_LAMBDA
return_expr_lambda ::= ret_expr RETURN_VALUE_LAMBDA LAMBDA_MARKER
return_expr_lambda ::= ret_expr RETURN_VALUE_LAMBDA
compare ::= compare_chained
compare ::= compare_single

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2017-2021 Rocky Bernstein
# Copyright (c) 2017-2022 Rocky Bernstein
"""
spark grammar differences over Python2 for Python 2.6.
"""
@@ -317,7 +317,7 @@ class Python26Parser(Python2Parser):
return_lambda ::= RETURN_END_IF_LAMBDA
return_lambda ::= RETURN_VALUE_LAMBDA
compare_chained2 ::= expr COMPARE_OP return_lambda
compare_chained2 ::= expr COMPARE_OP return_expr_lambda
return_if_lambda ::= RETURN_END_IF_LAMBDA POP_TOP
stmt ::= if_exp_lambda

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2015-2021 Rocky Bernstein
# Copyright (c) 2015-2022 Rocky Bernstein
# Copyright (c) 2005 by Dan Pascu <dan@windowmaker.org>
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
# Copyright (c) 1999 John Aycock
@@ -711,9 +711,9 @@ class Python3Parser(PythonParser):
stmt ::= if_exp_lambda
stmt ::= if_exp_not_lambda
if_expr_lambda ::= expr jmp_false expr return_if_lambda
return_lambda LAMBDA_MARKER
return_expr_lambda LAMBDA_MARKER
if_exp_not_lambda ::= expr jmp_true expr return_if_lambda
return_lambda LAMBDA_MARKER
return_expr_lambda LAMBDA_MARKER
""",
nop_func,
)
@@ -1452,7 +1452,7 @@ class Python3Parser(PythonParser):
elif opname == "RETURN_VALUE_LAMBDA":
self.addRule(
"""
return_lambda ::= ret_expr RETURN_VALUE_LAMBDA
return_expr_lambda ::= ret_expr RETURN_VALUE_LAMBDA
""",
nop_func,
)

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2017-2020 Rocky Bernstein
# Copyright (c) 2017-2020, 2022 Rocky Bernstein
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -199,10 +199,10 @@ class Python37Parser(Python37BaseParser):
ret_expr_or_cond ::= ret_expr
ret_expr_or_cond ::= if_exp_ret
stmt ::= return_lambda
stmt ::= return_expr_lambda
return_lambda ::= ret_expr RETURN_VALUE_LAMBDA LAMBDA_MARKER
return_lambda ::= ret_expr RETURN_VALUE_LAMBDA
return_expr_lambda ::= ret_expr RETURN_VALUE_LAMBDA LAMBDA_MARKER
return_expr_lambda ::= ret_expr RETURN_VALUE_LAMBDA
compare ::= compare_chained
compare ::= compare_single

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2016-2017, 2019-2020 Rocky Bernstein
# Copyright (c) 2016-2017, 2019-2020, 2022 Rocky Bernstein
"""
Python 3.7 base code. We keep non-custom-generated grammar rules out of this file.
"""
@@ -163,9 +163,9 @@ class Python37BaseParser(PythonParser):
stmt ::= if_exp_lambda
stmt ::= if_exp_not_lambda
if_exp_lambda ::= expr jmp_false expr return_if_lambda
return_lambda LAMBDA_MARKER
return_expr_lambda LAMBDA_MARKER
if_exp_not_lambda ::= expr jmp_true expr return_if_lambda
return_lambda LAMBDA_MARKER
return_expr_lambda LAMBDA_MARKER
""",
nop_func,
)
@@ -952,7 +952,7 @@ class Python37BaseParser(PythonParser):
elif opname == "RETURN_VALUE_LAMBDA":
self.addRule(
"""
return_lambda ::= ret_expr RETURN_VALUE_LAMBDA
return_expr_lambda ::= ret_expr RETURN_VALUE_LAMBDA
""",
nop_func,
)

View File

@@ -1,3 +1,17 @@
# Copyright (c) 2022 Rocky Bernstein
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
from xdis import iscode
@@ -46,7 +60,7 @@ def find_all_globals(node, globs):
# # print("XXX", n.kind, global_ops)
# if isinstance(n, SyntaxTree):
# # FIXME: do I need a caser for n.kind="mkfunc"?
# if n.kind in ("if_exp_lambda", "return_lambda"):
# if n.kind in ("if_exp_lambda", "return_expr_lambda"):
# globs = find_globals(n, globs, lambda_body_globals)
# else:
# globs = find_globals(n, globs, global_ops)

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2015-2021 by Rocky Bernstein
# Copyright (c) 2015-2022 by Rocky Bernstein
# Copyright (c) 2005 by Dan Pascu <dan@windowmaker.org>
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
# Copyright (c) 1999 John Aycock
@@ -491,7 +491,7 @@ class SourceWalker(GenericASTTraversal, object):
# Python 3.x can have be 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
def n_return_lambda(self, node):
def n_return_expr_lambda(self, node):
if 1 <= len(node) <= 2:
self.preorder(node[0])
self.write(" # Avoid dead code: ")