Skip to content

Commit 109feaa

Browse files
author
梶塚太智
committed
メモリ表示の可読性を向上
1 parent e8b28a9 commit 109feaa

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/main.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,12 @@ impl Executor {
180180

181181
/// メモリの変数を表示
182182
fn show_variables(&mut self) {
183-
self.log_print(format!(
184-
"メモリ内部の変数 {{ {} }}\n",
185-
self.memory
186-
.clone()
187-
.iter()
188-
.map(|(name, value)| { format!("'{name}': {}", value.display()) })
189-
.collect::<Vec<String>>()
190-
.join(", ")
191-
));
183+
self.log_print("メモリ内部の変数 {\n".to_string());
184+
let max = self.memory.keys().map(|s| s.len()).max().unwrap_or(0);
185+
for (name, value) in self.memory.clone() {
186+
self.log_print(format!(" {:>width$}: {}\n", name, value.display(), width=max))
187+
}
188+
self.log_print("}\n".to_string())
192189
}
193190

194191
// スタック内部を表示
@@ -212,7 +209,7 @@ impl Executor {
212209
let mut buffer = String::new(); //トークンの仮保存
213210
let mut in_brackets = 0; // 文字列のネスト構造
214211
let mut in_parentheses = 0; // リストのネスト構造
215-
let mut in_hash = false; // コメントか否か
212+
let mut in_hash = false; // コメントか否か
216213

217214
for c in code.chars() {
218215
match c {

0 commit comments

Comments
 (0)