From 7fd1cea8777aa6716af5340419be6fadaecaf999 Mon Sep 17 00:00:00 2001 From: rocky Date: Tue, 2 Nov 2021 06:05:09 -0400 Subject: [PATCH] Start PyPY 3.7 and 3.8 decompilation support --- pytest/test_build_const_key_map.py | 4 ++-- uncompyle6/scanners/pypy37.py | 24 ++++++++++++++++++++++++ uncompyle6/scanners/pypy38.py | 24 ++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 uncompyle6/scanners/pypy37.py create mode 100644 uncompyle6/scanners/pypy38.py diff --git a/pytest/test_build_const_key_map.py b/pytest/test_build_const_key_map.py index 06d3d4e8..407ded95 100644 --- a/pytest/test_build_const_key_map.py +++ b/pytest/test_build_const_key_map.py @@ -1,10 +1,10 @@ import pytest # uncompyle6 -from uncompyle6 import PYTHON_VERSION +from xdis.version_info import PYTHON_VERSION_TRIPLE, IS_PYPY from validate import validate_uncompyle -@pytest.mark.skipif(PYTHON_VERSION < 3.6, reason='need at least python 3.6') +@pytest.mark.skipif(PYTHON_VERSION_TRIPLE < (3, 6) or IS_PYPY, reason="need at least Python 3.6 and not PyPY") @pytest.mark.parametrize('text', ( "{0.: 'a', -1: 'b'}", # BUILD_MAP "{'a':'b'}", # BUILD_MAP diff --git a/uncompyle6/scanners/pypy37.py b/uncompyle6/scanners/pypy37.py new file mode 100644 index 00000000..16031dbe --- /dev/null +++ b/uncompyle6/scanners/pypy37.py @@ -0,0 +1,24 @@ +# Copyright (c) 2021 by Rocky Bernstein +""" +Python PyPy 3.7 decompiler scanner. + +Does some additional massaging of xdis-disassembled instructions to +make things easier for decompilation. +""" + +import decompyle3.scanners.scanner3y as scan + +# bytecode verification, verify(), uses JUMP_OPS from here +from xdis.opcodes import opcode_37pypy as opc # is this right? + +JUMP_OPs = opc.JUMP_OPS + +# We base this off of 3.7 +class ScannerPyPy37(scan.Scanner37): + def __init__(self, show_asm): + # There are no differences in initialization between + # pypy 3.7 and 3.7 + scan.Scanner37.__init__(self, show_asm, is_pypy=True) + self.version = (3, 7) + self.opc = opc + return diff --git a/uncompyle6/scanners/pypy38.py b/uncompyle6/scanners/pypy38.py new file mode 100644 index 00000000..e60ebeb1 --- /dev/null +++ b/uncompyle6/scanners/pypy38.py @@ -0,0 +1,24 @@ +# Copyright (c) 2021 by Rocky Bernstein +""" +Python PyPy 3.8 decompiler scanner. + +Does some additional massaging of xdis-disassembled instructions to +make things easier for decompilation. +""" + +import decompyle3.scanners.scanner38 as scan + +# bytecode verification, verify(), uses JUMP_OPS from here +from xdis.opcodes import opcode_38pypy as opc + +JUMP_OPs = opc.JUMP_OPS + +# We base this off of 3.8 +class ScannerPyPy38(scan.Scanner38): + def __init__(self, show_asm): + # There are no differences in initialization between + # pypy 3.8 and 3.8 + scan.Scanner38.__init__(self, show_asm, is_pypy=True) + self.version = (3, 8) + self.opc = opc + return