Fix bug in Python 3 lambda expression handling

Some other small cleanup changes
This commit is contained in:
rocky
2016-05-15 18:14:22 -04:00
parent bb31629c35
commit 2c121545f0
6 changed files with 27 additions and 8 deletions

Binary file not shown.

View File

@@ -0,0 +1,10 @@
# Bug in Python 3
# mklambda ::= LOAD_LAMBDA LOAD_CONST MAKE_FUNCTION_0
# _mklambda ::= mklambda
# expr ::= _mklambda
# kwarg ::= LOAD_CONST expr
# exprlist ::= exprlist expr
# call_function ::= expr kwarg CALL_FUNCTION_256
inspect.formatargvalues(formatvalue=lambda value: __file__)

View File

@@ -5,10 +5,10 @@ test_pyenvlib -- uncompyle and verify Python libraries
Usage-Examples:
test_pyenvlib --all # decompile all tests (suite + libs)
test_pyenvlib --all --verify # decomyile all tests and verify results
test_pyenvlib --test # decompile only the testsuite
test_pyenvlib --2.2 --verify # decompile and verify python lib 2.2
test_pyenvlib.py --all # decompile all tests (suite + libs)
test_pyenvlib.py --all --verify # decomyile all tests and verify results
test_pyenvlib.py --test # decompile only the testsuite
test_pyenvlib.py --2.7.11 --verify # decompile and verify python lib 2.7.11
Adding own test-trees:

View File

@@ -524,8 +524,9 @@ class Python3Parser(PythonParser):
rule = 'unpack_list ::= ' + opname + ' designator' * token.attr
elif opname_base.startswith('MAKE_FUNCTION'):
args_pos, args_kw, annotate_args = token.attr
self.addRule('mklambda ::= %sLOAD_LAMBDA %s' %
('pos_arg ' * args_pos, opname), nop_func)
rule = ('mklambda ::= %sLOAD_LAMBDA LOAD_CONST %s' %
('pos_arg '* args_pos, opname))
self.add_unique_rule(rule, opname, token.attr, customize)
if self.version > 3.2:
rule = ('mkfunc ::= %skwargs %s %s' %
('pos_arg ' * args_pos,

View File

@@ -43,12 +43,15 @@ class Scanner3(scan.Scanner):
## FIXME opnames should be passed in here
def __init__(self, version):
self.version = version
self.opnames = {} # will eventually get passed in
scan.Scanner.__init__(self, version)
## FIXME opnames should be moved to init
def disassemble3(self, co, opnames, classname=None, code_objects={}):
self.opnames = opnames # will eventually disasppear
# import dis; dis.disassemble(co) # DEBUG
# Container for tokens
@@ -829,7 +832,9 @@ class Scanner3(scan.Scanner):
if __name__ == "__main__":
import inspect
co = inspect.currentframe().f_code
tokens, customize = Scanner3().disassemble_generic(co)
from uncompyle6 import PYTHON_VERSION
from opcode import opname
tokens, customize = Scanner3(PYTHON_VERSION).disassemble3(co, opname)
for t in tokens:
print(t)
pass

View File

@@ -1605,7 +1605,10 @@ class SourceWalker(GenericASTTraversal, object):
pos_args = args_node.attr
pass
code = node[code_index].attr
if self.version > 3.0 and isLambda and iscode(node[-3].attr):
code = node[-3].attr
else:
code = node[code_index].attr
assert iscode(code)
code = Code(code, self.scanner, self.currentclass)