You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-02 16:44:46 +08:00
Pypy 3.3 tolerance and ...
Remove some duplicate grammar rules
This commit is contained in:
@@ -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
|
||||
|
||||
|
@@ -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):
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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):
|
||||
|
@@ -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
|
||||
|
23
uncompyle6/scanners/pypy33.py
Normal file
23
uncompyle6/scanners/pypy33.py
Normal file
@@ -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
|
@@ -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
|
||||
|
Reference in New Issue
Block a user