27 lines
621 B
Rust
27 lines
621 B
Rust
use crate::constants_table::ConstantsTable;
|
|
use dvm_lib::instruction::Instruction;
|
|
|
|
pub trait Assemble {
|
|
fn assemble(&self, builder: &mut InstructionsBuilder, constants_table: &mut ConstantsTable);
|
|
}
|
|
|
|
pub struct InstructionsBuilder {
|
|
instructions: Vec<Instruction>,
|
|
}
|
|
|
|
impl InstructionsBuilder {
|
|
pub fn new() -> Self {
|
|
Self {
|
|
instructions: vec![],
|
|
}
|
|
}
|
|
|
|
pub fn push(&mut self, instruction: Instruction) {
|
|
self.instructions.push(instruction);
|
|
}
|
|
|
|
pub fn take_instructions(&mut self) -> Vec<Instruction> {
|
|
std::mem::take(&mut self.instructions)
|
|
}
|
|
}
|