|
|
@ -5,6 +5,10 @@ use crate::value::Value;
|
|
|
|
#[derive(Debug)]
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum OpCode {
|
|
|
|
pub enum OpCode {
|
|
|
|
Constant(usize),
|
|
|
|
Constant(usize),
|
|
|
|
|
|
|
|
Add,
|
|
|
|
|
|
|
|
Subtract,
|
|
|
|
|
|
|
|
Multiply,
|
|
|
|
|
|
|
|
Divide,
|
|
|
|
Negate,
|
|
|
|
Negate,
|
|
|
|
Return,
|
|
|
|
Return,
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -68,6 +72,10 @@ impl fmt::Display for DisassembledInstruction<'_> {
|
|
|
|
"{:<16} {:4} '{}'",
|
|
|
|
"{:<16} {:4} '{}'",
|
|
|
|
"OP_CONSTANT", constant, self.chunk.constants[constant]
|
|
|
|
"OP_CONSTANT", constant, self.chunk.constants[constant]
|
|
|
|
)?,
|
|
|
|
)?,
|
|
|
|
|
|
|
|
OpCode::Add => write!(f, "OP_ADD")?,
|
|
|
|
|
|
|
|
OpCode::Subtract => write!(f, "OP_SUBTRACT")?,
|
|
|
|
|
|
|
|
OpCode::Multiply => write!(f, "OP_MULTIPLY")?,
|
|
|
|
|
|
|
|
OpCode::Divide => write!(f, "OP_DIVIDE")?,
|
|
|
|
OpCode::Negate => write!(f, "OP_NEGATE")?,
|
|
|
|
OpCode::Negate => write!(f, "OP_NEGATE")?,
|
|
|
|
OpCode::Return => write!(f, "OP_RETURN")?,
|
|
|
|
OpCode::Return => write!(f, "OP_RETURN")?,
|
|
|
|
}
|
|
|
|
}
|
|
|
|