feat(tazjin/rlox): Print compiled bytecode with disassemble feature
Change-Id: I42293b334248b5228dd90f13b9a400ccdca20a84 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2562 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
This commit is contained in:
parent
56f6a6e9f2
commit
758730d25d
2 changed files with 11 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -219,6 +219,10 @@ impl<T: Iterator<Item = Token>> Compiler<T> {
|
|||
|
||||
fn end_compiler(&mut self) -> LoxResult<()> {
|
||||
self.emit_op(OpCode::OpReturn);
|
||||
|
||||
#[cfg(feature = "disassemble")]
|
||||
chunk::disassemble_chunk(&self.chunk);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue