Skip to content

Commit 80a4ad4

Browse files
committed
Python 3.0 while1 if bug...
Is a workaround. We really need more tagging in of SETUP_LOOP and COME_FROM.
1 parent 50c2e1b commit 80a4ad4

File tree

7 files changed

+33
-7
lines changed

7 files changed

+33
-7
lines changed
222 Bytes
Binary file not shown.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# From python 3.4 sre.pyc
2+
while 1:
3+
if __file__:
4+
while 1:
5+
if __file__:
6+
break
7+
raise RuntimeError
8+
else:
9+
raise RuntimeError

uncompyle6/parsers/parse3.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ def p_loop_stmt3(self, args):
337337
338338
whileelsestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK POP_BLOCK
339339
else_suite COME_FROM_LOOP
340+
341+
# FIXME: This gets confused with if/else in a loop. But while/else in Python
342+
# is probably pretty rare.
340343
while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK
341344
else_suite COME_FROM_LOOP
342345

uncompyle6/parsers/parse30.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@ def p_30(self, args):
2323
jmp_true ::= JUMP_IF_TRUE POP_TOP
2424
jmp_false ::= JUMP_IF_FALSE POP_TOP
2525
26-
while1elsestmt ::= SETUP_LOOP l_stmts POP_TOP else_suite COME_FROM_LOOP JUMP_BACK
26+
# Used to keep index order the same in semantic actions
27+
jb_pop_top ::= JUMP_BACK POP_TOP
28+
29+
# FIXME: Add COME_FROM designators
30+
# This gets confused with while1elsestmt. But this is probably more common
31+
while1stmt ::= SETUP_LOOP l_stmts COME_FROM_LOOP
32+
33+
else_suitel ::= l_stmts COME_FROM_LOOP JUMP_BACK
34+
35+
ifelsestmtl ::= testexpr c_stmts_opt jb_pop_top else_suitel
2736
2837
withasstmt ::= expr setupwithas designator suite_stmts_opt
2938
POP_BLOCK LOAD_CONST COME_FROM_FINALLY

uncompyle6/scanners/scanner3.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def ingest(self, co, classname=None, code_objects={}, show_asm=None):
149149
"""
150150

151151
show_asm = self.show_asm if not show_asm else show_asm
152-
# show_asm = 'before'
152+
# show_asm = 'after'
153153
if show_asm in ('both', 'before'):
154154
bytecode = Bytecode(co, self.opc)
155155
for instr in bytecode.get_instructions(co):
@@ -314,7 +314,9 @@ def ingest(self, co, classname=None, code_objects={}, show_asm=None):
314314
if target <= inst.offset:
315315
next_opname = self.opname[self.code[inst.offset+3]]
316316
if (inst.offset in self.stmts and
317-
next_opname not in ('END_FINALLY', 'POP_BLOCK')
317+
next_opname not in ('END_FINALLY', 'POP_BLOCK',
318+
# Python 3.0 only uses POP_TOP
319+
'POP_TOP')
318320
and inst.offset not in self.not_continue):
319321
opname = 'CONTINUE'
320322
else:

uncompyle6/semantics/fragments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1772,7 +1772,7 @@ def deparse_code(version, co, out=StringIO(), showasm=False, showast=False,
17721772

17731773
if deparsed.ast_errors:
17741774
deparsed.write("# NOTE: have decompilation errors.\n")
1775-
deparsed.write("# Use -t option to show full of errors.")
1775+
deparsed.write("# Use -t option to show full context.")
17761776
for err in deparsed.ast_errors:
17771777
deparsed.write(err)
17781778
deparsed.ERROR = True

uncompyle6/semantics/pysource.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@
311311
'whileTruestmt': ( '%|while True:\n%+%c%-\n\n', 1 ),
312312
'whilestmt': ( '%|while %c:\n%+%c%-\n\n', 1, 2 ),
313313
'while1stmt': ( '%|while 1:\n%+%c%-\n\n', 1 ),
314-
'while1elsestmt': ( '%|while 1:\n%+%c%-%|else:\n%+%c%-\n\n', 1, 3 ),
314+
'while1elsestmt': ( '%|while 1:\n%+%c%-%|else:\n%+%c%-\n\n', 1, -2 ),
315315
'whileelsestmt': ( '%|while %c:\n%+%c%-%|else:\n%+%c%-\n\n', 1, 2, -2 ),
316316
'whileelselaststmt': ( '%|while %c:\n%+%c%-%|else:\n%+%c%-', 1, 2, -2 ),
317317
'forstmt': ( '%|for %c in %c:\n%+%c%-\n\n', 3, 1, 4 ),
@@ -1010,7 +1010,10 @@ def n_exec_stmt(self, node):
10101010
def n_ifelsestmt(self, node, preprocess=False):
10111011
else_suite = node[3]
10121012

1013-
n = else_suite[0]
1013+
try:
1014+
n = else_suite[0]
1015+
except:
1016+
from trepan.api import debug; debug()
10141017

10151018
if len(n) == 1 == len(n[0]) and n[0] == '_stmts':
10161019
n = n[0][0][0]
@@ -2322,7 +2325,7 @@ def deparse_code(version, co, out=sys.stdout, showasm=None, showast=False,
23222325

23232326
if deparsed.ast_errors:
23242327
deparsed.write("# NOTE: have decompilation errors.\n")
2325-
deparsed.write("# Use -t option to full context of errors.")
2328+
deparsed.write("# Use -t option to show full context.")
23262329
for err in deparsed.ast_errors:
23272330
deparsed.write(err)
23282331
raise SourceWalkerError("Deparsing hit an internal grammar-rule bug")

0 commit comments

Comments
 (0)