Пример #1
0
    def test_static_value_dereference(self):
        _, result = bootstrap_function(
            function_lit(
                return_op(static_op(addition_op(literal_op(5),
                                                literal_op(37))))))

        self.assertEquals(result.caught_break_mode, "return")
        self.assertEquals(result.value, 42)
Пример #2
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())))
Пример #3
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)
Пример #4
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)
Пример #5
0
    def __call__(self, expression):
        from lockdown.executor.raw_code_factories import dereference_op, assignment_op, \
            literal_op, dereference, context_op

        debug_info = get_debug_info_from_opcode(expression)

        if expression._get("opcode", None) == "unbound_dereference":
            reference = expression.reference
            bound_countext_op, is_static = self.search_for_reference(
                reference, debug_info)

            if bound_countext_op:
                new_dereference = dereference_op(bound_countext_op,
                                                 literal_op(reference), True,
                                                 **debug_info)
                if is_static:
                    new_dereference = static_op(new_dereference)
                get_manager(new_dereference).add_composite_type(
                    DEFAULT_READONLY_COMPOSITE_TYPE)
                return new_dereference
            else:
                new_dereference = dynamic_dereference_op(
                    reference, **debug_info)
                get_manager(new_dereference).add_composite_type(
                    DEFAULT_READONLY_COMPOSITE_TYPE)
                return new_dereference

        if expression._get("opcode", None) == "unbound_assignment":
            reference = expression.reference
            bound_countext_op, _ = self.search_for_reference(
                reference, debug_info)

            if bound_countext_op:
                new_assignment = assignment_op(bound_countext_op,
                                               literal_op(reference),
                                               expression.rvalue, **debug_info)
                get_manager(new_assignment).add_composite_type(
                    DEFAULT_READONLY_COMPOSITE_TYPE)
                return new_assignment
            else:
                raise FatalError()  # TODO, dynamic assignment

        return expression
Пример #6
0
 def visitStaticExpression(self, ctx):
     return static_op(self.visit(ctx.expression()))