mod impl_turing_engine;
#[allow(deprecated)]
mod impl_deprecated;
use crate::tmh::TMH;
use alloc::vec::Vec;
use rstm_programs::Program;
use rstm_state::{RawState, State};
pub struct TuringEngine<'a, Q, A>
where
Q: RawState,
{
pub(crate) driver: &'a mut TMH<Q, A>,
pub(crate) program: Option<Program<Q, A>>,
pub(crate) cycles: usize,
pub(crate) _inputs: Vec<A>,
}
impl<'a, Q, A> TuringEngine<'a, Q, A>
where
Q: RawState,
{
pub const fn new(driver: &'a mut TMH<Q, A>) -> Self {
Self {
driver,
_inputs: Vec::new(),
program: None,
cycles: 0,
}
}
pub fn load_with(self, program: Program<Q, A>) -> Self {
TuringEngine {
program: Some(program),
..self
}
}
pub const fn driver(&self) -> &TMH<Q, A> {
self.driver
}
pub const fn driver_mut(&mut self) -> &mut TMH<Q, A> {
self.driver
}
#[doc(hidden)]
pub const fn inputs(&self) -> &Vec<A> {
&self._inputs
}
pub fn program(&self) -> crate::Result<&Program<Q, A>> {
self.program.as_ref().ok_or(crate::Error::NoProgram)
}
pub fn program_mut(&mut self) -> crate::Result<&mut Program<Q, A>> {
self.program.as_mut().ok_or(crate::Error::NoProgram)
}
pub const fn cycles(&self) -> usize {
self.cycles
}
pub const fn current_state(&self) -> &State<Q> {
self.driver().state()
}
pub const fn has_program(&self) -> bool {
self.program.is_some()
}
}