diff --git a/pylingual/control_flow_reconstruction/templates/Generator.py b/pylingual/control_flow_reconstruction/templates/Generator.py index c6d17e8..87be641 100644 --- a/pylingual/control_flow_reconstruction/templates/Generator.py +++ b/pylingual/control_flow_reconstruction/templates/Generator.py @@ -20,6 +20,21 @@ class Await3_12(ControlFlowTemplate): to_indented_source = defer_source_to("awaited") +@register_template(0, 0) +class AwaitWith3_12(ControlFlowTemplate): + template = T( + awaited=~N("SEND", None).with_cond(no_back_edges), + SEND=~N("YIELD_VALUE", "CLEANUP_THROW").with_in_deg(2).with_cond(exact_instructions("SEND")), + YIELD_VALUE=N("JUMP_BACK_NO_INT", None, "CLEANUP_THROW").with_in_deg(1).with_cond(exact_instructions("YIELD_VALUE")), + JUMP_BACK_NO_INT=~N("SEND", None).with_cond(exact_instructions("JUMP_BACKWARD_NO_INTERRUPT")), + CLEANUP_THROW=N.tail(), + ) + + try_match = make_try_match({EdgeKind.Fall: "CLEANUP_THROW"}, "awaited", "SEND", "YIELD_VALUE", "JUMP_BACK_NO_INT") + + to_indented_source = defer_source_to("awaited") + + @register_template(0, 0) class Generator3_12(ControlFlowTemplate): template = T( diff --git a/pylingual/control_flow_reconstruction/templates/With.py b/pylingual/control_flow_reconstruction/templates/With.py index 331036b..1d7c9f2 100644 --- a/pylingual/control_flow_reconstruction/templates/With.py +++ b/pylingual/control_flow_reconstruction/templates/With.py @@ -6,17 +6,18 @@ class WithCleanup3_11(ControlFlowTemplate): template = T( start=N("reraise", "poptop", "exc").with_cond(starting_instructions("PUSH_EXC_INFO", "WITH_EXCEPT_START")), reraise=N(None, None, "exc").with_cond(exact_instructions("RERAISE")).with_in_deg(1), - poptop=N("tail", None, "exc").with_cond(exact_instructions("POP_TOP")).with_in_deg(1), + poptop=N("pop_exc", None, "exc").with_cond(exact_instructions("POP_TOP")).with_in_deg(1), exc=+N().with_cond(exact_instructions("COPY", "POP_EXCEPT", "RERAISE")).with_in_deg(3), - tail=~N.tail().with_cond(starting_instructions("POP_EXCEPT", "POP_TOP", "POP_TOP")).with_in_deg(1), + pop_exc=~N("tail.", None).with_cond(starting_instructions("POP_EXCEPT", "POP_TOP")).with_in_deg(1), + tail=N.tail(), ) - try_match = make_try_match({}, "start", "reraise", "poptop", "exc", "tail") + try_match = make_try_match({EdgeKind.Fall: "tail"}, "start", "reraise", "poptop", "exc", "pop_exc") @to_indented_source def to_indented_source(): """ - {tail} + {pop_exc} """ @@ -25,17 +26,19 @@ class With3_11(ControlFlowTemplate): template = T( setup_with=~N("with_body", None), with_body=N("normal_cleanup.", None, "exc_cleanup").with_in_deg(1), - exc_cleanup=N.tail().of_subtemplate(WithCleanup3_11).with_in_deg(1), - normal_cleanup=~N.tail(), + exc_cleanup=~N("tail.", None).of_subtemplate(WithCleanup3_11).with_in_deg(1), + normal_cleanup=~N("tail.", None).with_in_deg(1), + tail=N.tail(), ) - try_match = make_try_match({EdgeKind.Fall: "normal_cleanup"}, "setup_with", "with_body", "exc_cleanup") + try_match = make_try_match({EdgeKind.Fall: "tail"}, "setup_with", "with_body", "exc_cleanup", "normal_cleanup") @to_indented_source def to_indented_source(): """ {setup_with} {with_body} + {exc_cleanup} """