From 40bace03f3252a4d47ab13b8d5c251f6492ee395 Mon Sep 17 00:00:00 2001 From: Jeff Date: Mon, 2 Dec 2024 01:20:05 -0500 Subject: [PATCH] Display source with chunk disassembly --- dust-cli/src/main.rs | 6 +++++- dust-lang/src/disassembler.rs | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/dust-cli/src/main.rs b/dust-cli/src/main.rs index e3f9154..872084b 100644 --- a/dust-cli/src/main.rs +++ b/dust-cli/src/main.rs @@ -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); diff --git a/dust-lang/src/disassembler.rs b/dust-lang/src/disassembler.rs index aa4afd4..a4651e4 100644 --- a/dust-lang/src/disassembler.rs +++ b/dust-lang/src/disassembler.rs @@ -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