You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 09:22:40 +08:00
Merge branch 'master' into python-2.4
This commit is contained in:
@@ -98,13 +98,20 @@ check-bytecode-2.4:
|
|||||||
check-bytecode-2.5:
|
check-bytecode-2.5:
|
||||||
$(PYTHON) test_pythonlib.py --bytecode-2.5
|
$(PYTHON) test_pythonlib.py --bytecode-2.5
|
||||||
|
|
||||||
#: Check deparsing Python 2.6
|
#: Get grammar coverage for Python 2.5
|
||||||
check-bytecode-2.6:
|
grammar-coverage-2.5:
|
||||||
$(PYTHON) test_pythonlib.py --bytecode-2.6 --weak-verify
|
SPARK_PARSER_COVERAGE=/tmp/spark-grammar-25.cover $(PYTHON) test_pythonlib.py --bytecode-2.5
|
||||||
|
SPARK_PARSER_COVERAGE=/tmp/spark-grammar-25.cover $(PYTHON) test_pyenvlib.py --2.5.6
|
||||||
|
|
||||||
#: Check deparsing Python 2.7
|
#: Get grammar coverage for Python 2.6
|
||||||
check-bytecode-2.7:
|
grammar-coverage-2.6:
|
||||||
$(PYTHON) test_pythonlib.py --bytecode-2.7 --verify
|
SPARK_PARSER_COVERAGE=/tmp/spark-grammar-26.cover $(PYTHON) test_pythonlib.py --bytecode-2.6
|
||||||
|
SPARK_PARSER_COVERAGE=/tmp/spark-grammar-26.cover $(PYTHON) test_pyenvlib.py --2.6.9
|
||||||
|
|
||||||
|
#: Get grammar coverage for Python 2.7
|
||||||
|
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
|
||||||
|
|
||||||
#: Check deparsing Python 3.0
|
#: Check deparsing Python 3.0
|
||||||
check-bytecode-3.0:
|
check-bytecode-3.0:
|
||||||
|
Binary file not shown.
Binary file not shown.
BIN
test/bytecode_3.5/02_try_finally.pyc
Normal file
BIN
test/bytecode_3.5/02_try_finally.pyc
Normal file
Binary file not shown.
@@ -11,3 +11,8 @@ y &= 1 # INPLACE_AND
|
|||||||
y ^= 1 # INPLACE_XOR
|
y ^= 1 # INPLACE_XOR
|
||||||
|
|
||||||
`y` # UNARY_CONVERT - No in Python 3.x
|
`y` # UNARY_CONVERT - No in Python 3.x
|
||||||
|
|
||||||
|
# Beef up augassign and STORE_SLICE+3
|
||||||
|
x = [1,2,3,4,5]
|
||||||
|
x[0:1] = 1
|
||||||
|
x[0:3] += 1, 2, 3
|
||||||
|
14
test/simple_source/bug33/02_while1.py
Normal file
14
test/simple_source/bug33/02_while1.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# From Python 3.4 mailcap
|
||||||
|
def readmailcapfile(caps):
|
||||||
|
while 1:
|
||||||
|
line = 'abc'
|
||||||
|
if line[0] == '#' or line == '':
|
||||||
|
continue
|
||||||
|
key, fields = (1,2)
|
||||||
|
if not (key and fields):
|
||||||
|
continue
|
||||||
|
if key in caps:
|
||||||
|
caps[key].append(fields)
|
||||||
|
else:
|
||||||
|
caps[key] = [fields]
|
||||||
|
return caps
|
11
test/simple_source/exception/02_try_finally.py
Normal file
11
test/simple_source/exception/02_try_finally.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# From 2.6.9 cmd.py
|
||||||
|
try:
|
||||||
|
if __file__:
|
||||||
|
x = 2
|
||||||
|
x = 3
|
||||||
|
finally:
|
||||||
|
if x and __file__:
|
||||||
|
try:
|
||||||
|
x = 1
|
||||||
|
except:
|
||||||
|
pass
|
@@ -228,7 +228,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
if test_opts['coverage']:
|
if test_opts['coverage']:
|
||||||
os.environ['SPARK_PARSER_COVERAGE'] = (
|
os.environ['SPARK_PARSER_COVERAGE'] = (
|
||||||
'/tmp/spark-grammar-%s.cover' % test_dirs[0][-1]
|
'/tmp/spark-grammar-python-lib%s.cover' % test_dirs[0][-1]
|
||||||
)
|
)
|
||||||
|
|
||||||
last_compile_version = None
|
last_compile_version = None
|
||||||
|
@@ -28,19 +28,13 @@ class Python26Parser(Python2Parser):
|
|||||||
POP_TOP END_FINALLY
|
POP_TOP END_FINALLY
|
||||||
|
|
||||||
try_middle ::= jmp_abs COME_FROM except_stmts
|
try_middle ::= jmp_abs COME_FROM except_stmts
|
||||||
POP_TOP END_FINALLY
|
END_FINALLY JUMP_FORWARD
|
||||||
|
|
||||||
trystmt ::= SETUP_EXCEPT suite_stmts_opt POP_TOP
|
|
||||||
try_middle
|
|
||||||
|
|
||||||
# Sometimes we don't put in COME_FROM to the next statement
|
# Sometimes we don't put in COME_FROM to the next statement
|
||||||
# like we do in 2.7. Perhaps we should?
|
# like we do in 2.7. Perhaps we should?
|
||||||
trystmt ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
|
trystmt ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
|
||||||
try_middle
|
try_middle
|
||||||
|
|
||||||
trystmt ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
|
|
||||||
try_middle come_froms
|
|
||||||
|
|
||||||
tryelsestmt ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
|
tryelsestmt ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
|
||||||
try_middle else_suite COME_FROM
|
try_middle else_suite COME_FROM
|
||||||
|
|
||||||
|
@@ -42,6 +42,10 @@ class Python3Parser(PythonParser):
|
|||||||
|
|
||||||
list_for ::= expr FOR_ITER designator list_iter jb_or_c
|
list_for ::= expr FOR_ITER designator list_iter jb_or_c
|
||||||
|
|
||||||
|
# This is seen in PyPy, but possibly it appears on other Python 3?
|
||||||
|
list_if ::= expr jmp_false list_iter COME_FROM
|
||||||
|
list_if_not ::= expr jmp_true list_iter COME_FROM
|
||||||
|
|
||||||
jb_or_c ::= JUMP_BACK
|
jb_or_c ::= JUMP_BACK
|
||||||
jb_or_c ::= CONTINUE
|
jb_or_c ::= CONTINUE
|
||||||
|
|
||||||
@@ -50,6 +54,9 @@ class Python3Parser(PythonParser):
|
|||||||
setcomp_func ::= BUILD_SET_0 LOAD_FAST FOR_ITER designator comp_iter
|
setcomp_func ::= BUILD_SET_0 LOAD_FAST FOR_ITER designator comp_iter
|
||||||
JUMP_BACK RETURN_VALUE RETURN_LAST
|
JUMP_BACK RETURN_VALUE RETURN_LAST
|
||||||
|
|
||||||
|
setcomp_func ::= BUILD_SET_0 LOAD_FAST FOR_ITER designator comp_iter
|
||||||
|
COME_FROM JUMP_BACK RETURN_VALUE RETURN_LAST
|
||||||
|
|
||||||
comp_body ::= dict_comp_body
|
comp_body ::= dict_comp_body
|
||||||
comp_body ::= set_comp_body
|
comp_body ::= set_comp_body
|
||||||
dict_comp_body ::= expr expr MAP_ADD
|
dict_comp_body ::= expr expr MAP_ADD
|
||||||
@@ -111,9 +118,11 @@ class Python3Parser(PythonParser):
|
|||||||
classdefdeco1 ::= expr classdefdeco1 CALL_FUNCTION_1
|
classdefdeco1 ::= expr classdefdeco1 CALL_FUNCTION_1
|
||||||
classdefdeco1 ::= expr classdefdeco2 CALL_FUNCTION_1
|
classdefdeco1 ::= expr classdefdeco2 CALL_FUNCTION_1
|
||||||
|
|
||||||
assert ::= assert_expr jmp_true LOAD_ASSERT RAISE_VARARGS_1
|
assert ::= assert_expr jmp_true LOAD_ASSERT RAISE_VARARGS_1 COME_FROM
|
||||||
assert2 ::= assert_expr jmp_true LOAD_ASSERT expr CALL_FUNCTION_1 RAISE_VARARGS_1
|
assert2 ::= assert_expr jmp_true LOAD_ASSERT expr CALL_FUNCTION_1
|
||||||
assert2 ::= assert_expr jmp_true LOAD_ASSERT expr RAISE_VARARGS_2
|
RAISE_VARARGS_1 COME_FROM
|
||||||
|
assert2 ::= assert_expr jmp_true LOAD_ASSERT expr
|
||||||
|
RAISE_VARARGS_2 COME_FROM
|
||||||
|
|
||||||
assert_expr ::= expr
|
assert_expr ::= expr
|
||||||
assert_expr ::= assert_expr_or
|
assert_expr ::= assert_expr_or
|
||||||
@@ -130,6 +139,7 @@ class Python3Parser(PythonParser):
|
|||||||
|
|
||||||
_ifstmts_jump ::= return_if_stmts
|
_ifstmts_jump ::= return_if_stmts
|
||||||
_ifstmts_jump ::= c_stmts_opt JUMP_FORWARD COME_FROM
|
_ifstmts_jump ::= c_stmts_opt JUMP_FORWARD COME_FROM
|
||||||
|
_ifstmts_jump ::= c_stmts_opt COME_FROM
|
||||||
|
|
||||||
iflaststmt ::= testexpr c_stmts_opt JUMP_ABSOLUTE
|
iflaststmt ::= testexpr c_stmts_opt JUMP_ABSOLUTE
|
||||||
|
|
||||||
@@ -153,6 +163,7 @@ class Python3Parser(PythonParser):
|
|||||||
ifelsestmtr ::= testexpr return_if_stmts return_stmts
|
ifelsestmtr ::= testexpr return_if_stmts return_stmts
|
||||||
|
|
||||||
ifelsestmtl ::= testexpr c_stmts_opt JUMP_BACK else_suitel
|
ifelsestmtl ::= testexpr c_stmts_opt JUMP_BACK else_suitel
|
||||||
|
ifelsestmtl ::= testexpr c_stmts_opt COME_FROM JUMP_BACK else_suitel
|
||||||
|
|
||||||
# FIXME: this feels like a hack. Is it just 1 or two
|
# FIXME: this feels like a hack. Is it just 1 or two
|
||||||
# COME_FROMs? the parsed tree for this and even with just the
|
# COME_FROMs? the parsed tree for this and even with just the
|
||||||
@@ -327,6 +338,9 @@ class Python3Parser(PythonParser):
|
|||||||
forelselaststmtl ::= SETUP_LOOP expr _for designator for_block POP_BLOCK else_suitel
|
forelselaststmtl ::= SETUP_LOOP expr _for designator for_block POP_BLOCK else_suitel
|
||||||
COME_FROM_LOOP
|
COME_FROM_LOOP
|
||||||
|
|
||||||
|
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt COME_FROM JUMP_BACK POP_BLOCK
|
||||||
|
COME_FROM_LOOP
|
||||||
|
|
||||||
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK POP_BLOCK
|
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK POP_BLOCK
|
||||||
COME_FROM_LOOP
|
COME_FROM_LOOP
|
||||||
|
|
||||||
@@ -354,6 +368,9 @@ class Python3Parser(PythonParser):
|
|||||||
while1stmt ::= SETUP_LOOP l_stmts
|
while1stmt ::= SETUP_LOOP l_stmts
|
||||||
while1stmt ::= SETUP_LOOP l_stmts COME_FROM_LOOP
|
while1stmt ::= SETUP_LOOP l_stmts COME_FROM_LOOP
|
||||||
|
|
||||||
|
while1stmt ::= SETUP_LOOP l_stmts COME_FROM JUMP_BACK COME_FROM_LOOP
|
||||||
|
|
||||||
|
|
||||||
# FIXME: investigate - can code really produce a NOP?
|
# FIXME: investigate - can code really produce a NOP?
|
||||||
whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK NOP
|
whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK NOP
|
||||||
COME_FROM_LOOP
|
COME_FROM_LOOP
|
||||||
|
@@ -19,6 +19,9 @@ class Python35Parser(Python34Parser):
|
|||||||
# I'm sure by the time Python 4 comes around these will be turned
|
# I'm sure by the time Python 4 comes around these will be turned
|
||||||
# into special opcodes
|
# into special opcodes
|
||||||
|
|
||||||
|
while1stmt ::= SETUP_LOOP l_stmts COME_FROM JUMP_BACK
|
||||||
|
POP_BLOCK COME_FROM_LOOP
|
||||||
|
|
||||||
# Python 3.5+ Await statement
|
# Python 3.5+ Await statement
|
||||||
stmt ::= await_stmt
|
stmt ::= await_stmt
|
||||||
await_stmt ::= call_function GET_AWAITABLE LOAD_CONST YIELD_FROM POP_TOP
|
await_stmt ::= call_function GET_AWAITABLE LOAD_CONST YIELD_FROM POP_TOP
|
||||||
@@ -109,7 +112,6 @@ class Python35Parser(Python34Parser):
|
|||||||
|
|
||||||
yield_from ::= expr GET_YIELD_FROM_ITER LOAD_CONST YIELD_FROM
|
yield_from ::= expr GET_YIELD_FROM_ITER LOAD_CONST YIELD_FROM
|
||||||
|
|
||||||
_ifstmts_jump ::= c_stmts_opt COME_FROM
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def add_custom_rules(self, tokens, customize):
|
def add_custom_rules(self, tokens, customize):
|
||||||
|
@@ -337,7 +337,7 @@ class Scanner3(Scanner):
|
|||||||
(next_opname not in ('END_FINALLY', 'POP_BLOCK',
|
(next_opname not in ('END_FINALLY', 'POP_BLOCK',
|
||||||
# Python 3.0 only uses POP_TOP
|
# Python 3.0 only uses POP_TOP
|
||||||
'POP_TOP'))):
|
'POP_TOP'))):
|
||||||
if (self.version >= 3.5 or
|
if (self.version >= 3.4 or
|
||||||
(inst.offset not in self.not_continue) or
|
(inst.offset not in self.not_continue) or
|
||||||
(tokens[-1].type == 'RETURN_VALUE')):
|
(tokens[-1].type == 'RETURN_VALUE')):
|
||||||
opname = 'CONTINUE'
|
opname = 'CONTINUE'
|
||||||
@@ -899,7 +899,10 @@ class Scanner3(Scanner):
|
|||||||
else:
|
else:
|
||||||
self.fixed_jumps[offset] = rtarget
|
self.fixed_jumps[offset] = rtarget
|
||||||
self.not_continue.add(pre_rtarget)
|
self.not_continue.add(pre_rtarget)
|
||||||
|
else:
|
||||||
|
# For now, we'll only tag forward jump.
|
||||||
|
if rtarget > offset:
|
||||||
|
self.fixed_jumps[offset] = rtarget
|
||||||
|
|
||||||
elif op == self.opc.SETUP_EXCEPT:
|
elif op == self.opc.SETUP_EXCEPT:
|
||||||
target = self.get_target(offset)
|
target = self.get_target(offset)
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
# Copyright (c) 2015, 2016 by Rocky Bernstein
|
# Copyright (c) 2015-2017 by Rocky Bernstein
|
||||||
# Copyright (c) 2005 by Dan Pascu <dan@windowmaker.org>
|
# Copyright (c) 2005 by Dan Pascu <dan@windowmaker.org>
|
||||||
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
|
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
|
||||||
# Copyright (c) 1999 John Aycock
|
# Copyright (c) 1999 John Aycock
|
||||||
@@ -239,7 +239,7 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
TABLE_DIRECT.update({
|
TABLE_DIRECT.update({
|
||||||
'importmultiple': ( '%|import %c%c\n', 2, 3 ),
|
'importmultiple': ( '%|import %c%c\n', 2, 3 ),
|
||||||
'import_cont' : ( ', %c', 2 ),
|
'import_cont' : ( ', %c', 2 ),
|
||||||
# With/as is allowed as "from future" thing
|
# With/as is allowed as "from future" thing in 2.5
|
||||||
'withstmt': ( '%|with %c:\n%+%c%-', 0, 3),
|
'withstmt': ( '%|with %c:\n%+%c%-', 0, 3),
|
||||||
'withasstmt': ( '%|with %c as %c:\n%+%c%-', 0, 2, 3),
|
'withasstmt': ( '%|with %c as %c:\n%+%c%-', 0, 2, 3),
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user