Beispiel #1
0
def read_write_int_twice4(t1: Place) -> Place:
    IOExists4(Place, Place, int, int)(
        lambda t2, t3, value1, value2: (
        Requires(
            token(t1, 2) and
            read_int_twice_io(t1, value1, value2, t2) and
            write_int_twice_io(t2, value1, value2, t3)
        ),
        Ensures(
            token(t3) and
            t3 == Result()
        ),
        )
    )

    Open(read_int_twice_io(t1))

    t2, number1 = read_int(t1)
    t3, number2 = read_int(t2)

    Open(write_int_twice_io(t3, number1, number2))

    #:: ExpectedOutput(call.precondition:insufficient.permission)
    t4 = write_int(t3, number2)
    #:: ExpectedOutput(carbon)(call.precondition:insufficient.permission)
    t5 = write_int(t4, number1)

    return t5
Beispiel #2
0
def read_write_int_twice1(t1: Place) -> Place:
    IOExists4(Place, Place, int, int)(
        lambda t2, t3, value1, value2: (
        Requires(
            token(t1, 2) and
            read_int_twice_io(t1, value1, value2, t2) and
            write_int_twice_io(t2, value1, value2, t3)
        ),
        Ensures(
            token(t3) and
            t3 == Result()
        ),
        )
    )

    Open(read_int_twice_io(t1))

    t2, number1 = read_int(t1)
    t3, number2 = read_int(t2)

    Open(write_int_twice_io(t3, number1, number2))

    t4 = write_int(t3, number1)
    t5 = write_int(t4, number2)

    return t5
Beispiel #3
0
def read_int2(t1: Place) -> Tuple[int, int, Place]:
    IOExists4(Place, Place, int, int)(lambda t3, t2, value1, value2: (
        Requires(
            token(t1, 2) and read_int_io(t1, value1, t2) and read_int_io(
                t2, value2, t3)),
        Ensures(
            token(t3) and t3 == Result()[2] and value1 == Result()[0] and
            value2 == Result()[1]),
    ))

    t2, number1 = read_int(t1)
    t3, number2 = read_int(t2)

    return number1, number2, t3
Beispiel #4
0
def read_write_int2(t1: Place) -> Place:
    IOExists6(Place, Place, Place, Place, int,
              int)(lambda t2, t3, t4, t5, value1, value2: (
                  Requires(
                      token(t1, 2) and read_int_io(t1, value1, t2) and
                      read_int_io(t2, value2, t3) and write_int_io(
                          t3, value1, t4) and write_int_io(t4, value2, t5)),
                  Ensures(token(t5) and t5 == Result()),
              ))

    t2, number1 = read_int(t1)
    t3, number2 = read_int(t2)
    t4 = write_int(t3, number1)
    t5 = write_int(t4, number2)

    return t5
Beispiel #5
0
def read_int3(t1: Place) -> Tuple[int, int, Place]:
    IOExists4(Place, Place, int, int)(
        lambda t3, t2, value1, value2: (
            Requires(
                token(t1, 2) and read_int_io(t1, value1, t2) and read_int_io(
                    t2, value2, t3)),
            Ensures(
                #:: ExpectedOutput(postcondition.violated:assertion.false)
                token(t3) and t3 == Result()[2] and value1 == Result()[0] and
                value2 == Result()[1]),
        ))

    t2, number1 = read_int(t1)
    t3, number2 = read_int(t2)

    return number2, number1, t3
Beispiel #6
0
def read_int1(t1: Place) -> Tuple[int, Place]:
    IOExists2(Place, int)(lambda t2, value: (
        Requires(token(t1, 2) and read_int_io(t1, value, t2)),
        Ensures(token(t2) and t2 == Result()[1] and value == Result()[0]),
    ))

    t2, number = read_int(t1)

    return number, t2
    def read_int(self, t1: Place) -> Tuple[int, Place]:
        IOExists2(Place, int)(lambda t2_new, value_new: (
            Requires(token(t1, 2) and read_int_io(t1, value_new, t2_new)),
            Ensures(
                token(t2_new) and t2_new == Result()[1] and value_new ==
                Result()[0]),
        ))

        t2_new, number_new = read_int(t1)

        return number_new, t2_new
Beispiel #8
0
def read_write_int1(t1: Place) -> Place:
    IOExists3(Place, Place, int)(lambda t2, t3, value: (
        Requires(
            token(t1, 2) and read_int_io(t1, value, t2) and write_int_io(
                t2, value, t3)),
        Ensures(token(t3) and t3 == Result()),
    ))

    t2, number = read_int(t1)
    t3 = write_int(t2, number)

    return t3
Beispiel #9
0
def read_int_twice1(t1: Place) -> Tuple[Place, int, int]:
    IOExists3(Place, int, int)(
        lambda t2, value1, value2: (
        Requires(
            token(t1, 2) and
            read_int_twice_io(t1, value1, value2, t2)
        ),
        Ensures(
            token(t2) and
            t2 == Result()[0] and
            value1 == Result()[1] and
            value2 == Result()[2]
        ),
        )
    )

    Open(read_int_twice_io(t1))

    t2, number1 = read_int(t1)
    t3, number2 = read_int(t2)

    return t3, number1, number2
Beispiel #10
0
def read_int_twice2(t1: Place) -> Tuple[Place, int, int]:
    IOExists3(Place, int, int)(
        lambda t2, value1, value2: (
        Requires(
            token(t1, 2) and
            read_int_twice_io(t1, value1, value2, t2)
        ),
        Ensures(
            #:: ExpectedOutput(postcondition.violated:assertion.false)
            token(t2) and
            t2 == Result()[0] and
            value1 == Result()[1] and
            value2 == Result()[2]
        ),
        )
    )

    Open(read_int_twice_io(t1))

    t2, number1 = read_int(t1)
    t3, number2 = read_int(t2)

    return t3, number2, number1
Beispiel #11
0
def write_only_positive(t1: Place) -> Place:
    IOExists3(Place, Place, int)(lambda t2, t3, value: (
        Requires(
            token(t1, 2) and read_int_io(t1, value, t2) and write_int_io(
                t2, value, t3)),
        Ensures((token(t3) and t3 == Result()) if value > 0 else (token(
            t2) and write_int_io(t2, value, t3) and t2 == Result())),
    ))

    t2, number = read_int(t1)

    if number > 0:
        t3 = write_int(t2, number)
    else:
        t3 = t2

    return t3
Beispiel #12
0
def write_non_negative(t1: Place) -> Place:
    IOExists3(Place, Place, int)(lambda t2, t3, value: (
        Requires(
            token(t1, 2) and read_int_io(t1, value, t2) and
            (write_int_io(t2, value, t3)
             if value >= 0 else write_int_io(t2, -value, t3))),
        Ensures(token(t3) and t3 == Result()),
    ))

    t2, number = read_int(t1)

    if number >= 0:
        t3 = write_int(t2, number)
    else:
        t3 = write_int(t2, -number)

    return t3