You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-02 16:44:46 +08:00
2.7 exec stmt grammar rule isolation/reduction
This commit is contained in:
BIN
test/bytecode_2.6/02_test_exec.pyc
Normal file
BIN
test/bytecode_2.6/02_test_exec.pyc
Normal file
Binary file not shown.
13
test/simple_source/stmts/02_test_exec.py
Normal file
13
test/simple_source/stmts/02_test_exec.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# exec.py -- source test pattern for exec statement
|
||||||
|
#
|
||||||
|
# This simple program is part of the decompyle test suite.
|
||||||
|
#
|
||||||
|
# decompyle is a Python byte-code decompiler
|
||||||
|
# See http://www.goebel-consult.de/decompyle/ for download and
|
||||||
|
# for further information
|
||||||
|
|
||||||
|
testcode = 'a = 12'
|
||||||
|
|
||||||
|
exec testcode
|
||||||
|
exec testcode in globals()
|
||||||
|
exec testcode in globals(), locals()
|
@@ -501,9 +501,6 @@ class PythonParser(GenericASTBuilder):
|
|||||||
# Non-null kvlist items are broken out in the indiviual grammars
|
# Non-null kvlist items are broken out in the indiviual grammars
|
||||||
kvlist ::=
|
kvlist ::=
|
||||||
|
|
||||||
exprlist ::= exprlist expr
|
|
||||||
exprlist ::= expr
|
|
||||||
|
|
||||||
# Positional arguments in make_function
|
# Positional arguments in make_function
|
||||||
pos_arg ::= expr
|
pos_arg ::= expr
|
||||||
|
|
||||||
|
@@ -38,13 +38,6 @@ class Python2Parser(PythonParser):
|
|||||||
print_nl ::= PRINT_NEWLINE
|
print_nl ::= PRINT_NEWLINE
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def p_stmt2(self, args):
|
|
||||||
"""
|
|
||||||
exec_stmt ::= expr exprlist DUP_TOP EXEC_STMT
|
|
||||||
exec_stmt ::= expr exprlist EXEC_STMT
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
def p_print_to(self, args):
|
def p_print_to(self, args):
|
||||||
'''
|
'''
|
||||||
stmt ::= print_to
|
stmt ::= print_to
|
||||||
@@ -341,6 +334,13 @@ class Python2Parser(PythonParser):
|
|||||||
# FIXME: remove these conditions if they are not needed.
|
# FIXME: remove these conditions if they are not needed.
|
||||||
# no longer need to add a rule
|
# no longer need to add a rule
|
||||||
continue
|
continue
|
||||||
|
elif opname == 'EXEC_STMT':
|
||||||
|
self.addRule("""
|
||||||
|
exprlist ::= expr+
|
||||||
|
exec_stmt ::= expr exprlist DUP_TOP EXEC_STMT
|
||||||
|
exec_stmt ::= expr exprlist EXEC_STMT
|
||||||
|
""", nop_func)
|
||||||
|
continue
|
||||||
elif opname == 'JUMP_IF_NOT_DEBUG':
|
elif opname == 'JUMP_IF_NOT_DEBUG':
|
||||||
self.add_unique_rules([
|
self.add_unique_rules([
|
||||||
'jmp_true_false ::= POP_JUMP_IF_TRUE',
|
'jmp_true_false ::= POP_JUMP_IF_TRUE',
|
||||||
|
@@ -35,11 +35,6 @@ class Python35Parser(Python34Parser):
|
|||||||
|
|
||||||
# Python 3.5+ has WITH_CLEANUP_START/FINISH
|
# Python 3.5+ has WITH_CLEANUP_START/FINISH
|
||||||
|
|
||||||
withstmt ::= expr
|
|
||||||
SETUP_WITH exprlist suite_stmts_opt
|
|
||||||
POP_BLOCK LOAD_CONST COME_FROM_WITH
|
|
||||||
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
|
|
||||||
|
|
||||||
withstmt ::= expr
|
withstmt ::= expr
|
||||||
SETUP_WITH POP_TOP suite_stmts_opt
|
SETUP_WITH POP_TOP suite_stmts_opt
|
||||||
POP_BLOCK LOAD_CONST COME_FROM_WITH
|
POP_BLOCK LOAD_CONST COME_FROM_WITH
|
||||||
|
@@ -250,17 +250,15 @@ class Scanner2(Scanner):
|
|||||||
else:
|
else:
|
||||||
op_name = '%s_%d' % (op_name, oparg)
|
op_name = '%s_%d' % (op_name, oparg)
|
||||||
customize[op_name] = oparg
|
customize[op_name] = oparg
|
||||||
elif self.is_pypy and op_name in ('LOOKUP_METHOD',
|
elif self.is_pypy and op_name in frozenset(
|
||||||
'JUMP_IF_NOT_DEBUG',
|
"""LOOKUP_METHOD JUMP_IF_NOT_DEBUG SETUP_EXCEPT SETUP_FINALLY""".split()):
|
||||||
'SETUP_EXCEPT',
|
|
||||||
'SETUP_FINALLY'):
|
|
||||||
# The value in the dict is in special cases in semantic actions, such
|
# The value in the dict is in special cases in semantic actions, such
|
||||||
# as CALL_FUNCTION. The value is not used in these cases, so we put
|
# as CALL_FUNCTION. The value is not used in these cases, so we put
|
||||||
# in arbitrary value 0.
|
# in arbitrary value 0.
|
||||||
customize[op_name] = 0
|
customize[op_name] = 0
|
||||||
elif op == self.opc.CONTINUE_LOOP:
|
elif op_name in """
|
||||||
customize[op_name] = 0
|
CONTINUE_LOOP EXEC_STMT LOAD_LISTCOMP LOAD_SETCOMP
|
||||||
elif op_name in frozenset(('LOAD_LISTCOMP', 'LOAD_SETCOMP')):
|
""".split():
|
||||||
customize[op_name] = 0
|
customize[op_name] = 0
|
||||||
elif op == self.opc.JUMP_ABSOLUTE:
|
elif op == self.opc.JUMP_ABSOLUTE:
|
||||||
# Further classify JUMP_ABSOLUTE into backward jumps
|
# Further classify JUMP_ABSOLUTE into backward jumps
|
||||||
|
@@ -238,6 +238,10 @@ class Scanner26(scan.Scanner2):
|
|||||||
customize[op_name] = oparg
|
customize[op_name] = oparg
|
||||||
elif self.version > 2.0 and op == self.opc.CONTINUE_LOOP:
|
elif self.version > 2.0 and op == self.opc.CONTINUE_LOOP:
|
||||||
customize[op_name] = 0
|
customize[op_name] = 0
|
||||||
|
elif op_name in """
|
||||||
|
CONTINUE_LOOP EXEC_STMT LOAD_LISTCOMP LOAD_SETCOMP
|
||||||
|
""".split():
|
||||||
|
customize[op_name] = 0
|
||||||
elif op == self.opc.JUMP_ABSOLUTE:
|
elif op == self.opc.JUMP_ABSOLUTE:
|
||||||
# Further classify JUMP_ABSOLUTE into backward jumps
|
# Further classify JUMP_ABSOLUTE into backward jumps
|
||||||
# which are used in loops, and "CONTINUE" jumps which
|
# which are used in loops, and "CONTINUE" jumps which
|
||||||
|
Reference in New Issue
Block a user