You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
Python 3.4 if ifelse decompyling now works.
This commit is contained in:
BIN
test/bytecode_2.7/keyword.pyc
Normal file
BIN
test/bytecode_2.7/keyword.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.7/positional.pyc
Normal file
BIN
test/bytecode_2.7/positional.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.2/for.cpython-32.pyc
Normal file
BIN
test/bytecode_3.2/for.cpython-32.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.2/if.cpython-32.pyc
Normal file
BIN
test/bytecode_3.2/if.cpython-32.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.2/ifelse.cpython-32.pyc
Normal file
BIN
test/bytecode_3.2/ifelse.cpython-32.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.2/keyword.cpython-32.pyc
Normal file
BIN
test/bytecode_3.2/keyword.cpython-32.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.2/positional.cpython-32.pyc
Normal file
BIN
test/bytecode_3.2/positional.cpython-32.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.2/while.cpython-32.pyc
Normal file
BIN
test/bytecode_3.2/while.cpython-32.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/keyword.cpython-34.pyc
Normal file
BIN
test/bytecode_3.4/keyword.cpython-34.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/positional.python-34.pyc
Normal file
BIN
test/bytecode_3.4/positional.python-34.pyc
Normal file
Binary file not shown.
@@ -55,17 +55,19 @@ tests['2.5'] = tests['2.3']
|
|||||||
tests['2.6'] = tests['2.5']
|
tests['2.6'] = tests['2.5']
|
||||||
# tests['2.7'] = ['mine'] + tests['2.6']
|
# tests['2.7'] = ['mine'] + tests['2.6']
|
||||||
tests['2.7'] = [
|
tests['2.7'] = [
|
||||||
'source_3.4/branching/ifelse',
|
'simple-source/branching/ifelse',
|
||||||
'source_3.4/branching/if'
|
'simple-source/branching/if'
|
||||||
# 'source_3.4/call_arguments/keyword',
|
# 'simple-source/call_arguments/keyword',
|
||||||
# 'source_3.4/call_arguments/positional'
|
# 'simple-source/call_arguments/positional'
|
||||||
]
|
]
|
||||||
|
|
||||||
tests['3.4'] = [
|
tests['3.4'] = [
|
||||||
# 'source_3.4/branching/ifelse',
|
# 'simple-source/branching/ifelse',
|
||||||
# 'source_3.4/branching/if'
|
# 'simple-source/branching/if'
|
||||||
'source_3.4/call_arguments/keyword',
|
# 'simple-source/call_arguments/keyword',
|
||||||
'source_3.4/call_arguments/positional'
|
# 'simple-source/call_arguments/positional'
|
||||||
|
'simple-source/looping/for',
|
||||||
|
'simple-source/looping/while'
|
||||||
]
|
]
|
||||||
|
|
||||||
total_tests = len(tests['2.7'])
|
total_tests = len(tests['2.7'])
|
7
test/simple-source/README
Normal file
7
test/simple-source/README
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
Files in this directory contain very simnple constructs that work
|
||||||
|
across all versions of Python.
|
||||||
|
|
||||||
|
Their simnplicity is to try to make it easier to debug grammar
|
||||||
|
and AST walking routines.
|
||||||
|
|
||||||
|
This code originally taken from https://github.com/DarkFenX/uncompyle3
|
1
test/simple-source/call_arguments/keyword.py
Normal file
1
test/simple-source/call_arguments/keyword.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
a = b(c=d, e=f)
|
1
test/simple-source/call_arguments/positional.py
Normal file
1
test/simple-source/call_arguments/positional.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
a(b, c)
|
2
test/simple-source/looping/for.py
Normal file
2
test/simple-source/looping/for.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
for a in b:
|
||||||
|
c = d
|
2
test/simple-source/looping/while.py
Normal file
2
test/simple-source/looping/while.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
while a:
|
||||||
|
b = c
|
@@ -3,7 +3,7 @@
|
|||||||
# Copyright (c) 2005 by Dan Pascu <dan@windowmaker.org>
|
# Copyright (c) 2005 by Dan Pascu <dan@windowmaker.org>
|
||||||
# Copyright (c) 2015 Rocky Bernstein
|
# Copyright (c) 2015 Rocky Bernstein
|
||||||
#
|
#
|
||||||
# See main module for license.
|
# See LICENSE for lisence
|
||||||
"""
|
"""
|
||||||
A spark grammar for Python 2.x.
|
A spark grammar for Python 2.x.
|
||||||
|
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
# Copyright (c) 2005 by Dan Pascu <dan@windowmaker.org>
|
# Copyright (c) 2005 by Dan Pascu <dan@windowmaker.org>
|
||||||
# Copyright (c) 2015 Rocky Bernstein
|
# Copyright (c) 2015 Rocky Bernstein
|
||||||
#
|
#
|
||||||
# See main module for license.
|
# See LICENSE for license
|
||||||
"""
|
"""
|
||||||
A spark grammar for Python 3.x.
|
A spark grammar for Python 3.x.
|
||||||
|
|
||||||
|
@@ -306,6 +306,7 @@ class GenericParser:
|
|||||||
|
|
||||||
def makeState(self, state, sym):
|
def makeState(self, state, sym):
|
||||||
assert sym is not None
|
assert sym is not None
|
||||||
|
# print(sym) # debug
|
||||||
#
|
#
|
||||||
# Compute \epsilon-kernel state's core and see if
|
# Compute \epsilon-kernel state's core and see if
|
||||||
# it exists already.
|
# it exists already.
|
||||||
@@ -554,7 +555,7 @@ class GenericParser:
|
|||||||
rule = self.ambiguity(self.newrules[nt])
|
rule = self.ambiguity(self.newrules[nt])
|
||||||
else:
|
else:
|
||||||
rule = self.newrules[nt][0]
|
rule = self.newrules[nt][0]
|
||||||
# print(rule)
|
# print(rule) # debug
|
||||||
|
|
||||||
rhs = rule[1]
|
rhs = rule[1]
|
||||||
attr = [None] * len(rhs)
|
attr = [None] * len(rhs)
|
||||||
@@ -573,7 +574,7 @@ class GenericParser:
|
|||||||
rule = choices[0]
|
rule = choices[0]
|
||||||
if len(choices) > 1:
|
if len(choices) > 1:
|
||||||
rule = self.ambiguity(choices)
|
rule = self.ambiguity(choices)
|
||||||
# print(rule)
|
# print(rule) # debug
|
||||||
|
|
||||||
rhs = rule[1]
|
rhs = rule[1]
|
||||||
attr = [None] * len(rhs)
|
attr = [None] * len(rhs)
|
||||||
|
@@ -37,9 +37,24 @@ class Scanner34(scan.Scanner):
|
|||||||
return fn(co)
|
return fn(co)
|
||||||
|
|
||||||
def disassemble_built_in(self, co):
|
def disassemble_built_in(self, co):
|
||||||
bytecode = dis.Bytecode(co)
|
# Container for tokens
|
||||||
tokens = []
|
tokens = []
|
||||||
|
self.code = co.co_code
|
||||||
|
self.build_lines_data(co)
|
||||||
|
self.build_prev_op()
|
||||||
|
# Get jump targets
|
||||||
|
# Format: {target offset: [jump offsets]}
|
||||||
|
jump_targets = self.find_jump_targets()
|
||||||
|
bytecode = dis.Bytecode(co)
|
||||||
for inst in bytecode:
|
for inst in bytecode:
|
||||||
|
if inst.offset in jump_targets:
|
||||||
|
jump_idx = 0
|
||||||
|
for jump_offset in jump_targets[inst.offset]:
|
||||||
|
tokens.append(Token('COME_FROM', None, repr(jump_offset),
|
||||||
|
offset='%s_%s' % (inst.offset, jump_idx)))
|
||||||
|
jump_idx += 1
|
||||||
|
pass
|
||||||
|
pass
|
||||||
tokens.append(
|
tokens.append(
|
||||||
Token(
|
Token(
|
||||||
type_ = inst.opname,
|
type_ = inst.opname,
|
||||||
@@ -60,7 +75,6 @@ class Scanner34(scan.Scanner):
|
|||||||
"""
|
"""
|
||||||
# Container for tokens
|
# Container for tokens
|
||||||
tokens = []
|
tokens = []
|
||||||
customize = {}
|
|
||||||
self.code = code = co.co_code
|
self.code = code = co.co_code
|
||||||
codelen = len(code)
|
codelen = len(code)
|
||||||
self.build_lines_data(co)
|
self.build_lines_data(co)
|
||||||
@@ -116,7 +130,7 @@ class Scanner34(scan.Scanner):
|
|||||||
free = co.co_cellvars + co.co_freevars
|
free = co.co_cellvars + co.co_freevars
|
||||||
current_token.pattr = free[oparg]
|
current_token.pattr = free[oparg]
|
||||||
tokens.append(current_token)
|
tokens.append(current_token)
|
||||||
return tokens, customize
|
return tokens, {}
|
||||||
|
|
||||||
def build_lines_data(self, code_obj):
|
def build_lines_data(self, code_obj):
|
||||||
"""
|
"""
|
||||||
|
Reference in New Issue
Block a user