|
|
|
@ -5,6 +5,7 @@ use crate::value::Value;
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub enum OpCode {
|
|
|
|
|
Constant(usize),
|
|
|
|
|
Negate,
|
|
|
|
|
Return,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -62,13 +63,13 @@ impl fmt::Display for DisassembledInstruction<'_> {
|
|
|
|
|
write!(f, "{:>4} ", line)?;
|
|
|
|
|
}
|
|
|
|
|
match self.chunk.code[self.i] {
|
|
|
|
|
OpCode::Constant(constant) => {
|
|
|
|
|
let value = self.chunk.constants[constant];
|
|
|
|
|
write!(f, "{:<16} {:4} '{}'", "OP_CONSTANT", constant, value)?;
|
|
|
|
|
}
|
|
|
|
|
OpCode::Return => {
|
|
|
|
|
write!(f, "OP_RETURN")?;
|
|
|
|
|
}
|
|
|
|
|
OpCode::Constant(constant) => write!(
|
|
|
|
|
f,
|
|
|
|
|
"{:<16} {:4} '{}'",
|
|
|
|
|
"OP_CONSTANT", constant, self.chunk.constants[constant]
|
|
|
|
|
)?,
|
|
|
|
|
OpCode::Negate => write!(f, "OP_NEGATE")?,
|
|
|
|
|
OpCode::Return => write!(f, "OP_RETURN")?,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|