1
0

Display source with chunk disassembly

This commit is contained in:
Jeff 2024-12-02 01:20:05 -05:00
parent 215601707b
commit 40bace03f3
2 changed files with 10 additions and 3 deletions

View File

@ -158,7 +158,11 @@ fn main() {
return;
}
};
let disassembly = chunk.disassembler().style(style).disassemble();
let disassembly = chunk
.disassembler()
.style(style)
.source(&source)
.disassemble();
println!("{}", disassembly);

View File

@ -16,6 +16,9 @@
//! ```text
//! ┌──────────────────────────────────────────────────────────────────────────────┐
//! │ dust │
//! │ │
//! │ write_line("hello_world") │
//! │ │
//! │ 3 instructions, 1 constants, 0 locals, returns none │
//! │ │
//! │ Instructions │
@ -30,7 +33,7 @@
//! │ --------- │
//! │ i TYPE VALUE │
//! │ --- ---------------- ----------------- │
//! │ 0 str Hello, world!
//! │ 0 str hello_world
//! └──────────────────────────────────────────────────────────────────────────────┘
//! ```
use std::env::current_exe;
@ -91,7 +94,7 @@ impl<'a> Disassembler<'a> {
(longest_line.chars().count() + 2).max(80)
}
pub fn set_source(&mut self, source: &'a str) -> &mut Self {
pub fn source(mut self, source: &'a str) -> Self {
self.source = Some(source);
self