use crate::bytecode::{Instruction, Opcode, Program};
use crate::error::Result;
#[derive(Debug, Default, Clone)]
pub struct ProgramBuilder {
instructions: Vec<Instruction>,
}
impl ProgramBuilder {
pub fn new() -> Self {
Self::default()
}
pub fn push(mut self, opcode: Opcode, operand: u32) -> Self {
self.instructions.push(Instruction::new(opcode, operand));
self
}
pub fn build(self) -> Result<Program> {
let program = Program {
instructions: self.instructions,
};
program.validate()?;
Ok(program)
}
}