Skip to content

Commit

Permalink
Merge pull request #162 from rocky/pypy38-split
Browse files Browse the repository at this point in the history
Pypy38 split
  • Loading branch information
rocky authored Feb 29, 2024
2 parents 8db80ab + ecd9bca commit 4d97123
Show file tree
Hide file tree
Showing 23 changed files with 3,122 additions and 74 deletions.
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ PYTHON3 ?= python3
RM ?= rm
LINT = flake8

IS_PYPY = $(shell $(PYTHON) -c 'import platform; print("pypy" if platform.python_implementation() == "PyPy" else "")')
PYTHON_VERSION = $(shell $(PYTHON) -V 2>&1 | cut -d ' ' -f 2 | cut -d'.' -f1,2 | head -1)$(IS_PYPY)

#EXTRA_DIST=ipython/ipy_trepan.py trepan
PHONY=all test check clean distcheck pytest check-long dist distclean lint flake8 test rmChangeLog clean_pyc

Expand All @@ -20,8 +23,7 @@ all: check

#: Run all tests
test check:
@PYTHON_VERSION=`$(PYTHON) -V 2>&1 | cut -d ' ' -f 2 | cut -d'.' -f1,2`; \
$(MAKE) check-$$PYTHON_VERSION
$(MAKE) check-$(PYTHON_VERSION)

#: Run all quick tests
check-short: pytest
Expand All @@ -35,6 +37,11 @@ check-3.9 check-3.10: pytest

check-3.9 check-3.10: pytest

#: Run working tests from Python 3.8
check-3.8pypy:
$(MAKE) -C test $@


# FIXME
#: pypy3.8-7.3.7
7.3:
Expand Down
38 changes: 32 additions & 6 deletions decompyle3/parsers/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019-2023 Rocky Bernstein
# Copyright (c) 2019-2024 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
Expand Down Expand Up @@ -42,6 +42,13 @@
Python38ParserLambda,
Python38ParserSingle,
)
from decompyle3.parsers.p38pypy.heads import (
Python38PyPyParserEval,
Python38PyPyParserExec,
Python38PyPyParserExpr,
Python38PyPyParserLambda,
Python38PyPyParserSingle,
)
from decompyle3.parsers.treenode import SyntaxTree
from decompyle3.show import maybe_show_asm

Expand Down Expand Up @@ -99,17 +106,36 @@ def get_python_parser(
p = Python37ParserSingle(debug_parser)
elif version == (3, 8):
if compile_mode == "exec":
p = Python38ParserExec(debug_parser=debug_parser)
if is_pypy:
p = Python38PyPyParserExec(debug_parser=debug_parser)
else:
p = Python38ParserExec(debug_parser=debug_parser)

elif compile_mode == "single":
p = Python38ParserSingle(debug_parser=debug_parser)
if is_pypy:
p = Python38PyPyParserSingle(debug_parser=debug_parser)
else:
p = Python38ParserSingle(debug_parser=debug_parser)
elif compile_mode == "lambda":
p = Python38ParserLambda(debug_parser=debug_parser)
if is_pypy:
p = Python38PyPyParserLambda(debug_parser=debug_parser)
else:
p = Python38ParserLambda(debug_parser=debug_parser)
elif compile_mode == "eval":
p = Python38ParserEval(debug_parser=debug_parser)
if is_pypy:
p = Python38PyPyParserEval(debug_parser=debug_parser)
else:
p = Python38ParserEval(debug_parser=debug_parser)
elif compile_mode == "expr":
p = Python38ParserExpr(debug_parser=debug_parser)
if is_pypy:
p = Python38PyPyParserExpr(debug_parser=debug_parser)
else:
p = Python38ParserExpr(debug_parser=debug_parser)
elif is_pypy:
p = Python38PyPyParserSingle(debug_parser)
else:
p = Python38ParserSingle(debug_parser)

elif version > (3, 8):
raise RuntimeError(
f"""Version {version_tuple_to_str(version)} is not supported."""
Expand Down
4 changes: 4 additions & 0 deletions decompyle3/parsers/p38pypy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""
Here we have Python 3.8 PyPy grammars and associated customization
for the both full language and the subset used in lambda expressions.
"""
50 changes: 50 additions & 0 deletions decompyle3/parsers/p38pypy/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright (c) 2020-2022, 2024 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/>.

from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG

from decompyle3.parsers.parse_heads import PythonBaseParser
from decompyle3.parsers.reduce_check import (
break_invalid,
for38_invalid,
forelse38_invalid,
pop_return_check,
whilestmt38_check,
whileTruestmt38_check,
)


class Python38PyPyBaseParser(PythonBaseParser):
def __init__(self, start_symbol, debug_parser: dict = PARSER_DEFAULT_DEBUG):
super(Python38PyPyBaseParser, self).__init__(
start_symbol=start_symbol, debug_parser=debug_parser
)

def customize_grammar_rules38(self, tokens, customize):
self.customize_grammar_rules37(tokens, customize)
self.check_reduce["break"] = "tokens"
self.check_reduce["for38"] = "tokens"
self.check_reduce["forelsestmt38"] = "AST"
self.check_reduce["pop_return"] = "tokens"
self.check_reduce["whileTruestmt38"] = "AST"
self.check_reduce["whilestmt38"] = "tokens"
self.check_reduce["try_elsestmtl38"] = "AST"

self.reduce_check_table["break"] = break_invalid
self.reduce_check_table["for38"] = for38_invalid
self.reduce_check_table["forelsestmt38"] = forelse38_invalid
self.reduce_check_table["pop_return"] = pop_return_check
self.reduce_check_table["whilestmt38"] = whilestmt38_check
self.reduce_check_table["whileTruestmt38"] = whileTruestmt38_check
Loading

0 comments on commit 4d97123

Please sign in to comment.