rstm_actors/engine/
turing_engine.rs1mod impl_turing_engine;
7
8#[allow(deprecated)]
9mod impl_deprecated;
10
11use crate::tmh::TMH;
12use alloc::vec::Vec;
13use rstm_programs::Program;
14use rstm_state::{RawState, State};
15
16pub struct TuringEngine<'a, Q, A>
18where
19 Q: RawState,
20{
21 pub(crate) driver: &'a mut TMH<Q, A>,
23 pub(crate) program: Option<Program<Q, A>>,
25 pub(crate) cycles: usize,
27 pub(crate) _inputs: Vec<A>,
28}
29
30impl<'a, Q, A> TuringEngine<'a, Q, A>
31where
32 Q: RawState,
33{
34 pub const fn new(driver: &'a mut TMH<Q, A>) -> Self {
35 Self {
36 driver,
37 _inputs: Vec::new(),
38 program: None,
39 cycles: 0,
40 }
41 }
42 pub fn load_with(self, program: Program<Q, A>) -> Self {
44 TuringEngine {
45 program: Some(program),
46 ..self
47 }
48 }
49 pub const fn driver(&self) -> &TMH<Q, A> {
51 self.driver
52 }
53 pub const fn driver_mut(&mut self) -> &mut TMH<Q, A> {
55 self.driver
56 }
57 #[doc(hidden)]
58 pub const fn inputs(&self) -> &Vec<A> {
60 &self._inputs
61 }
62 pub fn program(&self) -> crate::Result<&Program<Q, A>> {
64 self.program.as_ref().ok_or(crate::Error::NoProgram)
65 }
66 pub fn program_mut(&mut self) -> crate::Result<&mut Program<Q, A>> {
68 self.program.as_mut().ok_or(crate::Error::NoProgram)
69 }
70 pub const fn cycles(&self) -> usize {
72 self.cycles
73 }
74 pub const fn current_state(&self) -> &State<Q> {
76 self.driver().state()
77 }
78 pub const fn has_program(&self) -> bool {
80 self.program.is_some()
81 }
82}