/* * Copyright 2025 Casper Dalgaard Nielsen * Adam Yasser Tallouzi * * Use of this source code is governed by the Apache 2.0 license * that can be found in the LICENSE.md file. *//// Type of simple mutable counters, and its functions.pubmod Fixpoint3.Counter {////// `Counter` is a wrapper around `Ref` for a simple counter.////// Its primary use is for generating identifiers.////// Not thread-safe.///pubstructCounter[r: Region] {mut state: Int32 }////// Returns a fresh `Counter` initialized to `0`.///pubdeffresh(rc: Region[r]): Counter[r] \ r = new Counter @ rc {state = 0}////// Returns the state of `counter` and increments it.///pubdefgetAndIncrement(counter: Counter[r]): Int32 \ r =letnewId = counter->state;counter->state = newId+1;newId////// Increments the state of `counter`.///pubdefincrement(counter: Counter[r]): Unit \ r =discardgetAndIncrement(counter)////// Returns the state of `counter`.///pubdefget(counter: Counter[r]): Int32 \ r =counter->state////// Sets the state of `counter` to `i`.///pubdefset(i: Int32, counter: Counter[r]): Unit \ r =counter->state = i}