You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Start going over Python 2.5 bytecode
Fix 2.6 with bug
This commit is contained in:
@@ -9,4 +9,5 @@ version = sys.version[0:3]
|
|||||||
cfile = "bytecode_%s/%s" % (version, short) + 'c'
|
cfile = "bytecode_%s/%s" % (version, short) + 'c'
|
||||||
print("byte-compiling %s to %s" % (path, cfile))
|
print("byte-compiling %s to %s" % (path, cfile))
|
||||||
py_compile.compile(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)
|
||||||
|
BIN
test/bytecode_2.5/00_assign.pyc
Normal file
BIN
test/bytecode_2.5/00_assign.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.5/00_import.pyc
Normal file
BIN
test/bytecode_2.5/00_import.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.5/00_pass.pyc
Normal file
BIN
test/bytecode_2.5/00_pass.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.5/01_class.pyc
Normal file
BIN
test/bytecode_2.5/01_class.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.5/01_list_comprehension.pyc
Normal file
BIN
test/bytecode_2.5/01_list_comprehension.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.5/02_def.pyc
Normal file
BIN
test/bytecode_2.5/02_def.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.5/03_if_elif.pyc
Normal file
BIN
test/bytecode_2.5/03_if_elif.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.5/06_list_ifnot.pyc
Normal file
BIN
test/bytecode_2.5/06_list_ifnot.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.5/06_list_ifnot_and.pyc
Normal file
BIN
test/bytecode_2.5/06_list_ifnot_and.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.5/11-list-if.pyc
Normal file
BIN
test/bytecode_2.5/11-list-if.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.6/05_with.pyc
Normal file
BIN
test/bytecode_2.6/05_with.pyc
Normal file
Binary file not shown.
@@ -1,2 +1,3 @@
|
|||||||
|
from __future__ import with_statement
|
||||||
with (sys) as f:
|
with (sys) as f:
|
||||||
print(f)
|
print(f)
|
||||||
|
@@ -592,12 +592,11 @@ def get_python_parser(version, debug_parser, compile_mode='exec'):
|
|||||||
else:
|
else:
|
||||||
p = parse23.Python23ParserSingle(debug_parser)
|
p = parse23.Python23ParserSingle(debug_parser)
|
||||||
elif version == 2.5:
|
elif version == 2.5:
|
||||||
# For now, we'll consider 2.5 exactly like 2.6
|
import uncompyle6.parsers.parse25 as parse25
|
||||||
import uncompyle6.parsers.parse26 as parse25
|
|
||||||
if compile_mode == 'exec':
|
if compile_mode == 'exec':
|
||||||
p = parse25.Python26Parser(debug_parser)
|
p = parse25.Python25Parser(debug_parser)
|
||||||
else:
|
else:
|
||||||
p = parse25.Python26ParserSingle(debug_parser)
|
p = parse25.Python25ParserSingle(debug_parser)
|
||||||
elif version == 2.6:
|
elif version == 2.6:
|
||||||
import uncompyle6.parsers.parse26 as parse26
|
import uncompyle6.parsers.parse26 as parse26
|
||||||
if compile_mode == 'exec':
|
if compile_mode == 'exec':
|
||||||
|
42
uncompyle6/parsers/parse25.py
Normal file
42
uncompyle6/parsers/parse25.py
Normal file
@@ -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()
|
@@ -128,6 +128,7 @@ class Python26Parser(Python2Parser):
|
|||||||
POP_BLOCK LOAD_CONST COME_FROM WITH_CLEANUP END_FINALLY
|
POP_BLOCK LOAD_CONST COME_FROM WITH_CLEANUP END_FINALLY
|
||||||
|
|
||||||
# Semantic actions want designator to be at index 2
|
# Semantic actions want designator to be at index 2
|
||||||
|
# Rule is possibly 2.6 only
|
||||||
withasstmt ::= expr setupwithas designator suite_stmts_opt
|
withasstmt ::= expr setupwithas designator suite_stmts_opt
|
||||||
POP_BLOCK LOAD_CONST COME_FROM WITH_CLEANUP END_FINALLY
|
POP_BLOCK LOAD_CONST COME_FROM WITH_CLEANUP END_FINALLY
|
||||||
|
|
||||||
@@ -135,8 +136,12 @@ class Python26Parser(Python2Parser):
|
|||||||
# opcode SETUP_WITH
|
# opcode SETUP_WITH
|
||||||
setupwith ::= DUP_TOP LOAD_ATTR ROT_TWO LOAD_ATTR CALL_FUNCTION_0 POP_TOP
|
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
|
# Possibly 2.6 only
|
||||||
SETUP_FINALLY LOAD_FAST DELETE_FAST
|
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_pop POP_BLOCK _come_from
|
||||||
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt jb_cf_pop bp_come_from
|
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt jb_cf_pop bp_come_from
|
||||||
|
Reference in New Issue
Block a user