From ce7015f382f2b6fb80c52697c628264b772f85bb Mon Sep 17 00:00:00 2001 From: rocky Date: Wed, 1 May 2019 11:10:16 -0400 Subject: [PATCH] Improve 3.x while1 reduction elimination --- uncompyle6/parsers/parse3.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index ae516e2a..23979936 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -1214,7 +1214,7 @@ class Python3Parser(PythonParser): pass elif lhs == 'while1stmt': - # If there is a fall through to the COME_FROM_LOOP. then this is + # If there is a fall through to the COME_FROM_LOOP, then this is # not a while 1. So the instruction before should either be a # JUMP_BACK or the instruction before should not be the target of a # jump. (Well that last clause i not quite right; that target could be @@ -1225,10 +1225,11 @@ class Python3Parser(PythonParser): cfl = last assert tokens[cfl] == 'COME_FROM_LOOP' - if tokens[cfl-1] != 'JUMP_BACK': - cfl_offset = tokens[cfl-1].offset - insn = next(i for i in self.insts if cfl_offset == i.offset) - if insn and insn.is_jump_target: + for i in range(cfl-1, first, -1): + if tokens[i] != 'POP_BLOCK': + break + if tokens[i].kind not in ('JUMP_BACK', 'RETURN_VALUE'): + if not tokens[i].kind.startswith('COME_FROM'): return True # Check that the SETUP_LOOP jumps to the offset after the