Update from master branch uncompyle2

This commit is contained in:
Mysterie
2012-09-20 12:31:22 +02:00
parent fd44d2e19f
commit 1e2b896134
5 changed files with 21 additions and 4 deletions

View File

@@ -514,6 +514,8 @@ class Parser(GenericASTBuilder):
while1stmt ::= SETUP_LOOP l_stmts JUMP_BACK COME_FROM
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
POP_BLOCK

View File

@@ -168,6 +168,7 @@ class Scanner:
oparg = self.get_argument(offset) + extended_arg
extended_arg = 0
if op == dis.EXTENDED_ARG:
raise 'TODO'
extended_arg = oparg * 65536L
continue
if op in dis.hasconst:
@@ -746,6 +747,10 @@ class Scanner:
(line_no, next_line_byte) = self.lines[pos]
jump_back = self.last_instr(start, end, JA,
next_line_byte, False)
if jump_back and jump_back != self.prev[end] and code[jump_back+3] in (JA, JF):
if code[self.prev[end]] == RETURN_VALUE or \
(code[self.prev[end]] == POP_BLOCK and code[self.prev[self.prev[end]]] == RETURN_VALUE):
jump_back = None
if not jump_back: # loop suite ends in return. wtf right?
jump_back = self.last_instr(start, end, RETURN_VALUE)
if not jump_back:
@@ -785,7 +790,7 @@ class Scanner:
test_target = self.get_target(test)
if test_target > (jump_back+3):
jump_back = test_target
self.not_continue.add(jump_back)
self.loops.append(target)
self.structs.append({'type': loop_type + '-loop',
'start': target,

View File

@@ -168,6 +168,7 @@ class Scanner:
oparg = self.get_argument(offset) + extended_arg
extended_arg = 0
if op == dis.EXTENDED_ARG:
raise 'TODO'
extended_arg = oparg * 65536L
continue
if op in dis.hasconst:
@@ -740,6 +741,10 @@ class Scanner:
(line_no, next_line_byte) = self.lines[pos]
jump_back = self.last_instr(start, end, JA,
next_line_byte, False)
if jump_back and jump_back != self.prev[end] and code[jump_back+3] in (JA, JF):
if code[self.prev[end]] == RETURN_VALUE or \
(code[self.prev[end]] == POP_BLOCK and code[self.prev[self.prev[end]]] == RETURN_VALUE):
jump_back = None
if not jump_back: # loop suite ends in return. wtf right?
jump_back = self.last_instr(start, end, RETURN_VALUE)
if not jump_back:
@@ -779,7 +784,7 @@ class Scanner:
test_target = self.get_target(test)
if test_target > (jump_back+3):
jump_back = test_target
self.not_continue.add(jump_back)
self.loops.append(target)
self.structs.append({'type': loop_type + '-loop',
'start': target,

View File

@@ -538,6 +538,10 @@ class Scanner:
(line_no, next_line_byte) = self.lines[pos]
jump_back = self.last_instr(start, end, JA,
next_line_byte, False)
if jump_back and jump_back != self.prev[end] and code[jump_back+3] in (JA, JF):
if code[self.prev[end]] == RETURN_VALUE or \
(code[self.prev[end]] == POP_BLOCK and code[self.prev[self.prev[end]]] == RETURN_VALUE):
jump_back = None
if not jump_back: # loop suite ends in return. wtf right?
jump_back = self.last_instr(start, end, RETURN_VALUE) + 1
if not jump_back:
@@ -576,7 +580,7 @@ class Scanner:
test_target = self.get_target(test)
if test_target > (jump_back+3):
jump_back = test_target
self.not_continue.add(jump_back)
self.loops.append(target)
self.structs.append({'type': loop_type + '-loop',
'start': target,

View File

@@ -258,6 +258,7 @@ TABLE_DIRECT = {
'whilestmt': ( '%|while %c:\n%+%c%-\n\n', 1, 2 ),
'while1stmt': ( '%|while 1:\n%+%c%-\n\n', 1 ),
'while1elsestmt': ( '%|while 1:\n%+%c%-%|else:\n%+%c%-\n\n', 1, 3 ),
'whileelsestmt': ( '%|while %c:\n%+%c%-%|else:\n%+%c%-\n\n', 1, 2, -2 ),
'whileelselaststmt': ( '%|while %c:\n%+%c%-%|else:\n%+%c%-', 1, 2, -2 ),
'forstmt': ( '%|for %c in %c:\n%+%c%-\n\n', 3, 1, 4 ),
@@ -1360,7 +1361,7 @@ class Walker(GenericASTTraversal, object):
#else:
# print ast[-1][-1]
for g in find_globals(ast, {}).keys():
for g in find_globals(ast, set()):
self.print_(indent, 'global ', g)
self.gen_source(ast, code._customize)