Пример #1
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
Пример #2
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
Пример #3
0
def write_four_ints_2(t1: Place) -> Place:
    IOExists2(Place, Place)(
        lambda t2, t3: (
        Requires(
            token(t1, 2) and
            write_two_ints_io(t1, t2) and
            write_two_ints_io(t2, t3)
        ),
        Ensures(
            token(t3) and
            t3 == Result()
        ),
        )
    )

    Open(write_two_ints_io(t1))

    t2 = write_int(t1, 4)
    #:: ExpectedOutput(call.precondition:insufficient.permission)
    t3 = write_int(t2, 9)

    #:: ExpectedOutput(carbon)(exhale.failed:insufficient.permission)
    Open(write_two_ints_io(t3))

    t4 = write_int(t3, 3)
    t5 = write_int(t4, 6)

    return t5
Пример #4
0
def write_four_ints_1(t1: Place) -> Place:
    IOExists2(Place, Place)(
        lambda t2, t3: (
        Requires(
            token(t1, 2) and
            write_two_ints_io(t1, t2) and
            write_two_ints_io(t2, t3)
        ),
        Ensures(
            token(t3) and
            t3 == Result()
        ),
        )
    )

    Open(write_two_ints_io(t1))

    t2 = write_int(t1, 4)
    t3 = write_int(t2, 8)

    Open(write_two_ints_io(t3))

    t4 = write_int(t3, 3)
    t5 = write_int(t4, 6)

    return t5
Пример #5
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
Пример #6
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
Пример #7
0
    def write_int2(self, t1: Place, value: int) -> Place:
        IOExists1(Place)(lambda t2: (
            Requires(token(t1, 2) and write_int_io(t1, value, t2)),
            Ensures(token(t2) and t2 == Result()),
        ))

        t2 = write_int(t1, value)

        return t2
Пример #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
Пример #9
0
    def write_int1(self, t1: Place, value: int) -> Place:
        """Defining getter is not heap dependent."""
        IOExists1(Place)(lambda t2: (
            Requires(
                token(t1, 2) and Acc(self.int_field, 1 / 2) and write_int_io(
                    t1, value, t2) and write_int_io(t1, self.int_field, t2)),
            Ensures(token(t2) and t2 == Result()),
        ))

        t2 = write_int(t1, value)

        return t2
Пример #10
0
def write_four_ints_3(t1: Place) -> Place:
    IOExists2(Place, Place)(
        lambda t2, t3: (
        Requires(
            token(t1, 2) and
            write_two_ints_io(t1, t2) and
            write_two_ints_io(t2, t3)
        ),
        Ensures(
            #:: ExpectedOutput(postcondition.violated:insufficient.permission)
            token(t3) and
            t3 == Result()
        ),
        )
    )

    Open(write_two_ints_io(t1))

    t2 = write_int(t1, 4)
    t3 = write_int(t2, 8)

    return t3
Пример #11
0
    def write_int1(self, t1: Place, value: int) -> Place:
        IOExists1(Place)(
            lambda t2: (
                Requires(
                    token(t1, 2) and Acc(self.int_field, 1 / 2) and
                    write_int_io(t1, self.int_field, t2)),
                Ensures(
                    # Getter is heap dependent, therefore need access to
                    # self.int_field.
                    Acc(self.int_field, 1 / 2) and token(t2) and t2 == Result(
                    )),
            ))

        t2 = write_int(t1, self.int_field)

        return t2
    def write_int(self, b: bool, t1: Place) -> Place:
        IOExists1(Place)(
            lambda t2: (
                Requires(
                    #:: ExpectedOutput(not.wellformed:insufficient.permission)|ExpectedOutput(carbon)(not.wellformed:insufficient.permission)
                    token(t1, 2) and
                    ((Acc(self.int_field1, 1 / 2) and write_int_io(
                        t1, self.int_field1, t2))
                     if b else (Acc(self.int_field2, 1 / 2) and write_int_io(
                         t1, self.int_field2, t2)))),
                Ensures((Acc(self.int_field1, 1 / 2) if b else Acc(
                    self.int_field2, 1 / 2)) and token(t2) and t2 == Result()),
            ))

        t2 = write_int(t1, self.int_field1)

        return t2
Пример #13
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
    def write_int(self, t1: Place) -> Place:
        IOExists1(Place)(
            lambda t2: (
            Requires(
                token(t1, 2) and
                Acc(self.int_field, 1/2) and
                write_int_io(t1, self.int_field, t2)
            ),
            Ensures(
                Acc(self.int_field, 1/2) and
                token(t2) and
                t2 == Result()
            ),
            )
        )

        t2 = write_int(t1, self.int_field)

        return t2