From e5f3d803a817c900b4e41d595e9df4f783e80d7e Mon Sep 17 00:00:00 2001 From: rocky Date: Sat, 19 May 2018 07:06:55 -0400 Subject: [PATCH] Start Python 1.4 decompilation ... Tidy up test code for issue 162 and comments for some disassembly massaging. --- test/bytecode_1.4/emacs.pyc | Bin 0 -> 809 bytes test/bytecode_2.7_run/05_dict_comp.pyc | Bin 578 -> 578 bytes test/bytecode_3.1/05_dict_comp.pyc | Bin 501 -> 0 bytes test/bytecode_3.1_run/05_dict_comp.pyc | Bin 0 -> 599 bytes test/bytecode_3.5_run/05_dict_comp.pyc | Bin 461 -> 461 bytes .../comprehension/05_dict_comp.py | 3 ++ uncompyle6/parsers/parse14.py | 30 ++++++++++++++++++ uncompyle6/parsers/parse15.py | 2 +- uncompyle6/scanner.py | 2 +- uncompyle6/scanners/scanner14.py | 27 ++++++++++++++++ uncompyle6/scanners/scanner15.py | 4 +-- uncompyle6/scanners/scanner21.py | 4 +-- uncompyle6/scanners/scanner22.py | 4 +-- uncompyle6/scanners/scanner23.py | 4 +-- uncompyle6/scanners/scanner24.py | 2 +- uncompyle6/scanners/scanner25.py | 4 +-- 16 files changed, 73 insertions(+), 13 deletions(-) create mode 100644 test/bytecode_1.4/emacs.pyc delete mode 100644 test/bytecode_3.1/05_dict_comp.pyc create mode 100644 test/bytecode_3.1_run/05_dict_comp.pyc create mode 100644 uncompyle6/parsers/parse14.py create mode 100644 uncompyle6/scanners/scanner14.py diff --git a/test/bytecode_1.4/emacs.pyc b/test/bytecode_1.4/emacs.pyc new file mode 100644 index 0000000000000000000000000000000000000000..006737e170186a55f1fc7b35182845a7ea05954b GIT binary patch literal 809 zcmbtROHaZ;5S~8pQBb2XsYl{ziIK*{crzaL#DyCdQo4&Y(3b2hBqVAR_2>E{oLO3e zc%*5kvpcijW5*9qg3sb-kbr&gk$xq;hadq4lpKL{VBkO*fOO%THeD!BL3%d#pgafZ z+uR4)fW9~&1av6e*!Yn+;DQGz7&(Bl2?iK5d;-bb@^6wOy=Qslf+S)3rXAq!H=ct-vl_SdF0T}*ja`D1If#V_jF z^2GvVs+DY8bJuHyH6R{W<-`;IAO%(G${n9XX1^rU~_*?)CrOIy#n z@Mho6&d$8OKOgk(vhTT;UrV9CM!5l?5cw3Dqfs(TA~2fwT--_Apxgxj5@X0BwHohNIE6Ukcj6lmM$<~k-Wr+W|}ADyS7iC_Ni&zn{5{f z?LDVSM?v)*@HGJ=0sIv@XUlqJa##6Ao1w1Cx-kp0cD7m%N8`M(y3NU^^}A<4Muxh6q|ju;xr4c=SWS;#-5ibo_J=bVXJu9Rm6?PPoaF~IUR_uK diff --git a/test/bytecode_3.1_run/05_dict_comp.pyc b/test/bytecode_3.1_run/05_dict_comp.pyc new file mode 100644 index 0000000000000000000000000000000000000000..17657f4ada7565d88fce67f3b42c76d863adfad3 GIT binary patch literal 599 zcmbtRO-sW-5PiGGV2b)51ciW*_TsG+MZLyDZhjCXS!ryOjk{StAiZe+fxp(9Gh3*| zqb|(LWb)>{*~!)J-ry_1O@WQGMfoX(Jt8Q9C2$QW$^(1|RKQHa9-xzW7bqpNc$=7o zAmGDKNpVhL_X$eD8a;49?ODv<(lwji0*Z{nCIqBU)Vo96N-P8x61~8qpM=_Nh~8H| zC7wc3V>ic;uhIeQboZvSFI6{CZ@GV-jM$LE+T@ZgRqvsK;BRc^I2g&G#RZjG9% z##Xu+j!yEjD!QDjN&Dv5V9XUROhWGF`6CgDmFjvT`wtfudF8cwafnbjcF7;KPW=Wq wUYYy5=I`xAJTcXca{MpOtW~C?dtDl%&Ch^;+rY?1jEu~a)fnv=nI@+(#&9z+FfbH@2p%>7*jWep diff --git a/test/simple_source/comprehension/05_dict_comp.py b/test/simple_source/comprehension/05_dict_comp.py index 02b7460e..5461ce72 100644 --- a/test/simple_source/comprehension/05_dict_comp.py +++ b/test/simple_source/comprehension/05_dict_comp.py @@ -1,4 +1,7 @@ +# Bug was in dictionary comprehension involving "if not" # Issue #162 +# +# This code is RUNNABLE! def x(s): return {k: v for (k, v) in s diff --git a/uncompyle6/parsers/parse14.py b/uncompyle6/parsers/parse14.py new file mode 100644 index 00000000..7876223b --- /dev/null +++ b/uncompyle6/parsers/parse14.py @@ -0,0 +1,30 @@ +# Copyright (c) 2018 Rocky Bernstein + +from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG +from uncompyle6.parser import PythonParserSingle +from uncompyle6.parsers.parse15 import Python15Parser + +class Python14Parser(Python15Parser): + + def p_misc14(self, args): + """ + # Nothing here yet, but will need to add UNARY_CALL, BINARY_CALL, + # RAISE_EXCEPTION, BUILD_FUNCTION, UNPACK_ARG, UNPACK_VARARG, LOAD_LOCAL, + # SET_FUNC_ARGS, and RESERVE_FAST + """ + def __init__(self, debug_parser=PARSER_DEFAULT_DEBUG): + super(Python14Parser, self).__init__(debug_parser) + self.customized = {} + + +class Python14ParserSingle(Python14Parser, PythonParserSingle): + pass + +if __name__ == '__main__': + # Check grammar + p = Python14Parser() + p.check_grammar() + p.dump_grammar() + +# local variables: +# tab-width: 4 diff --git a/uncompyle6/parsers/parse15.py b/uncompyle6/parsers/parse15.py index 7a7183b6..159653a0 100644 --- a/uncompyle6/parsers/parse15.py +++ b/uncompyle6/parsers/parse15.py @@ -23,7 +23,7 @@ class Python15Parser(Python21Parser): importlist ::= IMPORT_FROM """ -class Python15ParserSingle(Python21Parser, PythonParserSingle): +class Python15ParserSingle(Python15Parser, PythonParserSingle): pass if __name__ == '__main__': diff --git a/uncompyle6/scanner.py b/uncompyle6/scanner.py index 410bda00..b0d3255e 100755 --- a/uncompyle6/scanner.py +++ b/uncompyle6/scanner.py @@ -37,7 +37,7 @@ from xdis.util import code2num # The byte code versions we support. # Note: these all have to be floats -PYTHON_VERSIONS = frozenset((1.5, +PYTHON_VERSIONS = frozenset((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)) diff --git a/uncompyle6/scanners/scanner14.py b/uncompyle6/scanners/scanner14.py new file mode 100644 index 00000000..ea719b38 --- /dev/null +++ b/uncompyle6/scanners/scanner14.py @@ -0,0 +1,27 @@ +# Copyright (c) 2018 by Rocky Bernstein +""" +Python 1.4 bytecode decompiler massaging. + +This massages tokenized 1.4 bytecode to make it more amenable for +grammar parsing. +""" + +import uncompyle6.scanners.scanner15 as scan +# from uncompyle6.scanners.scanner26 import ingest as ingest26 + +# bytecode verification, verify(), uses JUMP_OPs from here +from xdis.opcodes import opcode_14 +JUMP_OPS = opcode_14.JUMP_OPS + +# We base this off of 1.5 instead of the other way around +# because we cleaned things up this way. +# The history is that 2.7 support is the cleanest, +# then from that we got 2.6 and so on. +class Scanner14(scan.Scanner15): + def __init__(self, show_asm=False): + scan.Scanner15.__init__(self, show_asm) + self.opc = opcode_14 + self.opname = opcode_14.opname + self.version = 1.4 + self.genexpr_name = '' + return diff --git a/uncompyle6/scanners/scanner15.py b/uncompyle6/scanners/scanner15.py index 2b00b5bb..eb2525c6 100644 --- a/uncompyle6/scanners/scanner15.py +++ b/uncompyle6/scanners/scanner15.py @@ -1,6 +1,6 @@ -# Copyright (c) 2016-2017 by Rocky Bernstein +# Copyright (c) 2016-2018 by Rocky Bernstein """ -Python 1.5 bytecode decompiler scanner. +Python 1.5 bytecode decompiler massaging. This massages tokenized 1.5 bytecode to make it more amenable for grammar parsing. diff --git a/uncompyle6/scanners/scanner21.py b/uncompyle6/scanners/scanner21.py index efa6e4c8..e381a9ea 100644 --- a/uncompyle6/scanners/scanner21.py +++ b/uncompyle6/scanners/scanner21.py @@ -1,6 +1,6 @@ -# Copyright (c) 2016-2017 by Rocky Bernstein +# Copyright (c) 2016-2018 by Rocky Bernstein """ -Python 2.1 bytecode scanner/deparser +Python 2.1 bytecode massaging. This massages tokenized 2.1 bytecode to make it more amenable for grammar parsing. diff --git a/uncompyle6/scanners/scanner22.py b/uncompyle6/scanners/scanner22.py index 0b2cfbcb..cb75f25d 100644 --- a/uncompyle6/scanners/scanner22.py +++ b/uncompyle6/scanners/scanner22.py @@ -1,6 +1,6 @@ -# Copyright (c) 2016-2017 by Rocky Bernstein +# Copyright (c) 2016-2018 by Rocky Bernstein """ -Python 2.2 bytecode ingester. +Python 2.2 bytecode massaging. This massages tokenized 2.2 bytecode to make it more amenable for grammar parsing. diff --git a/uncompyle6/scanners/scanner23.py b/uncompyle6/scanners/scanner23.py index 9919b831..d009d95d 100644 --- a/uncompyle6/scanners/scanner23.py +++ b/uncompyle6/scanners/scanner23.py @@ -1,6 +1,6 @@ -# Copyright (c) 2016-2017 by Rocky Bernstein +# Copyright (c) 2016-2018 by Rocky Bernstein """ -Python 2.3 bytecode scanner/deparser +Python 2.3 bytecode massaging. This massages tokenized 2.3 bytecode to make it more amenable for grammar parsing. diff --git a/uncompyle6/scanners/scanner24.py b/uncompyle6/scanners/scanner24.py index b7ae220b..107a6d60 100755 --- a/uncompyle6/scanners/scanner24.py +++ b/uncompyle6/scanners/scanner24.py @@ -1,6 +1,6 @@ # Copyright (c) 2016-2017 by Rocky Bernstein """ -Python 2.4 bytecode scanner/deparser +Python 2.4 bytecode massaging. This massages tokenized 2.7 bytecode to make it more amenable for grammar parsing. diff --git a/uncompyle6/scanners/scanner25.py b/uncompyle6/scanners/scanner25.py index 3162388d..14a6c1c1 100755 --- a/uncompyle6/scanners/scanner25.py +++ b/uncompyle6/scanners/scanner25.py @@ -1,6 +1,6 @@ -# Copyright (c) 2015-2017 by Rocky Bernstein +# Copyright (c) 2015-2018 by Rocky Bernstein """ -Python 2.5 bytecode scanner/deparser +Python 2.5 bytecode massaging. This overlaps Python's 2.5's dis module, but it can be run from Python 3 and other versions of Python. Also, we save token