Skip to main content

ironwork_exec/
unit.rs

1//! The interpreter's run unit: `rt::unit`'s, holding each loaded program as its `Compiled` and
2//! calling through the [`Library`].
3
4pub use crate::loader::{AddProgram, Library};
5pub use rt::unit::{ADDRESS_BASE, Clock, Event, LoadError, LoadedProgram, Loader, MAX_DEPTH, OS_COMMAND_ROUTINES, Observer, RETURN_CODE, StatementFilter};
6
7use crate::Compiled;
8use std::rc::Rc;
9
10pub type RunUnit<'w> = rt::unit::RunUnit<'w, Rc<Compiled>, Library>;
11pub type Loaded = rt::unit::Loaded<Rc<Compiled>>;
12
13/// What a run leaves in its run unit: memory, every byte, and each program's name and where its
14/// storage starts, which the differential test compares between the interpreter and the VM.
15#[derive(Clone, Debug, Default, PartialEq, Eq)]
16pub struct Remains {
17    pub mem: Vec<u8>,
18    pub programs: Vec<(String, usize)>,
19}
20
21impl Remains {
22    pub fn of<H: Clone, L: Loader<H>>(unit: &rt::unit::RunUnit<'_, H, L>) -> Self {
23        Self { mem: unit.mem.clone(), programs: unit.programs.iter().map(|p| (p.name.clone(), p.base)).collect() }
24    }
25}