1
0

Add bytcode to dissassembly

This commit is contained in:
Jeff 2024-09-19 11:53:41 -04:00
parent be77d64c39
commit dee09d3583
2 changed files with 14 additions and 4 deletions

View File

@ -288,8 +288,8 @@ impl<'a> ChunkDisassembler<'a> {
"", "",
"Instructions", "Instructions",
"------------", "------------",
"INDEX OPERATION INFO POSITION", "INDEX BYTECODE OPERATION INFO POSITION",
"----- --------------- ------------------------------ --------", "----- -------- --------------- ------------------------------ --------",
]; ];
const CONSTANT_HEADER: [&'static str; 5] = [ const CONSTANT_HEADER: [&'static str; 5] = [
@ -377,11 +377,15 @@ impl<'a> ChunkDisassembler<'a> {
let position = position.to_string(); let position = position.to_string();
let operation = instruction.operation().to_string(); let operation = instruction.operation().to_string();
let info_option = instruction.disassembly_info(Some(self.chunk)); let info_option = instruction.disassembly_info(Some(self.chunk));
let bytecode = u32::from(instruction);
let instruction_display = if let Some(info) = info_option { let instruction_display = if let Some(info) = info_option {
format!("{index:<5} {operation:15} {info:30} {position:8}") format!("{index:<5} {bytecode:<8X} {operation:15} {info:30} {position:8}")
} else { } else {
format!("{index:<5} {operation:15} {:30} {position:8}", " ") format!(
"{index:<5} {bytecode:<8X} {operation:15} {:30} {position:8}",
" "
)
}; };
disassembly.push_str(&center(&instruction_display)); disassembly.push_str(&center(&instruction_display));

View File

@ -528,6 +528,12 @@ impl Display for Instruction {
} }
} }
impl From<&Instruction> for u32 {
fn from(instruction: &Instruction) -> Self {
instruction.0
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;