use crate::{Effect, Value};
#[derive(Debug, Default)]
pub struct OperandStack {
pub values: Vec<Value>,
}
impl OperandStack {
pub fn push(&mut self, value: impl Into<Value>) {
self.values.push(value.into());
}
pub fn pop(&mut self) -> Result<Value, OperandStackUnderflow> {
self.values.pop().ok_or(OperandStackUnderflow)
}
pub fn to_i32_slice(&self) -> &[i32] {
bytemuck::cast_slice(&self.values)
}
pub fn to_u32_slice(&self) -> &[u32] {
bytemuck::cast_slice(&self.values)
}
}
#[derive(Debug)]
pub struct OperandStackUnderflow;
impl From<OperandStackUnderflow> for Effect {
fn from(OperandStackUnderflow: OperandStackUnderflow) -> Self {
Effect::OperandStackUnderflow
}
}