diff --git a/pytest/testdata/if-2.7.right b/pytest/testdata/if-2.7.right index 8c258cad..55a2f970 100644 --- a/pytest/testdata/if-2.7.right +++ b/pytest/testdata/if-2.7.right @@ -1,12 +1,12 @@ # Python 2.7 # Embedded file name: simple_source/branching/05_if.py - 6 0 LOAD_NAME 0 'True' - 3 POP_JUMP_IF_FALSE 15 '15' + 6 0 LOAD_NAME 0 'True' + 3 POP_JUMP_IF_FALSE 15 'to 15' - 7 6 LOAD_NAME 1 'False' - 9 STORE_NAME 2 'b' - 12 JUMP_FORWARD 0 '15' - 15_0 COME_FROM '12' - 15 LOAD_CONST 0 None - 18 RETURN_VALUE + 7 6 LOAD_NAME 1 'False' + 9 STORE_NAME 2 'b' + 12 JUMP_FORWARD 0 'to 15' + 15_0 COME_FROM '12' + 15 LOAD_CONST 0 '' + 18 RETURN_VALUE '' diff --git a/pytest/testdata/ifelse-2.7.right b/pytest/testdata/ifelse-2.7.right index 1f58e666..cb8f8999 100644 --- a/pytest/testdata/ifelse-2.7.right +++ b/pytest/testdata/ifelse-2.7.right @@ -1,15 +1,15 @@ # Python 2.7 # Embedded file name: simple_source/branching/05_ifelse.py - 3 0 LOAD_NAME 0 'True' - 3 POP_JUMP_IF_FALSE 15 '15' + 3 0 LOAD_NAME 0 'True' + 3 POP_JUMP_IF_FALSE 15 'to 15' - 4 6 LOAD_CONST 0 1 - 9 STORE_NAME 1 'b' - 12 JUMP_FORWARD 6 '21' + 4 6 LOAD_CONST 0 1 + 9 STORE_NAME 1 'b' + 12 JUMP_FORWARD 6 'to 21' - 6 15 LOAD_CONST 1 2 - 18 STORE_NAME 2 'd' - 21_0 COME_FROM '12' - 21 LOAD_CONST 2 None - 24 RETURN_VALUE + 6 15 LOAD_CONST 1 2 + 18 STORE_NAME 2 'd' + 21_0 COME_FROM '12' + 21 LOAD_CONST 2 '' + 24 RETURN_VALUE '' diff --git a/uncompyle6/scanners/scanner2.py b/uncompyle6/scanners/scanner2.py index 1778a42e..8f7baa82 100755 --- a/uncompyle6/scanners/scanner2.py +++ b/uncompyle6/scanners/scanner2.py @@ -219,10 +219,12 @@ class Scanner2(scan.Scanner): if offset not in replace: tokens.append(Token( - opname, oparg, pattr, offset, linestart, op, has_arg)) + opname, oparg, pattr, offset, linestart, op, + has_arg, self.opc)) else: tokens.append(Token( - replace[offset], oparg, pattr, offset, linestart, op, has_arg)) + replace[offset], oparg, pattr, offset, linestart, + op, has_arg, self.opc)) pass pass diff --git a/uncompyle6/scanners/scanner26.py b/uncompyle6/scanners/scanner26.py index 2dca3683..cb05beb9 100755 --- a/uncompyle6/scanners/scanner26.py +++ b/uncompyle6/scanners/scanner26.py @@ -284,10 +284,12 @@ class Scanner26(scan.Scanner2): if offset not in replace: tokens.append(Token( - op_name, oparg, pattr, offset, linestart, op, has_arg)) + op_name, oparg, pattr, offset, linestart, op, + has_arg, self.opc)) else: tokens.append(Token( - replace[offset], oparg, pattr, offset, linestart, op, has_arg)) + replace[offset], oparg, pattr, offset, linestart, op, + has_arg, self.opc)) pass pass diff --git a/uncompyle6/scanners/scanner3.py b/uncompyle6/scanners/scanner3.py index bb1eb5f4..9e645ed6 100644 --- a/uncompyle6/scanners/scanner3.py +++ b/uncompyle6/scanners/scanner3.py @@ -179,7 +179,7 @@ class Scanner3(scan.Scanner): for jump_offset in jump_targets[inst.offset]: tokens.append(Token('COME_FROM', None, repr(jump_offset), offset='%s_%s' % (inst.offset, jump_idx), - has_arg = True)) + has_arg = True, opc=self.opc)) jump_idx += 1 pass pass @@ -229,7 +229,8 @@ class Scanner3(scan.Scanner): offset = inst.offset, linestart = inst.starts_line, op = op, - has_arg = (op >= op3.HAVE_ARGUMENT) + has_arg = (op >= op3.HAVE_ARGUMENT), + opc = self.opc ) ) continue @@ -290,7 +291,8 @@ class Scanner3(scan.Scanner): offset = inst.offset, linestart = inst.starts_line, op = op, - has_arg = (op >= op3.HAVE_ARGUMENT) + has_arg = (op >= op3.HAVE_ARGUMENT), + opc = self.opc ) ) pass diff --git a/uncompyle6/scanners/tok.py b/uncompyle6/scanners/tok.py index 13615468..ae20cd40 100644 --- a/uncompyle6/scanners/tok.py +++ b/uncompyle6/scanners/tok.py @@ -21,7 +21,7 @@ class Token: # attr = argval # pattr = argrepr def __init__(self, type_, attr=None, pattr=None, offset=-1, - linestart=None, op=None, has_arg=None): + linestart=None, op=None, has_arg=None, opc=None): self.type = intern(type_) self.op = op self.has_arg = has_arg @@ -29,6 +29,7 @@ class Token: self.pattr = pattr self.offset = offset self.linestart = linestart + self.opc = opc def __eq__(self, o): """ '==', but it's okay if offsets and linestarts are different""" @@ -49,13 +50,22 @@ class Token: ('%9s %-18s %r' % (self.offset, self.type, pattr))) def format(self): - prefix = '\n%3d ' % self.linestart if self.linestart else (' ' * 6) - offset_opname = '%9s %-18s' % (self.offset, self.type) + prefix = '\n%4d ' % self.linestart if self.linestart else (' ' * 6) + offset_opname = '%6s %-17s' % (self.offset, self.type) argstr = "%6d " % self.attr if isinstance(self.attr, int) else (' '*7) - if self.has_arg: - return "%s%s%s %r" % (prefix, offset_opname, argstr, self.pattr) + if self.pattr: + pattr = self.pattr + if self.opc: + if self.op in self.opc.hasjrel: + pattr = "to " + self.pattr + elif self.op in self.opc.hasjabs: + pattr = "to " + self.pattr + pass + # And so on. See xdis/bytecode.py + pass else: - return "%s%s" % (prefix, offset_opname) + pattr = '' + return "%s%s%s %r" % (prefix, offset_opname, argstr, pattr) def __hash__(self): return hash(self.type)