use std::sync::Arc;
use serde::{Deserialize, Serialize};
use crate::{model::Graph, runtime::{instruction::{Instruction, Instructions}, instructions::Base, proc::ProcEnv, Error}};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EmptyIns {
pub ins: Arc<dyn Instruction>,
}
#[typetag::serde(name = "EmptyIns")]
impl Instruction for EmptyIns {
fn exec(&self, env: &mut ProcEnv, _graph: &mut Graph) -> Result<Option<Instructions>, Error> {
let mut instructions = Instructions::default();
let size = env.stack.len();
instructions.push(self.ins.clone());
instructions.push(Arc::new(Base::PopUntilStackCount(size)));
Ok(Some(instructions))
}
}
#[cfg(test)]
mod tests {
use std::sync::Arc;
use arcstr::literal;
use crate::{model::Graph, runtime::{instructions::{block::Block, empty::EmptyIns, Base}, Runtime, Val}};
#[test]
fn empty() {
let mut empty = Block::default();
empty.ins.push_back(Arc::new(Base::Literal(Val::Bool(true))));
empty.ins.push_back(Arc::new(Base::Literal(Val::Str(literal!("yo, dude")))));
let mut graph = Graph::default();
let res = Runtime::eval(&mut graph, Arc::new(EmptyIns { ins: Arc::new(empty) })).expect("expected pass");
assert_eq!(res, Val::Void);
}
}