Add 3.7 "testfalsel" for looping conditions

This commit is contained in:
rocky
2020-01-14 18:41:39 -05:00
parent e2cbf5f4bd
commit 5f230fa177
6 changed files with 22 additions and 3 deletions

View File

@@ -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":

View File

@@ -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