From da8c978c11153630eec933f09c39cc34e4ec7c7b Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Sun, 16 Oct 2022 20:58:25 -0700 Subject: [PATCH] 15.2.2 --- rust/src/vm.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/rust/src/vm.rs b/rust/src/vm.rs index db7c172..e26bb5f 100644 --- a/rust/src/vm.rs +++ b/rust/src/vm.rs @@ -34,14 +34,18 @@ impl VM { pub fn interpret(&mut self) -> Result<()> { loop { - let op_code = &self.chunk.code[self.ip]; + debug!("{:?}", &self.stack[0..self.stack_top]); debug!("{}", DisassembledInstruction::new(self.ip, &self.chunk,)); - match op_code { + + match &self.chunk.code[self.ip] { OpCode::Constant(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;