More Python 3.0 custom "if" statment handling.

This commit is contained in:
rocky
2019-11-10 18:44:43 -05:00
parent 04c2240d63
commit 07ec8fa1fb
4 changed files with 36 additions and 2 deletions

Binary file not shown.

View File

@@ -7,3 +7,14 @@ def main(args, f):
func(f, sys.stdout.buffer)
else:
func(sys.stdin.buffer, sys.stdout.buffer)
# From Python 3.0 _markupbase.py.
#
# The Problem was in the way "if"s are generated in 3.0 which is sort
# of like a more optimized Python 2.6, with reduced extraneous jumps,
# but still 2.6-ish and not 2.7- or 3.1-ish.
def parse_marked_section(fn, i, rawdata, report=1):
if report:
j = 1
fn(rawdata[i: j])
return 10

View File

@@ -91,6 +91,9 @@ class Python30Parser(Python31Parser):
except_suite ::= c_stmts POP_EXCEPT jump_except POP_TOP
except_suite_finalize ::= SETUP_FINALLY c_stmts_opt except_var_finalize END_FINALLY
_jump COME_FROM POP_TOP
_ifstmts_jump ::= c_stmts_opt JUMP_FORWARD COME_FROM POP_TOP
jump_except ::= JUMP_FORWARD COME_FROM POP_TOP
jump_except ::= JUMP_ABSOLUTE COME_FROM POP_TOP
or ::= expr jmp_false expr jmp_true expr
@@ -101,8 +104,22 @@ class Python30Parser(Python31Parser):
# JUMP_IF_FALSE
# The below rules in fact are the same or similar.
jmp_true ::= JUMP_IF_TRUE POP_TOP
jmp_false ::= JUMP_IF_FALSE _come_froms POP_TOP
jmp_true ::= JUMP_IF_TRUE POP_TOP
jmp_false ::= JUMP_IF_FALSE _come_froms POP_TOP
jmp_false_then ::= JUMP_IF_FALSE POP_TOP
# We don't have hacky THEN detection, so we do it
# in the grammar below which is also somewhat hacky.
stmt ::= ifstmt30
ifstmt30 ::= testexpr_then _ifstmts_jump30
testexpr_then ::= testfalse_then
testfalse_then ::= expr jmp_false_then
call_stmt ::= expr COME_FROM
_ifstmts_jump30 ::= c_stmts POP_TOP
################################################################################
for_block ::= l_stmts_opt _come_froms POP_TOP JUMP_BACK

View File

@@ -181,6 +181,12 @@ def customize_for_version3(self, version):
# the iteration variable. These rules we can ignore
# since we pick up the iteration variable some other way and
# we definitely don't include in the source _[dd].
TABLE_DIRECT.update({
'ifstmt30': ( '%|if %c:\n%+%c%-',
(0, "testexpr_then"),
(1, "_ifstmts_jump30") ),
})
def n_comp_iter(node):
if node[0] == "expr":
n = node[0][0]