Merge branch 'master' into python-2.4

This commit is contained in:
rocky
2018-09-20 17:40:46 -04:00
9 changed files with 74 additions and 16 deletions

View File

@@ -4,11 +4,11 @@ about: Tell us about uncompyle6 bugs
---
__Note:__ Have you read https://github.com/rocky/python-uncompyle6/blob/master/HOW-TO-REPORT-A-BUG.md ?
<!-- __Note:__ Have you read https://github.com/rocky/python-uncompyle6/blob/master/HOW-TO-REPORT-A-BUG.md ?
Please remove any of the optional sections if they are not applicable.
## Prerequisites
Prerequisites
* Make sure the bytecode you have can be disassembled with a
disassembler.
@@ -27,13 +27,15 @@ assistance
http://www.crazy-compilers.com/decompyle/ offers a byte-code
decompiler service for versions of Python up to 2.6.
-->
## Description
Replace this text with a clear and concise description of the bug.
<!-- Replace this text with a clear and concise description of the bug. -->
## How to Reproduce
Please show both the input you gave and the
<!-- Please show both the input you gave and the
output you got in describing how to reproduce the bug:
or give a complete console log with input and output
@@ -47,13 +49,15 @@ $
If there is a Solidity source code, a truffle project, or bytecode
that is involved, please provide that or links to it.
-->
## Expected behavior
A clear and concise description of what you expected to happen.
<!-- A clear and concise description of what you expected to happen. -->
## Environment
_This section sometimes is optional but helpful to us._
<!-- _This section sometimes is optional but helpful to us._
Please modify for your setup
@@ -61,8 +65,12 @@ Please modify for your setup
- Python version: `python -V`
- OS and Version: [e.g. Ubuntu bionic]
-->
## Additional Environment or Context
_This section is optional._
<!-- _This section is optional._
Add any other context about the problem here or special environment setup.
-->

View File

@@ -6,16 +6,17 @@ about: Tell us about a new feature that you would like to see in uncompyle6
## Description
Replace this text with a short description of the feature. This might
include same input and output.
<!-- Replace this text with a short description of the feature. This might
include same input and output. -->
## Background
Replace this text with any additional background for the
feature, for example: user scenarios, or the value of the feature.
<!-- Replace this text with any additional background for the
feature, for example: user scenarios, or the value of the feature. -->
## Tests
_This section is optional._
<!-- _This section is optional._
Replace this text with suggestions on how to test the feature,
if it is not obvious.
-->

Binary file not shown.

View File

@@ -1,4 +1,8 @@
# We have more than 1<<16 elements
# In Python2 this causes an EXTENDED_ARG instruction to be emitted and then we can check
# handling that.
# It also triggers the of special rules for expr32 and expr1024
[
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,11,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,11,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,11,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,11,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,

View File

@@ -42,6 +42,11 @@ class PythonParser(GenericASTBuilder):
def __init__(self, SyntaxTree, start, debug):
super(PythonParser, self).__init__(SyntaxTree, start, debug)
# FIXME: customize per python parser version
# These are the non-terminals we should collect into a list.
# For example instead of:
# stmts -> stmts stmt -> stmts stmt stmt ...
# collect as stmts -> stmt stmt ...
nt_list = [
'stmts', 'except_stmts', '_stmts', 'attributes',
'exprlist', 'kvlist', 'kwargs', 'come_froms', '_come_froms',

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2015-2017 Rocky Bernstein
# Copyright (c) 2015-2018 Rocky Bernstein
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
#
# Copyright (c) 1999 John Aycock
@@ -292,8 +292,20 @@ class Python2Parser(PythonParser):
# The order of opname listed is roughly sorted below
if opname_base in ('BUILD_LIST', 'BUILD_SET', 'BUILD_TUPLE'):
# We do this complicated test to speed up parsing of
# pathelogically long literals, especially those over 1024.
build_count = token.attr
thousands = (build_count//1024)
thirty32s = ((build_count//32) % 32)
if thirty32s > 0:
rule = "expr32 ::=%s" % (' expr' * 32)
self.add_unique_rule(rule, opname_base, build_count, customize)
if thousands > 0:
self.add_unique_rule("expr1024 ::=%s" % (' expr32' * 32),
opname_base, build_count, customize)
collection = opname_base[opname_base.find('_')+1:].lower()
rule = '%s ::= %s%s' % (collection, (token.attr * 'expr '), opname)
rule = (('%s ::= ' % collection) + 'expr1024 '*thousands +
'expr32 '*thirty32s + 'expr '*(build_count % 32) + opname)
self.add_unique_rules([
"expr ::= %s" % collection,
rule], customize)

View File

@@ -710,11 +710,26 @@ class Python3Parser(PythonParser):
rule = ('load_closure ::= %s%s' % (('LOAD_CLOSURE ' * v), opname))
self.add_unique_rule(rule, opname, token.attr, customize)
if not is_LOAD_CLOSURE or v == 0:
# We do this complicated test to speed up parsing of
# pathelogically long literals, especially those over 1024.
build_count = token.attr
thousands = (build_count//1024)
thirty32s = ((build_count//32) % 32)
if thirty32s > 0:
rule = "expr32 ::=%s" % (' expr' * 32)
self.add_unique_rule(rule, opname_base, build_count, customize)
pass
if thousands > 0:
self.add_unique_rule("expr1024 ::=%s" % (' expr32' * 32),
opname_base, build_count, customize)
pass
collection = opname_base[opname_base.find('_')+1:].lower()
rule = '%s ::= %s%s' % (collection, 'expr ' * v, opname)
rule = (('%s ::= ' % collection) + 'expr1024 '*thousands +
'expr32 '*thirty32s + 'expr '*(build_count % 32) + opname)
self.add_unique_rules([
'expr ::= %s' % collection,
"expr ::= %s" % collection,
rule], customize)
continue
continue
elif opname_base == 'BUILD_SLICE':
if token.attr == 2:

View File

@@ -110,6 +110,17 @@ class Scanner2(Scanner):
@staticmethod
def extended_arg_val(arg):
"""Return integer value of an EXTENDED_ARG operand.
In Python2 this always the operand value shifted 16 bits since
the operand is always 2 bytes. In Python 3.6+ this changes to one byte.
"""
if PYTHON3:
return (arg << 16)
else:
return (arg << long(16))
@staticmethod
def unmangle_name(name, classname):
"""Remove __ from the end of _name_ if it starts with __classname__

View File

@@ -148,10 +148,12 @@ def flatten_list(node):
for elem in node:
if elem == 'expr1024':
for subelem in elem:
assert subelem == 'expr32'
for subsubelem in subelem:
flat_elems.append(subsubelem)
elif elem == 'expr32':
for subelem in elem:
assert subelem == 'expr'
flat_elems.append(subelem)
else:
flat_elems.append(elem)