From 9fdf70f68d886e03d797ebcd67e9cd17fa3e8ee0 Mon Sep 17 00:00:00 2001 From: rocky Date: Mon, 11 Jul 2016 10:09:10 -0400 Subject: [PATCH] Python 3.(4?) while1 bug Clean up while1 grammar a tad --- uncompyle6/parser.py | 3 --- uncompyle6/parsers/parse26.py | 6 ++++-- uncompyle6/parsers/parse27.py | 5 ++++- uncompyle6/parsers/parse3.py | 1 + uncompyle6/scanners/scanner3.py | 4 +++- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/uncompyle6/parser.py b/uncompyle6/parser.py index efc69f68..51795bbe 100644 --- a/uncompyle6/parser.py +++ b/uncompyle6/parser.py @@ -294,9 +294,6 @@ class PythonParser(GenericASTBuilder): while1stmt ::= SETUP_LOOP l_stmts JUMP_BACK COME_FROM while1stmt ::= SETUP_LOOP l_stmts JUMP_BACK POP_BLOCK COME_FROM - # This is Python 2.7+; segregate - while1stmt ::= SETUP_LOOP return_stmts COME_FROM - while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK else_suite COME_FROM whileelsestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK diff --git a/uncompyle6/parsers/parse26.py b/uncompyle6/parsers/parse26.py index 651f5872..25437282 100644 --- a/uncompyle6/parsers/parse26.py +++ b/uncompyle6/parsers/parse26.py @@ -150,14 +150,16 @@ class Python26Parser(Python2Parser): whileelsestmt ::= SETUP_LOOP testexpr l_stmts_opt jb_pop POP_BLOCK else_suite COME_FROM - while1stmt ::= SETUP_LOOP return_stmts bp_come_from - return_stmt ::= ret_expr RETURN_END_IF come_from_pop return_stmt ::= ret_expr RETURN_VALUE come_from_pop return_if_stmt ::= ret_expr RETURN_END_IF come_from_pop iflaststmtl ::= testexpr c_stmts_opt JUMP_BACK come_from_pop iflaststmt ::= testexpr c_stmts_opt JUMP_ABSOLUTE come_from_pop + + # Common with 2.7 + while1stmt ::= SETUP_LOOP return_stmts bp_come_from + while1stmt ::= SETUP_LOOP return_stmts COME_FROM """ def p_comp26(self, args): diff --git a/uncompyle6/parsers/parse27.py b/uncompyle6/parsers/parse27.py index 29168671..49c4edb2 100644 --- a/uncompyle6/parsers/parse27.py +++ b/uncompyle6/parsers/parse27.py @@ -39,6 +39,7 @@ class Python27Parser(Python2Parser): _ifstmts_jump ::= c_stmts_opt JUMP_FORWARD COME_FROM jmp_false ::= POP_JUMP_IF_FALSE jmp_true ::= POP_JUMP_IF_TRUE + bp_come_from ::= POP_BLOCK COME_FROM """ @@ -55,7 +56,9 @@ class Python27Parser(Python2Parser): POP_BLOCK LOAD_CONST COME_FROM WITH_CLEANUP END_FINALLY - while1stmt ::= SETUP_LOOP l_stmts POP_BLOCK COME_FROM + # Common with 2.6 + while1stmt ::= SETUP_LOOP return_stmts bp_come_from + while1stmt ::= SETUP_LOOP return_stmts COME_FROM """ diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index 11bb9ffb..4c08ca80 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -273,6 +273,7 @@ class Python3Parser(PythonParser): # Python < 3.5 no POP BLOCK whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK _come_from whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK NOP _come_from + while1stmt ::= SETUP_LOOP l_stmts _come_from JUMP_BACK _come_from """ def p_genexpr3(self, args): diff --git a/uncompyle6/scanners/scanner3.py b/uncompyle6/scanners/scanner3.py index 20faae41..be49626d 100644 --- a/uncompyle6/scanners/scanner3.py +++ b/uncompyle6/scanners/scanner3.py @@ -307,7 +307,9 @@ class Scanner3(scan.Scanner): """ code = self.code codelen = len(code) - self.prev_op = [0] + # 2.x uses prev 3.x uses prev_op. Sigh + # Until we get this sorted out. + self.prev = self.prev_op = [0] for offset in self.op_range(0, codelen): op = code[offset] for _ in range(self.op_size(op)):