X Tutup
Skip to content

Commit ae980e4

Browse files
committed
Base 2.5 off of 2.6. Some other small bugs.
1 parent 21216b4 commit ae980e4

File tree

7 files changed

+35
-355
lines changed

7 files changed

+35
-355
lines changed
-311 Bytes
Binary file not shown.

uncompyle6/parser.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,10 @@ def p_jump(self, args):
200200
_jump ::= JUMP_BACK
201201
202202
# Note: Python < 2.7 doesn't have POP_JUMP_IF ...
203+
# FIXME: segregate 2.7+
204+
203205
jmp_false ::= POP_JUMP_IF_FALSE
204-
jmp_false ::= JUMP_IF_FALSE
205206
jmp_true ::= POP_JUMP_IF_TRUE
206-
jmp_true ::= JUMP_IF_TRUE
207207
208208
# Zero or more COME_FROM
209209
# loops can have this
@@ -465,10 +465,14 @@ def p_expr(self, args):
465465
_mklambda ::= load_closure mklambda
466466
_mklambda ::= mklambda
467467
468+
# Note: Python < 2.7 doesn't have *POP* or this. Remove from here?
469+
# FIXME: segregate 2.7+
470+
468471
or ::= expr JUMP_IF_TRUE_OR_POP expr COME_FROM
472+
and ::= expr JUMP_IF_FALSE_OR_POP expr COME_FROM
473+
469474
or ::= expr jmp_true expr come_from_opt
470475
and ::= expr jmp_false expr come_from_opt
471-
and ::= expr JUMP_IF_FALSE_OR_POP expr COME_FROM
472476
and2 ::= _jump jmp_false COME_FROM expr COME_FROM
473477
474478
expr ::= conditional
@@ -485,7 +489,9 @@ def p_expr(self, args):
485489
ret_expr_or_cond ::= ret_cond
486490
ret_expr_or_cond ::= ret_cond_not
487491
488-
# Note: Python < 2.7 doesn't use this. Remove from here?
492+
# Note: Python < 2.7 doesn't have *POP* or this. Remove from here?
493+
# FIXME: segregate 2.7+
494+
489495
ret_and ::= expr JUMP_IF_FALSE_OR_POP ret_expr_or_cond COME_FROM
490496
ret_or ::= expr JUMP_IF_TRUE_OR_POP ret_expr_or_cond COME_FROM
491497
ret_cond ::= expr POP_JUMP_IF_FALSE expr RETURN_END_IF ret_expr_or_cond
@@ -589,6 +595,13 @@ def get_python_parser(version, debug_parser, compile_mode='exec'):
589595
p = parse23.Python23Parser(debug_parser)
590596
else:
591597
p = parse23.Python23ParserSingle(debug_parser)
598+
elif version == 2.5:
599+
# For now, we'll consider 2.5 exactly like 2.6
600+
import uncompyle6.parsers.parse26 as parse25
601+
if compile_mode == 'exec':
602+
p = parse25.Python26Parser(debug_parser)
603+
else:
604+
p = parse25.Python26ParserSingle(debug_parser)
592605
elif version == 2.6:
593606
import uncompyle6.parsers.parse26 as parse26
594607
if compile_mode == 'exec':

uncompyle6/parsers/parse26.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,23 @@ def p_ret26(self, args):
107107
ret_cond ::= expr jmp_false expr RETURN_END_IF come_from_pop ret_expr_or_cond
108108
ret_cond ::= expr jmp_false expr ret_expr_or_cond
109109
ret_cond_not ::= expr jmp_true expr RETURN_END_IF come_from_pop ret_expr_or_cond
110+
111+
# FIXME: split into Python 2.5
112+
ret_cond ::= expr jmp_false expr JUMP_RETURN come_from_pop ret_expr_or_cond
113+
ret_or ::= expr jmp_true ret_expr_or_cond come_froms
110114
'''
111115

112116
def p_except26(self, args):
113117
'''
114118
except_suite ::= c_stmts_opt jmp_abs new_block
115119
'''
116120

121+
def p_jump26(self, args):
122+
"""
123+
jmp_false ::= JUMP_IF_FALSE
124+
jmp_true ::= JUMP_IF_TRUE
125+
"""
126+
117127

118128
class Python26ParserSingle(Python2Parser, PythonParserSingle):
119129
pass

uncompyle6/parsers/parse27.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def p_misc27(self, args):
2828
_ifstmts_jump ::= c_stmts_opt JUMP_FORWARD COME_FROM
2929
"""
3030

31-
class Python26ParserSingle(Python2Parser, PythonParserSingle):
31+
class Python27ParserSingle(Python27Parser, PythonParserSingle):
3232
pass
3333

3434
if __name__ == '__main__':

uncompyle6/scanners/scanner2.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ def unmangle(name):
188188
and self.code[offset+3] not in (self.opc.END_FINALLY,
189189
self.opc.POP_BLOCK)
190190
and offset not in self.not_continue):
191-
print("WOOT", target, offset, self.stmts)
192191
opname = 'CONTINUE'
193192
else:
194193
opname = 'JUMP_BACK'
@@ -481,7 +480,6 @@ def detect_structure(self, pos, op=None):
481480
target = self.get_target(pos, op)
482481
end = self.restrict_to_parent(target, parent)
483482
if target != end:
484-
print("XXXX", pos, end)
485483
self.fixed_jumps[pos] = end
486484
# print target, end, parent
487485
# Add the try block
@@ -517,7 +515,7 @@ def detect_structure(self, pos, op=None):
517515
if end_else != start_else:
518516
r_end_else = self.restrict_to_parent(end_else, parent)
519517
# May be able to drop the 2.7 test.
520-
if self.version == 2.7 and i > r_end_else:
518+
if self.version == 2.7:
521519
self.structs.append({'type': 'try-else',
522520
'start': i+1,
523521
'end': r_end_else})

0 commit comments

Comments
 (0)
X Tutup