diff --git a/src/compiler.rs b/src/compiler.rs index b0b8a57..31a25df 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -10,7 +10,7 @@ use cfg_if::cfg_if; use derive_new::new; use derive_wrapper::{AsRef, From}; use fasteval::{Compiler as _, EvalNamespace, Evaler, Instruction, Slab}; -use log::trace; +use log::{debug, trace}; use thiserror::Error; cfg_if! { @@ -74,7 +74,7 @@ pub struct Silence; impl Token for Silence { fn apply(&self, context: Context) -> Result { - trace!("⚡ {}", type_name::()); + debug!("⚡ {}", type_name::()); let (mut context, mut next) = context.render(None)?; context.result.append(&mut next); Ok(context) @@ -87,7 +87,7 @@ pub struct Marker; impl Token for Marker { fn apply(&self, mut context: Context) -> Result { - trace!("⚡ {}", type_name::()); + debug!("⚡ {}", type_name::()); context.result.clear(); Ok(context) } @@ -99,7 +99,7 @@ pub struct Note(pub u8); impl Token for Note { fn apply(&self, context: Context) -> Result { - trace!("⚡ {}", type_name::()); + debug!("⚡ {}", type_name::()); let (mut context, mut next) = context.render(Some(self.0))?; context.result.append(&mut next); Ok(context) @@ -118,7 +118,7 @@ impl AsRef for VariableChange { impl Token for VariableChange { fn apply(&self, mut context: Context) -> Result { - trace!("⚡ {}", type_name::()); + debug!("⚡ {}", type_name::()); *context.get_mut(self.0.to_string())? = context.eval(self.1.as_ref())?; Ok(context) } @@ -143,7 +143,7 @@ impl Default for LoopCount { impl Token for Loop { fn apply(&self, mut context: Context) -> Result { - trace!("⚡ {}", type_name::()); + debug!("⚡ {}", type_name::()); let mut old_result = context.result.clone(); let count = match self.0 { LoopCount::Litteral(n) => n, @@ -169,7 +169,7 @@ pub struct Tuplet(pub TokenVec); impl Token for Tuplet { fn apply(&self, mut context: Context) -> Result { - trace!("⚡ {}", type_name::()); + debug!("⚡ {}", type_name::()); let mut old_result = context.result.clone(); context.result.clear(); let mut new_context = self @@ -207,7 +207,7 @@ pub struct Slope(pub VariableChange, pub TokenVec); impl Token for Slope { fn apply(&self, mut context: Context) -> Result { - trace!("⚡ {}", type_name::()); + debug!("⚡ {}", type_name::()); context.slopes.push(( self.0.as_ref().0.to_string(), self.0.as_ref().1.as_ref().clone(), @@ -402,13 +402,16 @@ impl Context { pub fn eval_with( Expression { - from: _, + from, instruction, slab, }: &Expression, ns: &mut impl EvalNamespace, ) -> Result { - instruction.eval(slab, ns) + instruction + .eval(slab, ns) + .inspect(|ok| trace!("{from} = {ok}")) + .inspect_err(|e| trace!("{from} = {e}")) } pub fn render(mut self, n: Option) -> Result<(Self, Vec), CompilerError> { diff --git a/src/parser.rs b/src/parser.rs index 2aef237..b7ef122 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -74,7 +74,7 @@ where SV: Borrow, V: AsRef<[char]>, { - debug!("making the TOKEN parser"); + trace!("making the TOKEN parser"); let space_or_comment = || { value( (), @@ -107,7 +107,7 @@ impl Silence { I: Input, ::Item: AsChar, { - debug!("making the {} parser", type_name::()); + trace!("making the {} parser", type_name::()); value(Self, char('.')) } } @@ -118,7 +118,7 @@ impl Marker { I: Input, ::Item: AsChar, { - debug!("making the {} parser", type_name::()); + trace!("making the {} parser", type_name::()); value(Marker, char('%')) } } @@ -132,7 +132,7 @@ impl Note { NS: AsRef, I: Input + for<'z> Compare<&'z str>, { - debug!("making the {} parser", type_name::()); + trace!("making the {} parser", type_name::()); let notes = { let mut sorted = notes .into_iter() @@ -167,7 +167,7 @@ impl VariableChange { ::Item: AsChar, V: AsRef<[char]>, { - debug!("making the {} parser", type_name::()); + trace!("making the {} parser", type_name::()); move |i: I| { preceded( char('$'), @@ -195,7 +195,7 @@ impl Loop { SV: Borrow, V: AsRef<[char]>, { - debug!("making the {} parser", type_name::()); + trace!("making the {} parser", type_name::()); move |input| { delimited( char('('), @@ -235,7 +235,7 @@ impl Tuplet { SV: Borrow, V: AsRef<[char]>, { - debug!("making the {} parser", type_name::()); + trace!("making the {} parser", type_name::()); |input| { delimited(char('['), token_parser(parser), char(']')) .map(Self) @@ -259,7 +259,7 @@ impl Slope { SV: Borrow, V: AsRef<[char]>, { - debug!("making the {} parser", type_name::()); + trace!("making the {} parser", type_name::()); move |input| { let slopes = { let mut vec = parser @@ -300,7 +300,7 @@ where V: IntoIterator, C: Borrow, { - debug!("making the Expression parser"); + trace!("making the Expression parser"); let variables: Vec<(String, f64)> = variables .into_iter() .map(|v| (v.borrow().to_string(), 0.0)) @@ -347,7 +347,7 @@ where I: Input + Copy, F: Fn(I) -> Option, { - debug!("making take_while_map parser"); + trace!("making take_while_map parser"); move |input: I| { let mut len = input.input_len(); debug!(