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
def write_two_ints_io( t_pre: Place, t_post: Place = Result(), ) -> bool: Terminates(False) return IOForall(int, lambda value: IOExists(Place)( lambda t2: ( write_int_io(t_pre, value, t2) and write_int_io(t2, value * 2, t_post) ) ))
def write_int_twice_io( t_pre: Place, number1: int, number2: int, t_post: Place = Result(), ) -> bool: Terminates(True) TerminationMeasure(2) return IOExists1(Place)( lambda t2: ( write_int_io(t_pre, number1, t2) and write_int_io(t2, number2, t_post) ) )
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
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
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_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
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
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
def client1(t1: Place, value: int) -> Place: IOExists1(Place)(lambda t2: ( Requires(token(t1, 3) and write_int_io(t1, value, t2)), Ensures(token(t2) and t2 == Result()), )) writer = WriterSuper(value) t2 = writer.write_int(False, t1) return t2
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
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, 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