You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 09:22:40 +08:00
Add 3.7 "testfalsel" for looping conditions
This commit is contained in:
@@ -21,7 +21,6 @@ SKIP_TESTS=(
|
|||||||
[test_context.py]=1
|
[test_context.py]=1
|
||||||
[test_coroutines.py]=1 # Parse error
|
[test_coroutines.py]=1 # Parse error
|
||||||
[test_codecs.py]=1
|
[test_codecs.py]=1
|
||||||
[test_complex.py]=1 # Investigate
|
|
||||||
[test_crypt.py]=1 # Parse error
|
[test_crypt.py]=1 # Parse error
|
||||||
[test_ctypes.py]=1 # it fails on its own
|
[test_ctypes.py]=1 # it fails on its own
|
||||||
[test_curses.py]=1 # Parse error
|
[test_curses.py]=1 # Parse error
|
||||||
|
@@ -641,7 +641,6 @@ class Python37Parser(Python37BaseParser):
|
|||||||
expr ::= if_exp_37b
|
expr ::= if_exp_37b
|
||||||
if_exp_37a ::= and_not expr JUMP_FORWARD come_froms expr COME_FROM
|
if_exp_37a ::= and_not expr JUMP_FORWARD come_froms expr COME_FROM
|
||||||
if_exp_37b ::= expr jmp_false expr POP_JUMP_IF_FALSE jump_forward_else expr
|
if_exp_37b ::= expr jmp_false expr POP_JUMP_IF_FALSE jump_forward_else expr
|
||||||
or ::= expr jmp_true expr
|
|
||||||
jmp_false_cf ::= POP_JUMP_IF_FALSE COME_FROM
|
jmp_false_cf ::= POP_JUMP_IF_FALSE COME_FROM
|
||||||
comp_if ::= or jmp_false_cf comp_iter
|
comp_if ::= or jmp_false_cf comp_iter
|
||||||
"""
|
"""
|
||||||
@@ -922,7 +921,14 @@ class Python37Parser(Python37BaseParser):
|
|||||||
testfalse ::= testfalse_not_or
|
testfalse ::= testfalse_not_or
|
||||||
testfalse ::= testfalse_not_and
|
testfalse ::= testfalse_not_and
|
||||||
testfalse ::= or jmp_false COME_FROM
|
testfalse ::= or jmp_false COME_FROM
|
||||||
or ::= expr jmp_true expr
|
|
||||||
|
iflaststmtl ::= testexprl c_stmts JUMP_BACK
|
||||||
|
iflaststmtl ::= testexprl c_stmts JUMP_BACK COME_FROM_LOOP
|
||||||
|
iflaststmtl ::= testexprl c_stmts JUMP_BACK POP_BLOCK
|
||||||
|
testexprl ::= testfalsel
|
||||||
|
testfalsel ::= expr jmp_true
|
||||||
|
|
||||||
|
or ::= expr jmp_true expr
|
||||||
|
|
||||||
and ::= expr JUMP_IF_FALSE_OR_POP expr come_from_opt
|
and ::= expr JUMP_IF_FALSE_OR_POP expr come_from_opt
|
||||||
and ::= expr jifop_come_from expr
|
and ::= expr jifop_come_from expr
|
||||||
|
@@ -999,6 +999,7 @@ class Python37BaseParser(PythonParser):
|
|||||||
"ifstmtl": ifstmt,
|
"ifstmtl": ifstmt,
|
||||||
"or": or_check,
|
"or": or_check,
|
||||||
"testtrue": testtrue,
|
"testtrue": testtrue,
|
||||||
|
"testfalsel": testtrue,
|
||||||
"while1elsestmt": while1elsestmt,
|
"while1elsestmt": while1elsestmt,
|
||||||
"while1stmt": while1stmt,
|
"while1stmt": while1stmt,
|
||||||
"try_elsestmtl38": tryelsestmtl3,
|
"try_elsestmtl38": tryelsestmtl3,
|
||||||
@@ -1019,6 +1020,7 @@ class Python37BaseParser(PythonParser):
|
|||||||
self.check_reduce["import_from37"] = "AST"
|
self.check_reduce["import_from37"] = "AST"
|
||||||
self.check_reduce["or"] = "AST"
|
self.check_reduce["or"] = "AST"
|
||||||
self.check_reduce["testtrue"] = "tokens"
|
self.check_reduce["testtrue"] = "tokens"
|
||||||
|
self.check_reduce["testfalsel"] = "tokens"
|
||||||
return
|
return
|
||||||
|
|
||||||
def custom_classfunc_rule(self, opname, token, customize, next_token):
|
def custom_classfunc_rule(self, opname, token, customize, next_token):
|
||||||
|
@@ -17,7 +17,11 @@ def or_check(self, lhs, n, rule, ast, tokens, first, last):
|
|||||||
if load_global == "LOAD_GLOBAL" and load_global.attr == "AssertionError":
|
if load_global == "LOAD_GLOBAL" and load_global.attr == "AssertionError":
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
first_offset = tokens[first].off2int()
|
||||||
jmp_true_target = ast[1][0].attr
|
jmp_true_target = ast[1][0].attr
|
||||||
|
if jmp_true_target < first_offset:
|
||||||
|
return False
|
||||||
|
|
||||||
jmp_false = tokens[last]
|
jmp_false = tokens[last]
|
||||||
# If the jmp is backwards
|
# If the jmp is backwards
|
||||||
if jmp_false == "POP_JUMP_IF_FALSE":
|
if jmp_false == "POP_JUMP_IF_FALSE":
|
||||||
|
@@ -12,4 +12,11 @@ def testtrue(self, lhs, n, rule, ast, tokens, first, last):
|
|||||||
if pjit == "POP_JUMP_IF_TRUE" and tokens[first].off2int() > pjit.attr:
|
if pjit == "POP_JUMP_IF_TRUE" and tokens[first].off2int() > pjit.attr:
|
||||||
assert_next = tokens[min(last + 1, n - 1)]
|
assert_next = tokens[min(last + 1, n - 1)]
|
||||||
return assert_next != "RAISE_VARARGS_1"
|
return assert_next != "RAISE_VARARGS_1"
|
||||||
|
elif rule == ("testfalsel", ("expr", "jmp_true")):
|
||||||
|
pjit = tokens[min(last - 1, n - 2)]
|
||||||
|
# If we have a backwards (looping) jump then this is
|
||||||
|
# really a testtrue. But "asserts" work funny
|
||||||
|
if pjit == "POP_JUMP_IF_TRUE" and tokens[first].off2int() > pjit.attr:
|
||||||
|
assert_next = tokens[min(last + 1, n - 1)]
|
||||||
|
return assert_next == "RAISE_VARARGS_1"
|
||||||
return False
|
return False
|
||||||
|
@@ -148,6 +148,7 @@ def customize_for_version37(self, version):
|
|||||||
"list_if37_not": (" if not %p%c", (0, 27), 1),
|
"list_if37_not": (" if not %p%c", (0, 27), 1),
|
||||||
"testfalse_not_or": ("not %c or %c", (0, "expr"), (2, "expr")),
|
"testfalse_not_or": ("not %c or %c", (0, "expr"), (2, "expr")),
|
||||||
"testfalse_not_and": ("not (%c)", 0),
|
"testfalse_not_and": ("not (%c)", 0),
|
||||||
|
"testfalsel": ("not %c", (0, "expr")),
|
||||||
"try_except36": ("%|try:\n%+%c%-%c\n\n", 1, -2),
|
"try_except36": ("%|try:\n%+%c%-%c\n\n", 1, -2),
|
||||||
"tryfinally36": ("%|try:\n%+%c%-%|finally:\n%+%c%-\n\n", (1, "returns"), 3),
|
"tryfinally36": ("%|try:\n%+%c%-%|finally:\n%+%c%-\n\n", (1, "returns"), 3),
|
||||||
"unmap_dict": ("{**%C}", (0, -1, ", **")),
|
"unmap_dict": ("{**%C}", (0, -1, ", **")),
|
||||||
|
Reference in New Issue
Block a user