From dee09d3583062aaaa175ed996cf2be62d6ef4844 Mon Sep 17 00:00:00 2001 From: Jeff Date: Thu, 19 Sep 2024 11:53:41 -0400 Subject: [PATCH] Add bytcode to dissassembly --- dust-lang/src/chunk.rs | 12 ++++++++---- dust-lang/src/instruction.rs | 6 ++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/dust-lang/src/chunk.rs b/dust-lang/src/chunk.rs index a87cbb2..470b6df 100644 --- a/dust-lang/src/chunk.rs +++ b/dust-lang/src/chunk.rs @@ -288,8 +288,8 @@ impl<'a> ChunkDisassembler<'a> { "", "Instructions", "------------", - "INDEX OPERATION INFO POSITION", - "----- --------------- ------------------------------ --------", + "INDEX BYTECODE OPERATION INFO POSITION", + "----- -------- --------------- ------------------------------ --------", ]; const CONSTANT_HEADER: [&'static str; 5] = [ @@ -377,11 +377,15 @@ impl<'a> ChunkDisassembler<'a> { let position = position.to_string(); let operation = instruction.operation().to_string(); let info_option = instruction.disassembly_info(Some(self.chunk)); + let bytecode = u32::from(instruction); 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 { - format!("{index:<5} {operation:15} {:30} {position:8}", " ") + format!( + "{index:<5} {bytecode:<8X} {operation:15} {:30} {position:8}", + " " + ) }; disassembly.push_str(¢er(&instruction_display)); diff --git a/dust-lang/src/instruction.rs b/dust-lang/src/instruction.rs index 4694f83..6178f54 100644 --- a/dust-lang/src/instruction.rs +++ b/dust-lang/src/instruction.rs @@ -528,6 +528,12 @@ impl Display for Instruction { } } +impl From<&Instruction> for u32 { + fn from(instruction: &Instruction) -> Self { + instruction.0 + } +} + #[cfg(test)] mod tests { use super::*;