/* * Copyright 2023 Jakob Schneider Villumsen * * Use of this source code is governed by the Apache 2.0 license * that can be found in the LICENSE.md file. *//// Represents a mutable reference to a value of type `a` in region `r`.structRef[a, r] {mut v: a}////// Type of mutable references, and its functions.///pubmod Ref {////// Returns a new reference to `x` in the region `rc`.///pubdeffresh(rc: Region[r], x: a): Ref[a, r] \ r =new Ref @ rc {v = x}////// Returns the element referenced by `rf`.///pubdefget(rf: Ref[a, r]): a \ r =rf->v////// Updates `rf` to reference `x`.///pubdefput(x: a, rf: Ref[a, r]): Unit \ r =rf->v = x////// Updates `rf` to reference `f` applied to the value referenced by `rf`.////// I.e. if `rf` references `x` then `rf` is updated to reference `f(x)`.///pubdeftransform(f: a -> a \ ef, rf: Ref[a, r]): Unit \ { r, ef } =put(f(rf->v), rf)}