コード例 #1
0
def read_int_twice_io(
        t_pre: Place,
        number1: int = Result(),
        number2: int = Result(),
        t_post: Place = Result(),
        ) -> bool:
    Terminates(False)
    return IOExists1(Place)(
        lambda t2: (
        read_int_io(t_pre, number1, t2) and
        read_int_io(t2, number2, t_post)
        )
    )
コード例 #2
0
ファイル: test_read_int.py プロジェクト: zeta1999/nagini
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
コード例 #3
0
ファイル: test_read_int.py プロジェクト: zeta1999/nagini
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
コード例 #4
0
ファイル: test_read_int.py プロジェクト: zeta1999/nagini
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
コード例 #5
0
ファイル: test_read_int.py プロジェクト: zeta1999/nagini
def read_write_int3(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)
    #:: ExpectedOutput(call.precondition:insufficient.permission)
    t4 = write_int(t3, number2)
    #:: ExpectedOutput(carbon)(call.precondition:insufficient.permission)
    t5 = write_int(t4, number1)

    return t5
コード例 #6
0
ファイル: test_read_int.py プロジェクト: zeta1999/nagini
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
コード例 #7
0
    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
コード例 #8
0
ファイル: test_read_int.py プロジェクト: zeta1999/nagini
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_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
コード例 #10
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