use smol_str::SmolStr;
#[derive(Debug, Clone, PartialEq)]
pub enum Ir {
SetVar { name: SmolStr, value: SmolStr },
PushArg { value: SmolStr },
CallBuiltin { name: SmolStr },
CallUtility { name: SmolStr },
Return { status: i32 },
Nop,
}
#[derive(Debug, Clone, PartialEq)]
pub struct IrProgram {
pub instructions: Vec<Ir>,
}
impl IrProgram {
#[must_use]
pub fn new(instructions: Vec<Ir>) -> Self {
Self { instructions }
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn ir_program_construction() {
let prog = IrProgram::new(vec![
Ir::PushArg {
value: "echo".into(),
},
Ir::PushArg {
value: "hello".into(),
},
Ir::CallBuiltin {
name: "echo".into(),
},
Ir::Return { status: 0 },
]);
assert_eq!(prog.instructions.len(), 4);
}
}