use crate::*;
pub struct Bytecode {
pub words: Vec<Word>,
pub errors: Vec<BytecodeError>,
}
#[derive(Clone, Copy)]
pub struct Word {
pub bits: usize,
pub value: usize,
}
impl std::fmt::Display for Word {
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
for i in (0..self.bits).rev() {
let is_first_bit = i+1 == self.bits;
if !is_first_bit && (i+1) % 4 == 0 {
write!(f, "_")?;
}
match (self.value >> i) & 1 {
0 => write!(f, "0")?,
_ => write!(f, "1")?,
}
}
if self.bits == 0 {
write!(f, "0")?;
}
return Ok(());
}
}
pub struct BytecodeError {
pub source: SourceSpan,
pub variant: BytecodeErrorVariant,
}
pub enum BytecodeErrorVariant {
DefinitionNotFound(String),
DuplicateLabelDefinition(String),
/// pin, real
PinnedAddressBacktrack(usize, usize),
/// expected, received
ValueTooLarge(usize, usize),
StackUnderflow,
MultipleReturnValues,
NoReturnValue,
}