From 476eb50868789422b408558b14bbddbe1821ff2d Mon Sep 17 00:00:00 2001 From: rocky Date: Mon, 25 Jul 2016 09:06:13 -0400 Subject: [PATCH] Handle PyPy JUMP_IF_NOT_DEBUG Update README.rst to note PyPY and reorganize a little --- README.rst | 22 ++++++++++++++-------- test/bytecode_pypy2.7/03_if_elif.pyc | Bin 0 -> 255 bytes test/simple_source/stmts/03_if_elif.py | 9 +++++++-- uncompyle6/parsers/parse2.py | 8 ++++++++ uncompyle6/parsers/parse27.py | 3 +++ uncompyle6/parsers/parse3.py | 20 ++++++++++++-------- uncompyle6/scanners/scanner2.py | 2 +- uncompyle6/scanners/scanner3.py | 2 +- uncompyle6/semantics/pysource.py | 4 ++++ 9 files changed, 50 insertions(+), 20 deletions(-) create mode 100644 test/bytecode_pypy2.7/03_if_elif.pyc diff --git a/README.rst b/README.rst index 65b1dc97..a54722dc 100644 --- a/README.rst +++ b/README.rst @@ -12,20 +12,19 @@ Introduction *uncompyle6* translates Python bytecode back into equivalent Python source code. It accepts bytecodes from Python version 2.3 to 3.5 or -so. The code requires Python 2.6 or later and has been tested on Python -running versions 2.3-2.7, and 3.2-3.5. +so, including PyPy bytecode. Why this? --------- There were a number of decompyle, uncompile, uncompyle2, uncompyle3 -forks around. All of them come basically from the same code base, and -almost all of them no longer maintained or worked on. Only one handled -Python 3, and even there, only 3.2. This code pulls these together, -handles a wide range of bytecodes and addresses a number of open -issues in previous forks. +forks around. All of them came basically from the same code base, and +almost all of them no were no longer actively maintained. Only one +handled Python 3, and even there, only 3.2. This code pulls these +together and moves forward. It also addresses a number of open issues +in the previous forks. -What makes this different from other CPython bytecode decompilers? Its +What makes this different from other CPython bytecode decompilers?: its ability to deparse just fragments and give source-code information around a given bytecode offset. @@ -41,6 +40,13 @@ location in more detail than just a line number. It can be also used when source-code information does not exist and there is just bytecode information. +Requirements +------------ + +This project requires Python 2.6 or later, PyPy 3-2.40, or PyPy-5.0.1. +The bytecode files it can read has been tested on Python bytecodes from +versions 2.3-2.7, and 3.2-3.5 and the above-mentioned PyPy versions. + Installation ------------ diff --git a/test/bytecode_pypy2.7/03_if_elif.pyc b/test/bytecode_pypy2.7/03_if_elif.pyc new file mode 100644 index 0000000000000000000000000000000000000000..fb3de46d99f89f4b42496fc779a945b021b1f829 GIT binary patch literal 255 zcmd=3%*(ZacUpKd0~9bq>0%!sBb9-nNRc6xk)cQw%ob(H;{-G081fiE2&6!ZAx{ph z#)ILE5J;rh6~qOSB}@!Wj38wx3=F{E96q3o zV{vh6QAuWgo@-H2evt-HgaJX6C<3{~nYjf(<;D4>Mail9#U;5V#rg)u@tJAysX3Wx mdIgnWLv3>NQ%ZAE?N~rMgn$GaBM&1pBO4= 3.5: diff --git a/uncompyle6/scanners/scanner2.py b/uncompyle6/scanners/scanner2.py index 8f7baa82..ff4b0bcb 100755 --- a/uncompyle6/scanners/scanner2.py +++ b/uncompyle6/scanners/scanner2.py @@ -192,7 +192,7 @@ class Scanner2(scan.Scanner): opname = '%s_%d' % (opname, oparg) if op != self.opc.BUILD_SLICE: customize[opname] = oparg - elif self.is_pypy and opname == 'CALL_METHOD': + elif self.is_pypy and opname in ('CALL_METHOD', 'JUMP_IF_NOT_DEBUG'): customize[opname] = oparg elif op == self.opc.JUMP_ABSOLUTE: target = self.get_target(offset) diff --git a/uncompyle6/scanners/scanner3.py b/uncompyle6/scanners/scanner3.py index 9e645ed6..bdeb84e0 100644 --- a/uncompyle6/scanners/scanner3.py +++ b/uncompyle6/scanners/scanner3.py @@ -237,7 +237,7 @@ class Scanner3(scan.Scanner): elif op in self.varargs: pos_args = inst.argval opname = '%s_%d' % (opname, pos_args) - elif self.is_pypy and opname == 'CALL_METHOD': + elif self.is_pypy and opname in ('CALL_METHOD', 'JUMP_IF_NOT_DEBUG'): customize['CALL_METHOD'] = argval elif opname == 'UNPACK_EX': # FIXME: try with scanner and parser by diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index 971bf255..cdcb17e8 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -381,6 +381,10 @@ TABLE_DIRECT = { ####################### 'LOAD_CLASSDEREF': ( '%{pattr}', ), + ######################## + # PyPy Additions + ####################### + 'assert_pypy': ( '%|assert %c\n' , 1 ), }