1use core::{cell::Ref, fmt::Display};
2
3use alloc::string::ToString;
4use alloc::vec::Vec;
5
6use crate::{GlobalState, GlobalStateInner};
7
8use super::Instruction;
9
10pub trait Processor: core::fmt::Debug {
11 fn transform(&self, processing: ScopeProcessing) -> ScopeProcessing;
12}
13
14pub struct ScopeProcessing {
16 pub instructions: Vec<Instruction>,
18 pub global_state: GlobalState,
20}
21
22impl ScopeProcessing {
23 pub fn state(&self) -> Ref<'_, GlobalStateInner> {
24 self.global_state.borrow()
25 }
26}
27
28impl Display for ScopeProcessing {
29 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
30 writeln!(f, "{{")?;
31 for instruction in self.instructions.iter() {
32 let instruction_str = instruction.to_string();
33 if !instruction_str.is_empty() {
34 writeln!(f, " {instruction_str}")?;
35 }
36 }
37 write!(f, "}}")?;
38 Ok(())
39 }
40}