Skip to content

Commit ed0f451

Browse files
committed
add pretty Debug implementation for CodeObject
1 parent 36bef81 commit ed0f451

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

vm/src/bytecode.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ let call_function = 0x64;
1111
* Primitive instruction type, which can be encoded and decoded.
1212
*/
1313
use std::collections::HashMap;
14+
use std::fmt;
1415

15-
#[derive(Debug, Clone)]
16+
#[derive(Clone)]
1617
pub struct CodeObject {
1718
pub instructions: Vec<Instruction>,
1819
pub label_map: HashMap<Label, usize>,
@@ -117,3 +118,15 @@ pub enum BlockType {
117118
Except,
118119
}
119120
*/
121+
122+
impl fmt::Debug for CodeObject {
123+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
124+
let inst_str = self.instructions.iter()
125+
.enumerate()
126+
.map(|(i, inst)| format!("Inst {}: {:?}", i, inst))
127+
.collect::<Vec<_>>()
128+
.join("\n");
129+
let labelmap_str = format!("label_map: {:?}", self.label_map);
130+
write!(f, "Code Object {{ \n{}\n{} }}", inst_str, labelmap_str)
131+
}
132+
}

0 commit comments

Comments
 (0)