예제 #1
0
def build_executor(raw_code):
    return function_lit(
        transform_op(
            "yield", "read",
            reset_op(
                close_op(
                    static_op(
                        prepare_op(
                            literal_op(
                                parse(raw_code,
                                      post_chain_function=CodeBlockBuilder(
                                          [build_looper()]))))), context_op()),
                nop())))
예제 #2
0
    def test_basic_with_inferred_local_type(self):
        _, result = bootstrap_function(
            function_lit(
                no_value_type(), infer_all(), inferred_type(),
                close_op(
                    static_op(
                        prepare_op(
                            literal_op(
                                function_lit(no_value_type(), infer_all(),
                                             return_op(literal_op(42)))))),
                    context_op()),
                return_op(
                    invoke_op(
                        dereference_op(context_op(), literal_op("local"),
                                       True)))))

        self.assertEquals(result.caught_break_mode, "return")
        self.assertEquals(result.value, 42)
예제 #3
0
    def test_basic(self):
        _, result = bootstrap_function(
            function_lit(
                no_value_type(), build_break_types(int_type()),
                return_op(
                    invoke_op(
                        close_op(
                            static_op(
                                prepare_op(
                                    literal_op(
                                        function_lit(
                                            no_value_type(),
                                            build_break_types(int_type()),
                                            return_op(literal_op(42)))))),
                            context_op())))))

        self.assertEquals(result.caught_break_mode, "return")
        self.assertEquals(result.value, 42)
예제 #4
0
def build_looper():
    return invoke_op(
        close_op(prepare_op(shift_op(literal_op(42), any_type())),
                 context_op()), nop())