diff --git a/test/bytecode_3.5/03_while-if-break.pyc b/test/bytecode_3.5/03_while-if-break.pyc index 5f971ce9..0c5501e3 100644 Binary files a/test/bytecode_3.5/03_while-if-break.pyc and b/test/bytecode_3.5/03_while-if-break.pyc differ diff --git a/test/simple_source/bug35/03_while-if-break.py b/test/simple_source/bug35/03_while-if-break.py index 21e3ed1b..13ab2e40 100644 --- a/test/simple_source/bug35/03_while-if-break.py +++ b/test/simple_source/bug35/03_while-if-break.py @@ -2,7 +2,7 @@ # while True and if / break def display_date(loop): while True: - if loop.time(): + if loop: break x = 5 diff --git a/uncompyle6/parsers/parse35.py b/uncompyle6/parsers/parse35.py index c228ce34..06682934 100644 --- a/uncompyle6/parsers/parse35.py +++ b/uncompyle6/parsers/parse35.py @@ -26,6 +26,14 @@ class Python35Parser(Python34Parser): while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK POP_BLOCK else_suite COME_FROM_LOOP + # The following rule is for Python 3.5+ where we can have stuff like + # while .. + # if + # ... + # the end of the if will jump back to the loop and there will be a COME_FROM + # after the jump + l_stmts ::= lastl_stmt COME_FROM l_stmts + # Python 3.5+ Await statement expr ::= await_expr await_expr ::= expr GET_AWAITABLE LOAD_CONST YIELD_FROM diff --git a/uncompyle6/scanner.py b/uncompyle6/scanner.py index acbe7ed9..f0de7b4b 100755 --- a/uncompyle6/scanner.py +++ b/uncompyle6/scanner.py @@ -208,6 +208,9 @@ class Scanner(object): Return a list with indexes to them or [] if none found. """ + + # FIXME: this is broken on 3.6+. Revise to use instructions self.insts + code = self.code assert(start >= 0 and end <= len(code)) diff --git a/uncompyle6/scanners/scanner3.py b/uncompyle6/scanners/scanner3.py index ced88098..4d87ac09 100644 --- a/uncompyle6/scanners/scanner3.py +++ b/uncompyle6/scanners/scanner3.py @@ -363,7 +363,7 @@ class Scanner3(Scanner): # FIXME: 0 isn't always correct target = self.get_target(inst.offset) if target <= inst.offset: - next_opname = self.opname[self.code[inst.offset+3]] + next_opname = self.insts[i+1].opname if (inst.offset in self.stmts and (self.version != 3.0 or (hasattr(inst, 'linestart'))) and (next_opname not in ('END_FINALLY', 'POP_BLOCK', @@ -948,12 +948,12 @@ class Scanner3(Scanner): self.not_continue.add(pre_rtarget) else: # For now, we'll only tag forward jump. - if self.version >= 3.6: + if self.version >= 3.5: if target > offset: self.fixed_jumps[offset] = target pass else: - # FIXME: This is probably a bug in < 3.6 and we should + # FIXME: This is probably a bug in < 3.5 and we should # instead use the above code. But until we smoke things # out we'll stick with it. if rtarget > offset: