You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
3.x Grammar reduction of custom rules...
by looking for token patterns GET_ITER CALL_FUNCTION_1
This commit is contained in:
BIN
test/bytecode_3.3/01_ops.pyc
Normal file
BIN
test/bytecode_3.3/01_ops.pyc
Normal file
Binary file not shown.
16
test/simple_source/bug30/01_ops.py
Normal file
16
test/simple_source/bug30/01_ops.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# Statements to beef up grammar coverage rules
|
||||||
|
# Force "inplace" ops
|
||||||
|
y = +10 # UNARY_POSITIVE
|
||||||
|
y /= 1 # INPLACE_DIVIDE
|
||||||
|
y %= 4 # INPLACE_MODULO
|
||||||
|
y **= 1 # INPLACE POWER
|
||||||
|
y >>= 2 # INPLACE_RSHIFT
|
||||||
|
y <<= 2 # INPLACE_LSHIFT
|
||||||
|
y //= 1 # INPLACE_TRUE_DIVIDE
|
||||||
|
y &= 1 # INPLACE_AND
|
||||||
|
y ^= 1 # INPLACE_XOR
|
||||||
|
|
||||||
|
# Beef up augassign and STORE_SLICE+3
|
||||||
|
x = [1,2,3,4,5]
|
||||||
|
x[0:1] = 1
|
||||||
|
x[0:3] += 1, 2, 3
|
@@ -506,7 +506,6 @@ class PythonParser(GenericASTBuilder):
|
|||||||
|
|
||||||
expr ::= conditional
|
expr ::= conditional
|
||||||
conditional ::= expr jmp_false expr JUMP_FORWARD expr COME_FROM
|
conditional ::= expr jmp_false expr JUMP_FORWARD expr COME_FROM
|
||||||
conditional ::= expr jmp_false expr JUMP_ABSOLUTE expr
|
|
||||||
|
|
||||||
expr ::= conditionalTrue
|
expr ::= conditionalTrue
|
||||||
conditionalTrue ::= expr JUMP_FORWARD expr COME_FROM
|
conditionalTrue ::= expr JUMP_FORWARD expr COME_FROM
|
||||||
|
@@ -201,6 +201,8 @@ class Python2Parser(PythonParser):
|
|||||||
|
|
||||||
# In Python 3, DUP_TOPX_2 is DUP_TOP_TWO
|
# In Python 3, DUP_TOPX_2 is DUP_TOP_TWO
|
||||||
binary_subscr2 ::= expr expr DUP_TOPX_2 BINARY_SUBSCR
|
binary_subscr2 ::= expr expr DUP_TOPX_2 BINARY_SUBSCR
|
||||||
|
|
||||||
|
conditional ::= expr jmp_false expr JUMP_ABSOLUTE expr
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def p_slice2(self, args):
|
def p_slice2(self, args):
|
||||||
|
@@ -279,8 +279,6 @@ class Python3Parser(PythonParser):
|
|||||||
for_block ::= l_stmts_opt opt_come_from_loop JUMP_BACK
|
for_block ::= l_stmts_opt opt_come_from_loop JUMP_BACK
|
||||||
for_block ::= l_stmts
|
for_block ::= l_stmts
|
||||||
iflaststmtl ::= testexpr c_stmts_opt
|
iflaststmtl ::= testexpr c_stmts_opt
|
||||||
iflaststmt ::= testexpr c_stmts_opt33
|
|
||||||
c_stmts_opt33 ::= JUMP_BACK JUMP_ABSOLUTE c_stmts_opt
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def p_def_annotations3(self, args):
|
def p_def_annotations3(self, args):
|
||||||
@@ -421,7 +419,6 @@ class Python3Parser(PythonParser):
|
|||||||
def p_expr3(self, args):
|
def p_expr3(self, args):
|
||||||
"""
|
"""
|
||||||
expr ::= conditionalnot
|
expr ::= conditionalnot
|
||||||
conditional ::= expr jmp_false expr jump_forward_else expr COME_FROM
|
|
||||||
conditionalnot ::= expr jmp_true expr jump_forward_else expr COME_FROM
|
conditionalnot ::= expr jmp_true expr jump_forward_else expr COME_FROM
|
||||||
|
|
||||||
# a JUMP_FORWARD to another JUMP_FORWARD can get turned into
|
# a JUMP_FORWARD to another JUMP_FORWARD can get turned into
|
||||||
@@ -862,7 +859,7 @@ class Python3Parser(PythonParser):
|
|||||||
('kwarg '* args_kw),
|
('kwarg '* args_kw),
|
||||||
opname))
|
opname))
|
||||||
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
|
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
|
||||||
if seen_LOAD_LISTCOMP:
|
if seen_LOAD_LISTCOMP and has_get_iter_call_function1:
|
||||||
rule_pat = ("listcomp ::= %sLOAD_LISTCOMP %%s%s expr "
|
rule_pat = ("listcomp ::= %sLOAD_LISTCOMP %%s%s expr "
|
||||||
"GET_ITER CALL_FUNCTION_1" % ('expr ' * args_pos, opname))
|
"GET_ITER CALL_FUNCTION_1" % ('expr ' * args_pos, opname))
|
||||||
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
|
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
|
||||||
@@ -872,17 +869,20 @@ class Python3Parser(PythonParser):
|
|||||||
else:
|
else:
|
||||||
args_pos, args_kw, annotate_args, closure = token.attr
|
args_pos, args_kw, annotate_args, closure = token.attr
|
||||||
|
|
||||||
rule_pat = ("genexpr ::= %sload_genexpr %%s%s expr "
|
if has_get_iter_call_function1:
|
||||||
"GET_ITER CALL_FUNCTION_1" % ('pos_arg '* args_pos, opname))
|
rule_pat = ("genexpr ::= %sload_genexpr %%s%s expr "
|
||||||
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
|
"GET_ITER CALL_FUNCTION_1" % ('pos_arg '* args_pos, opname))
|
||||||
|
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
|
||||||
rule_pat = ('mklambda ::= %s%sLOAD_LAMBDA %%s%s' %
|
rule_pat = ('mklambda ::= %s%sLOAD_LAMBDA %%s%s' %
|
||||||
(('pos_arg '* args_pos),
|
(('pos_arg '* args_pos),
|
||||||
('kwarg '* args_kw),
|
('kwarg '* args_kw),
|
||||||
opname))
|
opname))
|
||||||
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
|
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
|
||||||
rule_pat = ("listcomp ::= %sLOAD_LISTCOMP %%s%s expr "
|
|
||||||
"GET_ITER CALL_FUNCTION_1" % ('expr ' * args_pos, opname))
|
if seen_LOAD_LISTCOMP and has_get_iter_call_function1:
|
||||||
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
|
rule_pat = ("listcomp ::= %sLOAD_LISTCOMP %%s%s expr "
|
||||||
|
"GET_ITER CALL_FUNCTION_1" % ('expr ' * args_pos, opname))
|
||||||
|
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
|
||||||
|
|
||||||
if self.version == 3.3:
|
if self.version == 3.3:
|
||||||
# positional args after keyword args
|
# positional args after keyword args
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
# Copyright (c) 2016 Rocky Bernstein
|
# Copyright (c) 2016-2017 Rocky Bernstein
|
||||||
"""
|
"""
|
||||||
spark grammar differences over Python 3 for Python 3.2.
|
spark grammar differences over Python 3 for Python 3.2.
|
||||||
"""
|
"""
|
||||||
@@ -10,15 +10,15 @@ from uncompyle6.parsers.parse3 import Python3Parser
|
|||||||
class Python32Parser(Python3Parser):
|
class Python32Parser(Python3Parser):
|
||||||
def p_32to35(self, args):
|
def p_32to35(self, args):
|
||||||
"""
|
"""
|
||||||
|
conditional ::= expr jmp_false expr jump_forward_else expr COME_FROM
|
||||||
|
|
||||||
# Store locals is only in Python 3.0 to 3.3
|
# Store locals is only in Python 3.0 to 3.3
|
||||||
stmt ::= store_locals
|
stmt ::= store_locals
|
||||||
store_locals ::= LOAD_FAST STORE_LOCALS
|
store_locals ::= LOAD_FAST STORE_LOCALS
|
||||||
|
|
||||||
# Python < 3.5 no POP BLOCK
|
# Python < 3.5 no POP BLOCK
|
||||||
whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK
|
whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK COME_FROM_LOOP
|
||||||
COME_FROM_LOOP
|
whileTruestmt ::= SETUP_LOOP return_stmts COME_FROM_LOOP
|
||||||
whileTruestmt ::= SETUP_LOOP return_stmts
|
|
||||||
COME_FROM_LOOP
|
|
||||||
|
|
||||||
try_middle ::= JUMP_FORWARD COME_FROM_EXCEPT except_stmts
|
try_middle ::= JUMP_FORWARD COME_FROM_EXCEPT except_stmts
|
||||||
END_FINALLY
|
END_FINALLY
|
||||||
|
Reference in New Issue
Block a user