WIP deal with JUMP_IF_{TRUE,FALSE} vs with POP version

This commit is contained in:
rocky
2016-06-24 20:06:10 -04:00
parent fa7d8f955a
commit fa84f4277a
4 changed files with 17 additions and 3 deletions

View File

@@ -179,6 +179,9 @@ class Python2Parser(PythonParser):
tryelsestmtl ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
try_middle else_suitel COME_FROM
trystmt ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
try_middle COME_FROM
except_stmts ::= except_stmts except_stmt
except_stmts ::= except_stmt

View File

@@ -38,11 +38,21 @@ class Python26Parser(Python2Parser):
"""
def p_whilestmt(self, args):
"""
whilestmt ::= SETUP_LOOP
testexpr
l_stmts_opt jb_pop
POP_BLOCK _come_from
"""
def p_misc26(self, args):
"""
jmp_true ::= JUMP_IF_TRUE POP_TOP
jmp_false ::= JUMP_IF_FALSE POP_TOP
jf_pop ::= JUMP_FORWARD POP_TOP
jb_pop ::= JUMP_BACK POP_TOP
_ifstmts_jump ::= c_stmts_opt jf_pop COME_FROM
"""

View File

@@ -10,9 +10,6 @@ class Python27Parser(Python2Parser):
def p_try27(self, args):
"""
trystmt ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
try_middle COME_FROM
try_middle ::= JUMP_FORWARD COME_FROM except_stmts
END_FINALLY COME_FROM
try_middle ::= jmp_abs COME_FROM except_stmts

View File

@@ -704,6 +704,10 @@ class Scanner2(scan.Scanner):
if op in (self.opc.JUMP_IF_FALSE_OR_POP, self.opc.JUMP_IF_TRUE_OR_POP):
if (oparg > i):
label = oparg
elif self.version < 2.7 and op in self.opc.hasjabs:
if op in (self.opc.JUMP_IF_FALSE, self.opc.JUMP_IF_TRUE):
if (oparg > i):
label = oparg
if label is not None and label != -1:
targets[label] = targets.get(label, []) + [i]