From e116d7280cadfab77457f464f219cfbdb82d37aa Mon Sep 17 00:00:00 2001 From: rocky Date: Fri, 17 Nov 2017 12:06:14 -0500 Subject: [PATCH] custom rule hacking ... Reduce extraneous 3.x "load_list" and "load_closure" rules --- test/Makefile | 16 +++++++++++++-- test/bytecode_3.4/05_list_comprehension.pyc | Bin 344 -> 346 bytes uncompyle6/parsers/parse3.py | 21 +++++++++++++++----- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/test/Makefile b/test/Makefile index e5f7ba9b..ed4b2f5a 100644 --- a/test/Makefile +++ b/test/Makefile @@ -117,14 +117,26 @@ grammar-coverage-2.7: SPARK_PARSER_COVERAGE=/tmp/spark-grammar-27.cover $(PYTHON) test_pythonlib.py --bytecode-2.7 SPARK_PARSER_COVERAGE=/tmp/spark-grammar-27.cover $(PYTHON) test_pyenvlib.py --2.7.13 -#: Get grammar coverage for Python 3.4 +#: Get grammar coverage for Python 3.3 +grammar-coverage-3.3: + rm $(COVER_DIR)/spark-grammar-33.cover || /bin/true + SPARK_PARSER_COVERAGE=$(COVER_DIR)/spark-grammar-33.cover $(PYTHON) test_pythonlib.py --bytecode-3.3 + SPARK_PARSER_COVERAGE=$(COVER_DIR)/spark-grammar-33.cover $(PYTHON) test_pyenvlib.py --3.3.6 + +##: Get grammar coverage for Python 3.4 grammar-coverage-3.4: rm $(COVER_DIR)/spark-grammar-34.cover || /bin/true SPARK_PARSER_COVERAGE=$(COVER_DIR)/spark-grammar-34.cover $(PYTHON) test_pythonlib.py --bytecode-3.4 SPARK_PARSER_COVERAGE=$(COVER_DIR)/spark-grammar-34.cover $(PYTHON) test_pyenvlib.py --3.4.2 +##: Get grammar coverage for Python 3.5 +grammar-coverage-3.5: + rm $(COVER_DIR)/spark-grammar-35.cover || /bin/true + SPARK_PARSER_COVERAGE=$(COVER_DIR)/spark-grammar-35.cover $(PYTHON) test_pythonlib.py --bytecode-3.5 + SPARK_PARSER_COVERAGE=$(COVER_DIR)/spark-grammar-35.cover $(PYTHON) test_pyenvlib.py --3.5.2 + #: Check deparsing Python 2.6 -check-bytecode-2.6: +pcheck-bytecode-2.6: $(PYTHON) test_pythonlib.py --bytecode-2.6 --weak-verify #: Check deparsing Python 2.7 diff --git a/test/bytecode_3.4/05_list_comprehension.pyc b/test/bytecode_3.4/05_list_comprehension.pyc index 51943d101cec73191aa9356f5d35e833433afdef..297a2a693bc6d688f1c3d9136b8b8ba5975395fa 100644 GIT binary patch delta 44 scmcb?bc>1e9S<*8om*DKtBIUb#I1SjLf5AoarFs?i!02*Nl-T(jq delta 42 scmcb`bc2cW9S<*8>9O{(MH4yiaPu%QFcdQZ2~LKIAL2Q|Tp*7D01!F}{r~^~ diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index 9641e53c..9ceebe6a 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -694,12 +694,23 @@ class Python3Parser(PythonParser): self.add_unique_rule(rule, opname, token.attr, customize) elif opname_base in ('BUILD_LIST', 'BUILD_TUPLE', 'BUILD_SET'): v = token.attr - rule = ('build_list ::= ' + 'expr1024 ' * int(v//1024) + - 'expr32 ' * int((v//32) % 32) + - 'expr ' * (v % 32) + opname) - self.add_unique_rule(rule, opname, token.attr, customize) + + is_LOAD_CLOSURE = False if opname_base == 'BUILD_TUPLE': - rule = ('load_closure ::= %s%s' % (('LOAD_CLOSURE ' * v), opname)) + # If is part of a "load_closure", then it is not part of a + # "build_list". + is_LOAD_CLOSURE = True + for j in range(v): + if tokens[i-j-1].kind != 'LOAD_CLOSURE': + is_LOAD_CLOSURE = False + break + if is_LOAD_CLOSURE: + rule = ('load_closure ::= %s%s' % (('LOAD_CLOSURE ' * v), opname)) + self.add_unique_rule(rule, opname, token.attr, customize) + if not is_LOAD_CLOSURE: + rule = ('build_list ::= ' + 'expr1024 ' * int(v//1024) + + 'expr32 ' * int((v//32) % 32) + + 'expr ' * (v % 32) + opname) self.add_unique_rule(rule, opname, token.attr, customize) elif opname.startswith('BUILD_TUPLE_UNPACK_WITH_CALL'): v = token.attr