From 8879df0983737b42eee1df26004b861599dd88d6 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Mon, 25 Aug 2025 08:20:22 -0400 Subject: clippy --- src/lib.rs | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 60a406f..487a5ce 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,4 @@ use log::{Level, error, info}; -use console_log; use wasm_bindgen::prelude::*; pub mod forth; @@ -25,11 +24,11 @@ impl ExportedByteCode { fn tr_op(op: &forth::vm::OpCode) -> String { use forth::vm::OpCode::*; let s = match op { - If(t, None) => format!("If({}, none)", t), - If(t, Some(f)) => format!("If({}, {})", t, f), - TIf(t, None) => format!("TIf({}, none)", t), - TIf(t, Some(f)) => format!("TIf({}, {})", t, f), - other => format!("{:?}", other), + If(t, None) => format!("If({t}, none)"), + If(t, Some(f)) => format!("If({t}, {f})"), + TIf(t, None) => format!("TIf({t}, none)"), + TIf(t, Some(f)) => format!("TIf({t}, {f})"), + other => format!("{other:?}"), }; s.to_string() } @@ -47,6 +46,10 @@ impl ExportedByteCode { self.0.len() } + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } + pub fn at(&self, offset: usize) -> String { self.0[offset].clone() } @@ -86,6 +89,10 @@ impl ExportedWordAnnotations { self.0.len() } + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } + pub fn at(&self, offset: usize) -> ExportedAnnotation { self.0[offset].clone() } @@ -104,15 +111,15 @@ impl ExportedVM { } pub fn compile(&mut self, text: &str) -> bool { - let mut comp = forth::compiler::Compiler::new(&text); + let mut comp = forth::compiler::Compiler::new(text); if let Err(e) = comp.compile() { - error!("couldn't compile program text: {:?}", e); + error!("couldn't compile program text: {e:?}"); return false } self.annos = comp.annotations.iter() .map(|word_anno| -> ExportedWordAnnotations { - word_anno.into_iter().map(|a| a.into()).collect() + word_anno.iter().map(|a| a.into()).collect() }) .collect(); let vm = forth::vm::VM::new(comp.wordlist); @@ -124,7 +131,7 @@ impl ExportedVM { let Some(vm) = &mut self.vm else { return Err("no vm".to_string()) }; - vm.tick().or_else(|err| Err(format!("runtime error: {:?}", err))) + vm.tick().map_err(|err| format!("runtime error: {err:?}")) } pub fn run(&mut self) -> Result { @@ -134,7 +141,7 @@ impl ExportedVM { vm.ip.word = 0; vm.ip.offset = 0; - vm.run().or_else(|err| Err(format!("runtime error: {:?}", err))) + vm.run().map_err(|err| format!("runtime error: {err:?}")) } pub fn stack(&self) -> Vec { @@ -142,7 +149,7 @@ impl ExportedVM { return vec![] }; - return vm.stack.0.clone() + vm.stack.0.clone() } pub fn wordlist(&self) -> Vec { -- cgit v1.3