Skip to main content

vyre_self_substrate/
persistent_fixpoint_program.rs

1//! Persistent-fixpoint Program builder for runtime and driver scheduling loops.
2
3use vyre_foundation::ir::{Node, Program};
4
5/// Build a persistent-fixpoint Program around a caller-supplied transfer body.
6///
7/// The generated program runs `transfer_body`, ping-pongs `current` and `next`,
8/// and stops when `changed[0] == 0` or `max_iterations` is reached. Runtime and
9/// driver crates call this self-substrate wrapper instead of depending on the
10/// primitive catalog directly.
11#[must_use]
12pub fn persistent_fixpoint_program(
13    transfer_body: Vec<Node>,
14    current: &str,
15    next: &str,
16    changed: &str,
17    words: u32,
18    max_iterations: u32,
19) -> Program {
20    vyre_primitives::fixpoint::persistent_fixpoint::persistent_fixpoint(
21        transfer_body,
22        current,
23        next,
24        changed,
25        words,
26        max_iterations,
27    )
28}
29
30#[cfg(test)]
31mod tests {
32    use super::persistent_fixpoint_program;
33
34    #[test]
35    fn builds_program_with_caller_buffers() {
36        let program = persistent_fixpoint_program(Vec::new(), "current", "next", "changed", 4, 8);
37        let names = program
38            .buffers()
39            .iter()
40            .map(|buffer| buffer.name())
41            .collect::<Vec<_>>();
42
43        assert!(names.contains(&"current"));
44        assert!(names.contains(&"next"));
45        assert!(names.contains(&"changed"));
46    }
47}