use core::{cell::Ref, fmt::Display};
use alloc::string::ToString;
use alloc::vec::Vec;
use crate::{GlobalState, GlobalStateInner};
use super::Instruction;
pub trait Processor: core::fmt::Debug {
fn transform(&self, processing: ScopeProcessing) -> ScopeProcessing;
}
pub struct ScopeProcessing {
pub instructions: Vec<Instruction>,
pub global_state: GlobalState,
}
impl ScopeProcessing {
pub fn state(&self) -> Ref<'_, GlobalStateInner> {
self.global_state.borrow()
}
}
impl Display for ScopeProcessing {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
writeln!(f, "{{")?;
for instruction in self.instructions.iter() {
let instruction_str = instruction.to_string();
if !instruction_str.is_empty() {
writeln!(f, " {instruction_str}")?;
}
}
write!(f, "}}")?;
Ok(())
}
}