Python 3.4 if ifelse decompyling now works.

This commit is contained in:
rocky
2015-12-17 08:10:43 -05:00
parent 2dc8375ed0
commit 87a3c5d687
24 changed files with 45 additions and 15 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

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

View 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

View File

@@ -0,0 +1 @@
a = b(c=d, e=f)

View File

@@ -0,0 +1 @@
a(b, c)

View File

@@ -0,0 +1,2 @@
for a in b:
c = d

View File

@@ -0,0 +1,2 @@
while a:
b = c

View File

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

View File

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

View File

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

View File

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