From a981db884ca3f8d2da0d53470880fa89de51250b Mon Sep 17 00:00:00 2001 From: rocky Date: Tue, 30 Apr 2019 05:12:42 -0400 Subject: [PATCH] Pypy 3.6 tolerance --- __pkginfo__.py | 2 +- test/Makefile | 6 ++++++ test/test_pythonlib.py | 2 +- uncompyle6/parsers/parse36.py | 8 +++++++- uncompyle6/scanners/pypy35.py | 4 ++-- uncompyle6/scanners/scanner36.py | 13 ++++++++----- 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/__pkginfo__.py b/__pkginfo__.py index 09dc71cc..b4bde950 100644 --- a/__pkginfo__.py +++ b/__pkginfo__.py @@ -58,7 +58,7 @@ entry_points = { ]} ftp_url = None install_requires = ['spark-parser >= 1.8.7, < 1.9.0', - 'xdis >= 4.0.0, < 4.1.0'] + 'xdis >= 4.0.1, < 4.1.0'] license = 'GPL3' mailing_list = 'python-debugger@googlegroups.com' diff --git a/test/Makefile b/test/Makefile index eadbeb6a..04546f64 100644 --- a/test/Makefile +++ b/test/Makefile @@ -308,6 +308,12 @@ pypy-2.7 5.0 5.3 6.0: pypy-3.2 2.4: $(PYTHON) test_pythonlib.py --bytecode-pypy3.2 --verify +#: PyPy 5.0.x with Python 3.6 ... +7.1: + $(PYTHON) test_pythonlib.py --bytecode-pypy3.6 --verify + + + clean: clean-py-dis clean-dis clean-unverified clean-dis: diff --git a/test/test_pythonlib.py b/test/test_pythonlib.py index df05fcf5..344060d5 100755 --- a/test/test_pythonlib.py +++ b/test/test_pythonlib.py @@ -81,7 +81,7 @@ for vers in (2.7, 3.4, 3.5, 3.6): for vers in (1.3, 1.4, 1.5, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2, 3.3, - 3.4, 3.5, 3.6, 3.7, 3.8, 'pypy3.2', 'pypy2.7'): + 3.4, 3.5, 3.6, 3.7, 3.8, 'pypy3.2', 'pypy2.7', 'pypy3.6'): bytecode = "bytecode_%s" % vers key = "bytecode-%s" % vers test_options[key] = (bytecode, PYC, bytecode, vers) diff --git a/uncompyle6/parsers/parse36.py b/uncompyle6/parsers/parse36.py index 0117c24e..b7770e5c 100644 --- a/uncompyle6/parsers/parse36.py +++ b/uncompyle6/parsers/parse36.py @@ -171,7 +171,13 @@ class Python36Parser(Python35Parser): for i, token in enumerate(tokens): opname = token.kind - if opname == 'FORMAT_VALUE': + if opname == 'LOAD_ASSERT': + if 'PyPy' in customize: + rules_str = """ + stmt ::= JUMP_IF_NOT_DEBUG stmts COME_FROM + """ + self.add_unique_doc_rules(rules_str, customize) + elif opname == 'FORMAT_VALUE': rules_str = """ expr ::= fstring_single fstring_single ::= expr FORMAT_VALUE diff --git a/uncompyle6/scanners/pypy35.py b/uncompyle6/scanners/pypy35.py index 2cbca409..acbc68b7 100644 --- a/uncompyle6/scanners/pypy35.py +++ b/uncompyle6/scanners/pypy35.py @@ -1,6 +1,6 @@ -# Copyright (c) 2017 by Rocky Bernstein +# Copyright (c) 2017, 2019 by Rocky Bernstein """ -Python PyPy 3.2 decompiler scanner. +Python PyPy 3.5 decompiler scanner. Does some additional massaging of xdis-disassembled instructions to make things easier for decompilation. diff --git a/uncompyle6/scanners/scanner36.py b/uncompyle6/scanners/scanner36.py index 522d1def..b781c871 100644 --- a/uncompyle6/scanners/scanner36.py +++ b/uncompyle6/scanners/scanner36.py @@ -19,23 +19,26 @@ JUMP_OPS = opc.JUMP_OPS class Scanner36(Scanner3): - def __init__(self, show_asm=None): - Scanner3.__init__(self, 3.6, show_asm) + def __init__(self, show_asm=None, is_pypy=False): + Scanner3.__init__(self, 3.6, show_asm, is_pypy) return def ingest(self, co, classname=None, code_objects={}, show_asm=None): tokens, customize = Scanner3.ingest(self, co, classname, code_objects, show_asm) + not_pypy36 = not (self.version == 3.6 and self.is_pypy) for t in tokens: # The lowest bit of flags indicates whether the # var-keyword argument is placed at the top of the stack - if t.op == self.opc.CALL_FUNCTION_EX and t.attr & 1: + if ( not_pypy36 and + t.op == self.opc.CALL_FUNCTION_EX and t.attr & 1): t.kind = 'CALL_FUNCTION_EX_KW' pass elif t.op == self.opc.CALL_FUNCTION_KW: t.kind = 'CALL_FUNCTION_KW_{t.attr}'.format(**locals()) - elif t.op == self.opc.BUILD_MAP_UNPACK_WITH_CALL: + elif ( not_pypy36 and + t.op == self.opc.BUILD_MAP_UNPACK_WITH_CALL ): t.kind = 'BUILD_MAP_UNPACK_WITH_CALL_%d' % t.attr - elif t.op == self.opc.BUILD_TUPLE_UNPACK_WITH_CALL: + elif ( not_pypy36 and t.op == self.opc.BUILD_TUPLE_UNPACK_WITH_CALL ): t.kind = 'BUILD_TUPLE_UNPACK_WITH_CALL_%d' % t.attr pass return tokens, customize