Start Python 1.4 decompilation ...

Tidy up test code for issue 162 and comments for some disassembly massaging.
This commit is contained in:
rocky
2018-05-19 07:06:55 -04:00
parent e5ae70bea8
commit e5f3d803a8
16 changed files with 73 additions and 13 deletions

BIN
test/bytecode_1.4/emacs.pyc Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -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

View File

@@ -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

View File

@@ -23,7 +23,7 @@ class Python15Parser(Python21Parser):
importlist ::= IMPORT_FROM
"""
class Python15ParserSingle(Python21Parser, PythonParserSingle):
class Python15ParserSingle(Python15Parser, PythonParserSingle):
pass
if __name__ == '__main__':

View File

@@ -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))

View File

@@ -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 = '<generator expression>'
return

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -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