diff --git a/test/add-test.py b/test/add-test.py index 85a64022..09ed8211 100755 --- a/test/add-test.py +++ b/test/add-test.py @@ -9,4 +9,5 @@ version = sys.version[0:3] cfile = "bytecode_%s/%s" % (version, short) + 'c' print("byte-compiling %s to %s" % (path, cfile)) py_compile.compile(path, cfile) -os.system("../bin/uncompyle6 -a -t %s" % cfile) +if sys.version >= (2, 6, 0): + os.system("../bin/uncompyle6 -a -t %s" % cfile) diff --git a/test/bytecode_2.5/00_assign.pyc b/test/bytecode_2.5/00_assign.pyc new file mode 100644 index 00000000..e1ef8cd9 Binary files /dev/null and b/test/bytecode_2.5/00_assign.pyc differ diff --git a/test/bytecode_2.5/00_import.pyc b/test/bytecode_2.5/00_import.pyc new file mode 100644 index 00000000..c73f03f7 Binary files /dev/null and b/test/bytecode_2.5/00_import.pyc differ diff --git a/test/bytecode_2.5/00_pass.pyc b/test/bytecode_2.5/00_pass.pyc new file mode 100644 index 00000000..bde60dc2 Binary files /dev/null and b/test/bytecode_2.5/00_pass.pyc differ diff --git a/test/bytecode_2.5/01_class.pyc b/test/bytecode_2.5/01_class.pyc new file mode 100644 index 00000000..3183b027 Binary files /dev/null and b/test/bytecode_2.5/01_class.pyc differ diff --git a/test/bytecode_2.5/01_list_comprehension.pyc b/test/bytecode_2.5/01_list_comprehension.pyc new file mode 100644 index 00000000..adb300b7 Binary files /dev/null and b/test/bytecode_2.5/01_list_comprehension.pyc differ diff --git a/test/bytecode_2.5/02_def.pyc b/test/bytecode_2.5/02_def.pyc new file mode 100644 index 00000000..cd98701c Binary files /dev/null and b/test/bytecode_2.5/02_def.pyc differ diff --git a/test/bytecode_2.5/03_if_elif.pyc b/test/bytecode_2.5/03_if_elif.pyc new file mode 100644 index 00000000..7ab22f03 Binary files /dev/null and b/test/bytecode_2.5/03_if_elif.pyc differ diff --git a/test/bytecode_2.5/06_list_ifnot.pyc b/test/bytecode_2.5/06_list_ifnot.pyc new file mode 100644 index 00000000..8516184a Binary files /dev/null and b/test/bytecode_2.5/06_list_ifnot.pyc differ diff --git a/test/bytecode_2.5/06_list_ifnot_and.pyc b/test/bytecode_2.5/06_list_ifnot_and.pyc new file mode 100644 index 00000000..f2ae4037 Binary files /dev/null and b/test/bytecode_2.5/06_list_ifnot_and.pyc differ diff --git a/test/bytecode_2.5/11-list-if.pyc b/test/bytecode_2.5/11-list-if.pyc new file mode 100644 index 00000000..d899d476 Binary files /dev/null and b/test/bytecode_2.5/11-list-if.pyc differ diff --git a/test/bytecode_2.6/05_with.pyc b/test/bytecode_2.6/05_with.pyc new file mode 100644 index 00000000..5845d4ce Binary files /dev/null and b/test/bytecode_2.6/05_with.pyc differ diff --git a/test/simple_source/stmts/05_with.py b/test/simple_source/stmts/05_with.py index eb098c80..74706b8f 100644 --- a/test/simple_source/stmts/05_with.py +++ b/test/simple_source/stmts/05_with.py @@ -1,2 +1,3 @@ +from __future__ import with_statement with (sys) as f: print(f) diff --git a/uncompyle6/parser.py b/uncompyle6/parser.py index 59671e2f..583d192f 100644 --- a/uncompyle6/parser.py +++ b/uncompyle6/parser.py @@ -592,12 +592,11 @@ def get_python_parser(version, debug_parser, compile_mode='exec'): else: p = parse23.Python23ParserSingle(debug_parser) elif version == 2.5: - # For now, we'll consider 2.5 exactly like 2.6 - import uncompyle6.parsers.parse26 as parse25 + import uncompyle6.parsers.parse25 as parse25 if compile_mode == 'exec': - p = parse25.Python26Parser(debug_parser) + p = parse25.Python25Parser(debug_parser) else: - p = parse25.Python26ParserSingle(debug_parser) + p = parse25.Python25ParserSingle(debug_parser) elif version == 2.6: import uncompyle6.parsers.parse26 as parse26 if compile_mode == 'exec': diff --git a/uncompyle6/parsers/parse25.py b/uncompyle6/parsers/parse25.py new file mode 100644 index 00000000..1f95ed2f --- /dev/null +++ b/uncompyle6/parsers/parse25.py @@ -0,0 +1,42 @@ +# Copyright (c) 2016 Rocky Bernstein +""" +spark grammar differences over Python2.6 for Python 2.6. +""" + +from uncompyle6.parser import PythonParserSingle +from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG +from uncompyle6.parsers.parse26 import Python26Parser + +class Python25Parser(Python26Parser): + def __init__(self, debug_parser=PARSER_DEFAULT_DEBUG): + super(Python25Parser, self).__init__(debug_parser) + self.customized = {} + + def p_misc(self, args): + ''' + + # If "return_if_stmt" is in a loop, a JUMP_BACK can be emitted. In 2.6 the + # JUMP_BACK doesn't appear + + return_if_stmt ::= ret_expr RETURN_END_IF JUMP_BACK + + # Pyython 2.6 uses ROT_TWO instead of the STORE_FAST + setupwithas ::= DUP_TOP LOAD_ATTR STORE_FAST LOAD_ATTR CALL_FUNCTION_0 STORE_FAST + SETUP_FINALLY LOAD_FAST DELETE_FAST + + # Python 2.6 omits ths LOAD_FAST DELETE_FAST below + withasstmt ::= expr setupwithas designator suite_stmts_opt + POP_BLOCK LOAD_CONST COME_FROM + LOAD_FAST DELETE_FAST + WITH_CLEANUP END_FINALLY + + + ''' + +class Python25ParserSingle(Python26Parser, PythonParserSingle): + pass + +if __name__ == '__main__': + # Check grammar + p = Python26Parser() + p.checkGrammar() diff --git a/uncompyle6/parsers/parse26.py b/uncompyle6/parsers/parse26.py index 30f2a93d..2488d8d6 100644 --- a/uncompyle6/parsers/parse26.py +++ b/uncompyle6/parsers/parse26.py @@ -128,6 +128,7 @@ class Python26Parser(Python2Parser): POP_BLOCK LOAD_CONST COME_FROM WITH_CLEANUP END_FINALLY # Semantic actions want designator to be at index 2 + # Rule is possibly 2.6 only withasstmt ::= expr setupwithas designator suite_stmts_opt POP_BLOCK LOAD_CONST COME_FROM WITH_CLEANUP END_FINALLY @@ -135,8 +136,12 @@ class Python26Parser(Python2Parser): # opcode SETUP_WITH setupwith ::= DUP_TOP LOAD_ATTR ROT_TWO LOAD_ATTR CALL_FUNCTION_0 POP_TOP - setupwithas ::= DUP_TOP LOAD_ATTR ROT_TWO LOAD_ATTR CALL_FUNCTION_0 STORE_FAST - SETUP_FINALLY LOAD_FAST DELETE_FAST + # Possibly 2.6 only + setupwithas ::= DUP_TOP LOAD_ATTR ROT_TWO LOAD_ATTR CALL_FUNCTION_0 setup_finally + + setup_finally ::= STORE_FAST SETUP_FINALLY LOAD_FAST DELETE_FAST + setup_finally ::= STORE_NAME SETUP_FINALLY LOAD_NAME DELETE_NAME + whilestmt ::= SETUP_LOOP testexpr l_stmts_opt jb_pop POP_BLOCK _come_from whilestmt ::= SETUP_LOOP testexpr l_stmts_opt jb_cf_pop bp_come_from