Python 3.(4?) while1 bug

Clean up while1 grammar a tad
This commit is contained in:
rocky
2016-07-11 10:09:10 -04:00
parent f571f6dfce
commit 9fdf70f68d
5 changed files with 12 additions and 7 deletions

View File

@@ -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

View File

@@ -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):

View File

@@ -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
"""

View File

@@ -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):

View File

@@ -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)):