diff --git a/uncompyle6/parsers/parse27.py b/uncompyle6/parsers/parse27.py index 9bc8bf51..e63f7f69 100644 --- a/uncompyle6/parsers/parse27.py +++ b/uncompyle6/parsers/parse27.py @@ -41,8 +41,6 @@ class Python27Parser(Python2Parser): comp_body ::= set_comp_body comp_for ::= expr for_iter store comp_iter JUMP_BACK - comp_iter ::= comp_body - dict_comp_body ::= expr expr MAP_ADD set_comp_body ::= expr SET_ADD diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index 3b9beb2b..c0e3a535 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -86,10 +86,8 @@ class Python3Parser(PythonParser): dict_comp_func ::= BUILD_MAP_0 LOAD_FAST FOR_ITER store comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST - comp_iter ::= comp_if comp_iter ::= comp_if_not comp_if_not ::= expr jmp_true comp_iter - comp_iter ::= comp_body """ def p_grammar(self, args): diff --git a/uncompyle6/parsers/parse32.py b/uncompyle6/parsers/parse32.py index ea18dbba..0f3bbc16 100644 --- a/uncompyle6/parsers/parse32.py +++ b/uncompyle6/parsers/parse32.py @@ -8,9 +8,15 @@ from uncompyle6.parser import PythonParserSingle from uncompyle6.parsers.parse3 import Python3Parser class Python32Parser(Python3Parser): + def p_30to33(self, args): + """ + # Store locals is only in Python 3.0 to 3.3 + stmt ::= store_locals + store_locals ::= LOAD_FAST STORE_LOCALS + """ + def p_32to35(self, args): """ - expr ::= conditional conditional ::= expr jmp_false expr jump_forward_else expr COME_FROM # compare_chained2 is used in a "chained_compare": x <= y <= z @@ -18,10 +24,6 @@ class Python32Parser(Python3Parser): compare_chained2 ::= expr COMPARE_OP RETURN_VALUE compare_chained2 ::= expr COMPARE_OP RETURN_VALUE_LAMBDA - # Store locals is only in Python 3.0 to 3.3 - stmt ::= store_locals - store_locals ::= LOAD_FAST STORE_LOCALS - # Python < 3.5 no POP BLOCK whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK COME_FROM_LOOP diff --git a/uncompyle6/parsers/parse33.py b/uncompyle6/parsers/parse33.py index 46b7c8d2..8135db87 100644 --- a/uncompyle6/parsers/parse33.py +++ b/uncompyle6/parsers/parse33.py @@ -14,23 +14,6 @@ class Python33Parser(Python32Parser): # Python 3.3+ adds yield from. expr ::= yield_from yield_from ::= expr expr YIELD_FROM - - # We do the grammar hackery below for semantics - # actions that want c_stmts_opt at index 1 - - # Python 3.5+ has jump optimization to remove the redundant - # jump_excepts. But in 3.3 we need them added - - try_except ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK - except_handler - jump_excepts come_from_except_clauses - """ - - def p_30to33(self, args): - """ - # Store locals is only in Python 3.0 to 3.3 - stmt ::= store_locals - store_locals ::= LOAD_FAST STORE_LOCALS """ def customize_grammar_rules(self, tokens, customize): diff --git a/uncompyle6/scanners/pypy32.py b/uncompyle6/scanners/pypy32.py index 232c168b..657e1580 100644 --- a/uncompyle6/scanners/pypy32.py +++ b/uncompyle6/scanners/pypy32.py @@ -9,8 +9,8 @@ make things easier for decompilation. import uncompyle6.scanners.scanner32 as scan # bytecode verification, verify(), uses JUMP_OPs from here -from xdis.opcodes import opcode_32 as opc # is this right? -JUMP_OPs = map(lambda op: opc.opname[op], opc.hasjrel + opc.hasjabs) +from xdis.opcodes import opcode_32pypy as opc +JUMP_OPs = opc.JUMP_OPS # We base this off of 3.2 class ScannerPyPy32(scan.Scanner32): @@ -19,4 +19,5 @@ class ScannerPyPy32(scan.Scanner32): # pypy 3.2 and 3.2 scan.Scanner32.__init__(self, show_asm, is_pypy=True) self.version = 3.2 + self.opc = opc return diff --git a/uncompyle6/scanners/pypy33.py b/uncompyle6/scanners/pypy33.py new file mode 100644 index 00000000..818f8f0e --- /dev/null +++ b/uncompyle6/scanners/pypy33.py @@ -0,0 +1,23 @@ +# Copyright (c) 2019 by Rocky Bernstein +""" +Python PyPy 3.3 decompiler scanner. + +Does some additional massaging of xdis-disassembled instructions to +make things easier for decompilation. +""" + +import uncompyle6.scanners.scanner33 as scan + +# bytecode verification, verify(), uses JUMP_OPs from here +from xdis.opcodes import opcode_33pypy as opc +JUMP_OPs = map(lambda op: opc.opname[op], opc.hasjrel + opc.hasjabs) + +# We base this off of 3.3 +class ScannerPyPy33(scan.Scanner33): + def __init__(self, show_asm): + # There are no differences in initialization between + # pypy 3.3 and 3.3 + scan.Scanner33.__init__(self, show_asm, is_pypy=True) + self.version = 3.3 + self.opc = opc + return diff --git a/uncompyle6/scanners/scanner33.py b/uncompyle6/scanners/scanner33.py index 564ba300..63f01fdc 100644 --- a/uncompyle6/scanners/scanner33.py +++ b/uncompyle6/scanners/scanner33.py @@ -1,4 +1,4 @@ -# Copyright (c) 2015-2018 by Rocky Bernstein +# Copyright (c) 2015-2019 by 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 @@ -28,7 +28,7 @@ JUMP_OPS = opc.JUMP_OPS from uncompyle6.scanners.scanner3 import Scanner3 class Scanner33(Scanner3): - def __init__(self, show_asm=False): + def __init__(self, show_asm=False, is_pypy=False): Scanner3.__init__(self, 3.3, show_asm) return pass