use super::instruction::Instruction;
use super::value::Value;
pub const MAGIC: [u8; 4] = *b"BFV0";
pub const ABI_VERSION: u32 = 4;
#[derive(Clone, Debug, PartialEq)]
pub struct FunctionDef {
pub name: String,
pub entry: u32,
pub arity: u8,
pub num_registers: u8,
}
#[derive(Clone, Debug, Default)]
pub struct Chunk {
pub name: String,
pub constants: Vec<Value>,
pub code: Vec<Instruction>,
pub functions: Vec<FunctionDef>,
}
impl Chunk {
pub fn function(&self, index: u32) -> Option<&FunctionDef> {
self.functions.get(index as usize)
}
pub fn constant(&self, index: u32) -> Option<&Value> {
self.constants.get(index as usize)
}
pub fn len(&self) -> usize {
self.code.len()
}
pub fn is_empty(&self) -> bool {
self.code.is_empty()
}
}