Start Python 2.1 bytecode decompile

This commit is contained in:
rocky
2016-10-07 22:42:30 -04:00
parent 2e1bd2dc13
commit 056f600da1
89 changed files with 128 additions and 31 deletions

View File

@@ -564,14 +564,18 @@ class SourceWalker(GenericASTTraversal, object):
TABLE_DIRECT.update({
'tryfinallystmt': ( '%|try:\n%+%c%-%|finally:\n%+%c%-\n\n', 1, 4 )
})
###########################
# Import style for 2.0-2.3
###########################
TABLE_DIRECT.update({
'importstmt20': ( '%|import %c\n', 1),
'importstar20': ( '%|from %[1]{pattr} import *\n', ),
'importfrom20': ( '%|from %[1]{pattr} import %c\n', 2 ),
'importlist20': ( '%C', (0, maxint, ', ') ),
if version == 2.1:
###########################
# Import style for 2.0-2.3
###########################
TABLE_DIRECT.update({
'importstmt2': ( '%|import %c\n', 1),
'import_as_cont': ( '%|import %c as %c\n', 1, 2),
'importstar2': ( '%|from %[1]{pattr} import *\n', ),
'importfrom2': ( '%|from %[1]{pattr} import %c\n', 2 ),
'importlist2': ( '%C', (0, maxint, ', ') ),
'IMPORT_NAME': ( '%{pattr}', ),
'IMPORT_NAME_CONT': ( '%{pattr}', ),
})
elif version >= 2.5:
@@ -1055,13 +1059,17 @@ class SourceWalker(GenericASTTraversal, object):
self.prune()
def n_import_as(self, node):
iname = node[0].pattr
if self.version == 2.1 and node == 'import_as_cont':
self.write("\n", self.indent, "import ")
iname = node[1].pattr if node[0] == 'LOAD_CONST' else node[0].pattr
assert node[-1][-1].type.startswith('STORE_')
sname = node[-1][-1].pattr # assume one of STORE_.... here
if iname == sname or iname.startswith(sname + '.'):
if iname and iname == sname or iname.startswith(sname + '.'):
self.write(iname)
else:
self.write(iname, ' as ', sname)
if self.version == 2.1 and node == 'import_as_cont':
self.write("\n")
self.prune() # stop recursing
n_import_as_cont = n_import_as
@@ -1794,7 +1802,6 @@ class SourceWalker(GenericASTTraversal, object):
"""
# self.println("----> ", startnode.type)
fmt = entry[0]
arg = 1
i = 0