Cope more JUMP/POP_IF not being in 3.0...

more is probably needed though.
This commit is contained in:
rocky
2019-11-11 19:58:35 -05:00
parent 4abdffecb9
commit 9f250b49ee
4 changed files with 30 additions and 5 deletions

Binary file not shown.

View File

@@ -18,3 +18,13 @@ assert normpath(['.']) == []
assert normpath(['a', 'b', '..']) == ['a'] assert normpath(['a', 'b', '..']) == ['a']
assert normpath(['a', 'b', '', 'c']) == ['a', 'b', 'c'] assert normpath(['a', 'b', '', 'c']) == ['a', 'b', 'c']
assert normpath(['a', 'b', '.', '', 'c', '..']) == ['a', 'b'] assert normpath(['a', 'b', '.', '', 'c', '..']) == ['a', 'b']
# Adapted from 3.0.1 cgi.py
# Bug was in detecting "or" and "and" due to lack of PUSH/POP_IF instructions.
def handle(format, html, text):
formatter = (format and html) or text
return formatter
assert handle(False, False, True)
assert not handle(True, False, False)
assert handle(True, True, False)

View File

@@ -124,6 +124,10 @@ class Python30Parser(Python31Parser):
except_handler ::= jmp_abs COME_FROM_EXCEPT except_stmts except_handler ::= jmp_abs COME_FROM_EXCEPT except_stmts
COME_FROM POP_TOP END_FINALLY COME_FROM POP_TOP END_FINALLY
expr ::= or30
ret_or ::= or30
or30 ::= expr JUMP_IF_TRUE COME_FROM POP_TOP expr come_from_opt
################################################################################ ################################################################################
for_block ::= l_stmts_opt _come_froms POP_TOP JUMP_BACK for_block ::= l_stmts_opt _come_froms POP_TOP JUMP_BACK
@@ -168,15 +172,22 @@ class Python30Parser(Python31Parser):
whileelsestmt ::= SETUP_LOOP testexpr l_stmts JUMP_BACK POP_BLOCK whileelsestmt ::= SETUP_LOOP testexpr l_stmts JUMP_BACK POP_BLOCK
else_suitel COME_FROM_LOOP else_suitel COME_FROM_LOOP
# No JUMP_IF_FALSE_OR_POP # No JUMP_IF_FALSE_OR_POP, JUMP_IF_TRUE_OR_POP,
# POP_JUMP_IF_FALSE, or POP_JUMP_IF_TRUE
jmp_false ::= POP_JUMP_IF_FALSE
jmp_true ::= JUMP_IF_TRUE_OR_POP POP_TOP
compare_chained1 ::= expr DUP_TOP ROT_THREE COMPARE_OP JUMP_IF_FALSE_OR_POP compare_chained1 ::= expr DUP_TOP ROT_THREE COMPARE_OP JUMP_IF_FALSE_OR_POP
compare_chained1 COME_FROM compare_chained1 COME_FROM
compare_chained1 ::= expr DUP_TOP ROT_THREE COMPARE_OP JUMP_IF_FALSE_OR_POP compare_chained1 ::= expr DUP_TOP ROT_THREE COMPARE_OP JUMP_IF_FALSE_OR_POP
compare_chained2 COME_FROM compare_chained2 COME_FROM
ret_or ::= expr JUMP_IF_TRUE_OR_POP ret_expr_or_cond COME_FROM
or ::= expr JUMP_IF_TRUE_OR_POP expr COME_FROM
""") """)
self.check_reduce['iflaststmtl'] = 'AST' self.check_reduce["iflaststmtl"] = "AST"
# self.check_reduce['ifelsestmt'] = 'AST' self.check_reduce['ifstmt'] = "AST"
# self.check_reduce["ifelsestmt"] = "AST"
return return
def reduce_is_invalid(self, rule, ast, tokens, first, last): def reduce_is_invalid(self, rule, ast, tokens, first, last):
@@ -186,7 +197,7 @@ class Python30Parser(Python31Parser):
if invalid: if invalid:
return invalid return invalid
if ( if (
rule[0] in ("iflaststmtl",) and ast[0] == "testexpr" rule[0] in ("iflaststmtl", "ifstmt") and ast[0] == "testexpr"
): ):
testexpr = ast[0] testexpr = ast[0]
if testexpr[0] == "testfalse": if testexpr[0] == "testfalse":

View File

@@ -182,9 +182,13 @@ def customize_for_version3(self, version):
# since we pick up the iteration variable some other way and # since we pick up the iteration variable some other way and
# we definitely don't include in the source _[dd]. # we definitely don't include in the source _[dd].
TABLE_DIRECT.update({ TABLE_DIRECT.update({
'ifstmt30': ( '%|if %c:\n%+%c%-', 'ifstmt30': ( "%|if %c:\n%+%c%-",
(0, "testexpr_then"), (0, "testexpr_then"),
(1, "_ifstmts_jump30") ), (1, "_ifstmts_jump30") ),
"or30": ( "%c or %c",
(0, "expr"),
(4, "expr") ),
}) })
def n_comp_iter(node): def n_comp_iter(node):