main
Alpha Chen 2 years ago
parent 3138932c13
commit da8c978c11
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -34,14 +34,18 @@ impl VM {
pub fn interpret(&mut self) -> Result<()> { pub fn interpret(&mut self) -> Result<()> {
loop { loop {
let op_code = &self.chunk.code[self.ip]; debug!("{:?}", &self.stack[0..self.stack_top]);
debug!("{}", DisassembledInstruction::new(self.ip, &self.chunk,)); debug!("{}", DisassembledInstruction::new(self.ip, &self.chunk,));
match op_code {
match &self.chunk.code[self.ip] {
OpCode::Constant(constant) => { OpCode::Constant(constant) => {
let value = self.chunk.constants[*constant]; let value = self.chunk.constants[*constant];
println!("{}", value); self.push(value);
}
OpCode::Return => {
println!("{}", self.pop());
return Ok(());
} }
OpCode::Return => return Ok(()),
} }
self.ip += 1; self.ip += 1;

Loading…
Cancel
Save