Closer to being able to handle Python 3.4 bytecode. Loading of Python

Python bytecode now works. magics from 3.3 to Python 3.4 has been added.
Some Python 3.4 scanner issues have been fixed.
This commit is contained in:
rocky
2015-12-14 14:55:32 -05:00
parent b5797dfa0f
commit 3e31f41552
4 changed files with 81 additions and 22 deletions

View File

@@ -17,12 +17,12 @@ from uncompyle6.scanner import Token
# Get all the opcodes into globals
globals().update(dis.opmap)
from uncompyle6.opcodes.opcode_27 import *
import scanner as scan
import uncompyle6.scanner as scan
class Scanner34(scan.Scanner):
def __init__(self):
self.Token = scan.Scanner.__init__(self, 2.7) # check
self.Token = scan.Scanner.__init__(self, 3.4) # check
def run(self, bytecode):
code_object = marshal.loads(bytecode)
@@ -60,8 +60,7 @@ class Scanner34(scan.Scanner):
op = code[offset]
# Create token and fill all the fields we can
# w/o touching arguments
current_token = Token()
current_token.type = dis.opname[op]
current_token = Token(dis.opname[op])
current_token.offset = offset
current_token.linestart = True if offset in self.linestarts else False
if op >= dis.HAVE_ARGUMENT:
@@ -135,6 +134,16 @@ class Scanner34(scan.Scanner):
for _ in range(self.op_size(op)):
self.prev_op.append(offset)
def op_size(self, op):
"""
Return size of operator with its arguments
for given opcode <op>.
"""
if op < dis.HAVE_ARGUMENT:
return 1
else:
return 3
def find_jump_targets(self):
"""
Detect all offsets in a byte code which are jump targets.