Start going over Python 2.5 bytecode

Fix 2.6 with bug
This commit is contained in:
rocky
2016-07-08 07:01:48 -04:00
parent f3696cc3f1
commit 6f5dce342f
16 changed files with 55 additions and 7 deletions

View File

@@ -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)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,2 +1,3 @@
from __future__ import with_statement
with (sys) as f:
print(f)

View File

@@ -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':

View 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()

View File

@@ -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