diff --git a/test/stdlib/3.7-exclude.sh b/test/stdlib/3.7-exclude.sh index d812369c..b11c206b 100644 --- a/test/stdlib/3.7-exclude.sh +++ b/test/stdlib/3.7-exclude.sh @@ -21,7 +21,6 @@ SKIP_TESTS=( [test_context.py]=1 [test_coroutines.py]=1 # Parse error [test_codecs.py]=1 - [test_complex.py]=1 # Investigate [test_crypt.py]=1 # Parse error [test_ctypes.py]=1 # it fails on its own [test_curses.py]=1 # Parse error diff --git a/uncompyle6/parsers/parse37.py b/uncompyle6/parsers/parse37.py index 49e4d20d..7850040a 100644 --- a/uncompyle6/parsers/parse37.py +++ b/uncompyle6/parsers/parse37.py @@ -641,7 +641,6 @@ class Python37Parser(Python37BaseParser): expr ::= if_exp_37b 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 - or ::= expr jmp_true expr jmp_false_cf ::= POP_JUMP_IF_FALSE COME_FROM comp_if ::= or jmp_false_cf comp_iter """ @@ -922,7 +921,14 @@ class Python37Parser(Python37BaseParser): testfalse ::= testfalse_not_or testfalse ::= testfalse_not_and 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 jifop_come_from expr diff --git a/uncompyle6/parsers/parse37base.py b/uncompyle6/parsers/parse37base.py index c5c30049..0ab95360 100644 --- a/uncompyle6/parsers/parse37base.py +++ b/uncompyle6/parsers/parse37base.py @@ -999,6 +999,7 @@ class Python37BaseParser(PythonParser): "ifstmtl": ifstmt, "or": or_check, "testtrue": testtrue, + "testfalsel": testtrue, "while1elsestmt": while1elsestmt, "while1stmt": while1stmt, "try_elsestmtl38": tryelsestmtl3, @@ -1019,6 +1020,7 @@ class Python37BaseParser(PythonParser): self.check_reduce["import_from37"] = "AST" self.check_reduce["or"] = "AST" self.check_reduce["testtrue"] = "tokens" + self.check_reduce["testfalsel"] = "tokens" return def custom_classfunc_rule(self, opname, token, customize, next_token): diff --git a/uncompyle6/parsers/reducecheck/or_check.py b/uncompyle6/parsers/reducecheck/or_check.py index 218812b5..e72c33be 100644 --- a/uncompyle6/parsers/reducecheck/or_check.py +++ b/uncompyle6/parsers/reducecheck/or_check.py @@ -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": return True + first_offset = tokens[first].off2int() jmp_true_target = ast[1][0].attr + if jmp_true_target < first_offset: + return False + jmp_false = tokens[last] # If the jmp is backwards if jmp_false == "POP_JUMP_IF_FALSE": diff --git a/uncompyle6/parsers/reducecheck/testtrue.py b/uncompyle6/parsers/reducecheck/testtrue.py index 9f859acc..45450de0 100644 --- a/uncompyle6/parsers/reducecheck/testtrue.py +++ b/uncompyle6/parsers/reducecheck/testtrue.py @@ -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: assert_next = tokens[min(last + 1, n - 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 diff --git a/uncompyle6/semantics/customize37.py b/uncompyle6/semantics/customize37.py index 092471f6..3ec60c0c 100644 --- a/uncompyle6/semantics/customize37.py +++ b/uncompyle6/semantics/customize37.py @@ -148,6 +148,7 @@ def customize_for_version37(self, version): "list_if37_not": (" if not %p%c", (0, 27), 1), "testfalse_not_or": ("not %c or %c", (0, "expr"), (2, "expr")), "testfalse_not_and": ("not (%c)", 0), + "testfalsel": ("not %c", (0, "expr")), "try_except36": ("%|try:\n%+%c%-%c\n\n", 1, -2), "tryfinally36": ("%|try:\n%+%c%-%|finally:\n%+%c%-\n\n", (1, "returns"), 3), "unmap_dict": ("{**%C}", (0, -1, ", **")),