예제 #1
0
def NoOp(t_pre: Place) -> Place:
    """Perform ``no_op_io``."""
    IOExists1(Place)(
        lambda t_post: (
            Requires(
                token(t_pre, 1) and
                no_op_io(t_pre, t_post) and
                MustTerminate(1)
            ),
            Ensures(
                token(t_post) and
                t_post == Result()
            ),
        )
    )
예제 #2
0
def End(t_pre: Place) -> Place:
    """Perform ``end_io``."""
    Requires(
        token(t_pre, 1) and
        end_io(t_pre) and
        MustTerminate(1)
    )
예제 #3
0
def Join(t_pre1: Place, t_pre2: Place) -> Place:
    """Perform ``join_io``."""
    IOExists1(Place)(
        lambda t_post: (
            Requires(
                token(t_pre1, 1) and
                token(t_pre2, 1) and
                join_io(t_pre1, t_pre2, t_post) and
                MustTerminate(1)
            ),
            Ensures(
                token(t_post) and
                t_post == Result()
            ),
        )
    )
예제 #4
0
def Split(t_pre: Place) -> Tuple[Place, Place]:
    """Perform ``split_io``."""
    IOExists2(Place, Place)(
        lambda t_post1, t_post2: (
            Requires(
                token(t_pre, 1) and
                split_io(t_pre, t_post1, t_post2) and
                MustTerminate(1)
            ),
            Ensures(
                token(t_post1) and
                t_post1 == Result()[0] and
                token(t_post2) and
                t_post2 == Result()[1]
            ),
        )
    )
예제 #5
0
def Eval(t_pre: Place, func: Callable[[T], V], arg: T) -> Tuple[V, Place]:
    IOExists2(Place, object)(
        lambda t_post, result: (
            Requires(
                token(t_pre, 1) and
                eval_io(t_pre, func, arg, result, t_post) and
                MustTerminate(1)
            ),
            Ensures(
                token(t_post) and
                t_post is Result()[1] and
                result is Result()[0]
                # and resul result == func(arg)
                # This is part of the contract but guaranteed via additional inhales after
                # any call to Eval, and cannot be part of the contract written here
                # because the fact that func can have an arbitrary precondition would make
                # the contract of Eval not well-formed.
            ),
        )
    )
예제 #6
0
def SetVar(t_pre: Place, value: int) -> Tuple[int, Place]:
    """Perform ``set_var_io``.

    .. note::

        Mypy does not allow generics as function arguments. Therefore,
        we have to use a concrete type for ``value``.
    """
    IOExists2(Place, int)(
        lambda t_post, result: (
            Requires(
                token(t_pre, 1) and
                set_var_io(t_pre, value, result, t_post) and
                MustTerminate(1)
            ),
            Ensures(
                token(t_post) and
                t_post == Result()[1] and
                result == Result()[0] and
                value == result
            ),
        )
    )