diff --git a/users/tazjin/rlox/src/bytecode/chunk.rs b/users/tazjin/rlox/src/bytecode/chunk.rs index 649aafcfd..b2a7c7b6a 100644 --- a/users/tazjin/rlox/src/bytecode/chunk.rs +++ b/users/tazjin/rlox/src/bytecode/chunk.rs @@ -84,3 +84,10 @@ pub fn disassemble_instruction(chunk: &Chunk, offset: usize) { op => println!("{:?}", op), } } + +#[cfg(feature = "disassemble")] +pub fn disassemble_chunk(chunk: &Chunk) { + for (idx, _) in chunk.code.iter().enumerate() { + disassemble_instruction(chunk, idx); + } +} diff --git a/users/tazjin/rlox/src/bytecode/compiler/mod.rs b/users/tazjin/rlox/src/bytecode/compiler/mod.rs index 58a5c1b98..547c1ab18 100644 --- a/users/tazjin/rlox/src/bytecode/compiler/mod.rs +++ b/users/tazjin/rlox/src/bytecode/compiler/mod.rs @@ -219,6 +219,10 @@ impl> Compiler { fn end_compiler(&mut self) -> LoxResult<()> { self.emit_op(OpCode::OpReturn); + + #[cfg(feature = "disassemble")] + chunk::disassemble_chunk(&self.chunk); + Ok(()) }