better logs
This commit is contained in:
parent
03ded1fb74
commit
52cbb88a6d
2 changed files with 23 additions and 20 deletions
|
@ -10,7 +10,7 @@ use cfg_if::cfg_if;
|
||||||
use derive_new::new;
|
use derive_new::new;
|
||||||
use derive_wrapper::{AsRef, From};
|
use derive_wrapper::{AsRef, From};
|
||||||
use fasteval::{Compiler as _, EvalNamespace, Evaler, Instruction, Slab};
|
use fasteval::{Compiler as _, EvalNamespace, Evaler, Instruction, Slab};
|
||||||
use log::trace;
|
use log::{debug, trace};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
|
@ -74,7 +74,7 @@ pub struct Silence;
|
||||||
|
|
||||||
impl Token for Silence {
|
impl Token for Silence {
|
||||||
fn apply(&self, context: Context) -> Result<Context, CompilerError> {
|
fn apply(&self, context: Context) -> Result<Context, CompilerError> {
|
||||||
trace!("⚡ {}", type_name::<Self>());
|
debug!("⚡ {}", type_name::<Self>());
|
||||||
let (mut context, mut next) = context.render(None)?;
|
let (mut context, mut next) = context.render(None)?;
|
||||||
context.result.append(&mut next);
|
context.result.append(&mut next);
|
||||||
Ok(context)
|
Ok(context)
|
||||||
|
@ -87,7 +87,7 @@ pub struct Marker;
|
||||||
|
|
||||||
impl Token for Marker {
|
impl Token for Marker {
|
||||||
fn apply(&self, mut context: Context) -> Result<Context, CompilerError> {
|
fn apply(&self, mut context: Context) -> Result<Context, CompilerError> {
|
||||||
trace!("⚡ {}", type_name::<Self>());
|
debug!("⚡ {}", type_name::<Self>());
|
||||||
context.result.clear();
|
context.result.clear();
|
||||||
Ok(context)
|
Ok(context)
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ pub struct Note(pub u8);
|
||||||
|
|
||||||
impl Token for Note {
|
impl Token for Note {
|
||||||
fn apply(&self, context: Context) -> Result<Context, CompilerError> {
|
fn apply(&self, context: Context) -> Result<Context, CompilerError> {
|
||||||
trace!("⚡ {}", type_name::<Self>());
|
debug!("⚡ {}", type_name::<Self>());
|
||||||
let (mut context, mut next) = context.render(Some(self.0))?;
|
let (mut context, mut next) = context.render(Some(self.0))?;
|
||||||
context.result.append(&mut next);
|
context.result.append(&mut next);
|
||||||
Ok(context)
|
Ok(context)
|
||||||
|
@ -118,7 +118,7 @@ impl AsRef<VariableChange> for VariableChange {
|
||||||
|
|
||||||
impl Token for VariableChange {
|
impl Token for VariableChange {
|
||||||
fn apply(&self, mut context: Context) -> Result<Context, CompilerError> {
|
fn apply(&self, mut context: Context) -> Result<Context, CompilerError> {
|
||||||
trace!("⚡ {}", type_name::<Self>());
|
debug!("⚡ {}", type_name::<Self>());
|
||||||
*context.get_mut(self.0.to_string())? = context.eval(self.1.as_ref())?;
|
*context.get_mut(self.0.to_string())? = context.eval(self.1.as_ref())?;
|
||||||
Ok(context)
|
Ok(context)
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,7 @@ impl Default for LoopCount {
|
||||||
|
|
||||||
impl Token for Loop {
|
impl Token for Loop {
|
||||||
fn apply(&self, mut context: Context) -> Result<Context, CompilerError> {
|
fn apply(&self, mut context: Context) -> Result<Context, CompilerError> {
|
||||||
trace!("⚡ {}", type_name::<Self>());
|
debug!("⚡ {}", type_name::<Self>());
|
||||||
let mut old_result = context.result.clone();
|
let mut old_result = context.result.clone();
|
||||||
let count = match self.0 {
|
let count = match self.0 {
|
||||||
LoopCount::Litteral(n) => n,
|
LoopCount::Litteral(n) => n,
|
||||||
|
@ -169,7 +169,7 @@ pub struct Tuplet(pub TokenVec);
|
||||||
|
|
||||||
impl Token for Tuplet {
|
impl Token for Tuplet {
|
||||||
fn apply(&self, mut context: Context) -> Result<Context, CompilerError> {
|
fn apply(&self, mut context: Context) -> Result<Context, CompilerError> {
|
||||||
trace!("⚡ {}", type_name::<Self>());
|
debug!("⚡ {}", type_name::<Self>());
|
||||||
let mut old_result = context.result.clone();
|
let mut old_result = context.result.clone();
|
||||||
context.result.clear();
|
context.result.clear();
|
||||||
let mut new_context = self
|
let mut new_context = self
|
||||||
|
@ -207,7 +207,7 @@ pub struct Slope(pub VariableChange, pub TokenVec);
|
||||||
|
|
||||||
impl Token for Slope {
|
impl Token for Slope {
|
||||||
fn apply(&self, mut context: Context) -> Result<Context, CompilerError> {
|
fn apply(&self, mut context: Context) -> Result<Context, CompilerError> {
|
||||||
trace!("⚡ {}", type_name::<Self>());
|
debug!("⚡ {}", type_name::<Self>());
|
||||||
context.slopes.push((
|
context.slopes.push((
|
||||||
self.0.as_ref().0.to_string(),
|
self.0.as_ref().0.to_string(),
|
||||||
self.0.as_ref().1.as_ref().clone(),
|
self.0.as_ref().1.as_ref().clone(),
|
||||||
|
@ -402,13 +402,16 @@ impl Context {
|
||||||
|
|
||||||
pub fn eval_with(
|
pub fn eval_with(
|
||||||
Expression {
|
Expression {
|
||||||
from: _,
|
from,
|
||||||
instruction,
|
instruction,
|
||||||
slab,
|
slab,
|
||||||
}: &Expression,
|
}: &Expression,
|
||||||
ns: &mut impl EvalNamespace,
|
ns: &mut impl EvalNamespace,
|
||||||
) -> Result<f64, fasteval::Error> {
|
) -> Result<f64, fasteval::Error> {
|
||||||
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<u8>) -> Result<(Self, Vec<f64>), CompilerError> {
|
pub fn render(mut self, n: Option<u8>) -> Result<(Self, Vec<f64>), CompilerError> {
|
||||||
|
|
|
@ -74,7 +74,7 @@ where
|
||||||
SV: Borrow<VariableChange>,
|
SV: Borrow<VariableChange>,
|
||||||
V: AsRef<[char]>,
|
V: AsRef<[char]>,
|
||||||
{
|
{
|
||||||
debug!("making the TOKEN parser");
|
trace!("making the TOKEN parser");
|
||||||
let space_or_comment = || {
|
let space_or_comment = || {
|
||||||
value(
|
value(
|
||||||
(),
|
(),
|
||||||
|
@ -107,7 +107,7 @@ impl Silence {
|
||||||
I: Input,
|
I: Input,
|
||||||
<I as Input>::Item: AsChar,
|
<I as Input>::Item: AsChar,
|
||||||
{
|
{
|
||||||
debug!("making the {} parser", type_name::<Self>());
|
trace!("making the {} parser", type_name::<Self>());
|
||||||
value(Self, char('.'))
|
value(Self, char('.'))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,7 @@ impl Marker {
|
||||||
I: Input,
|
I: Input,
|
||||||
<I as Input>::Item: AsChar,
|
<I as Input>::Item: AsChar,
|
||||||
{
|
{
|
||||||
debug!("making the {} parser", type_name::<Self>());
|
trace!("making the {} parser", type_name::<Self>());
|
||||||
value(Marker, char('%'))
|
value(Marker, char('%'))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ impl Note {
|
||||||
NS: AsRef<str>,
|
NS: AsRef<str>,
|
||||||
I: Input + for<'z> Compare<&'z str>,
|
I: Input + for<'z> Compare<&'z str>,
|
||||||
{
|
{
|
||||||
debug!("making the {} parser", type_name::<Self>());
|
trace!("making the {} parser", type_name::<Self>());
|
||||||
let notes = {
|
let notes = {
|
||||||
let mut sorted = notes
|
let mut sorted = notes
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -167,7 +167,7 @@ impl VariableChange {
|
||||||
<I as Input>::Item: AsChar,
|
<I as Input>::Item: AsChar,
|
||||||
V: AsRef<[char]>,
|
V: AsRef<[char]>,
|
||||||
{
|
{
|
||||||
debug!("making the {} parser", type_name::<Self>());
|
trace!("making the {} parser", type_name::<Self>());
|
||||||
move |i: I| {
|
move |i: I| {
|
||||||
preceded(
|
preceded(
|
||||||
char('$'),
|
char('$'),
|
||||||
|
@ -195,7 +195,7 @@ impl Loop {
|
||||||
SV: Borrow<VariableChange>,
|
SV: Borrow<VariableChange>,
|
||||||
V: AsRef<[char]>,
|
V: AsRef<[char]>,
|
||||||
{
|
{
|
||||||
debug!("making the {} parser", type_name::<Self>());
|
trace!("making the {} parser", type_name::<Self>());
|
||||||
move |input| {
|
move |input| {
|
||||||
delimited(
|
delimited(
|
||||||
char('('),
|
char('('),
|
||||||
|
@ -235,7 +235,7 @@ impl Tuplet {
|
||||||
SV: Borrow<VariableChange>,
|
SV: Borrow<VariableChange>,
|
||||||
V: AsRef<[char]>,
|
V: AsRef<[char]>,
|
||||||
{
|
{
|
||||||
debug!("making the {} parser", type_name::<Self>());
|
trace!("making the {} parser", type_name::<Self>());
|
||||||
|input| {
|
|input| {
|
||||||
delimited(char('['), token_parser(parser), char(']'))
|
delimited(char('['), token_parser(parser), char(']'))
|
||||||
.map(Self)
|
.map(Self)
|
||||||
|
@ -259,7 +259,7 @@ impl Slope {
|
||||||
SV: Borrow<VariableChange>,
|
SV: Borrow<VariableChange>,
|
||||||
V: AsRef<[char]>,
|
V: AsRef<[char]>,
|
||||||
{
|
{
|
||||||
debug!("making the {} parser", type_name::<Self>());
|
trace!("making the {} parser", type_name::<Self>());
|
||||||
move |input| {
|
move |input| {
|
||||||
let slopes = {
|
let slopes = {
|
||||||
let mut vec = parser
|
let mut vec = parser
|
||||||
|
@ -300,7 +300,7 @@ where
|
||||||
V: IntoIterator<Item = C>,
|
V: IntoIterator<Item = C>,
|
||||||
C: Borrow<char>,
|
C: Borrow<char>,
|
||||||
{
|
{
|
||||||
debug!("making the Expression parser");
|
trace!("making the Expression parser");
|
||||||
let variables: Vec<(String, f64)> = variables
|
let variables: Vec<(String, f64)> = variables
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|v| (v.borrow().to_string(), 0.0))
|
.map(|v| (v.borrow().to_string(), 0.0))
|
||||||
|
@ -347,7 +347,7 @@ where
|
||||||
I: Input + Copy,
|
I: Input + Copy,
|
||||||
F: Fn(I) -> Option<O>,
|
F: Fn(I) -> Option<O>,
|
||||||
{
|
{
|
||||||
debug!("making take_while_map parser");
|
trace!("making take_while_map parser");
|
||||||
move |input: I| {
|
move |input: I| {
|
||||||
let mut len = input.input_len();
|
let mut len = input.input_len();
|
||||||
debug!(
|
debug!(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue