clean up most warnings

This commit is contained in:
Scott Richmond 2024-11-21 17:10:50 -05:00
parent ad076622aa
commit 0cd170bd83
5 changed files with 31 additions and 35 deletions

View File

@ -1,8 +1,8 @@
// Solution to the #[derive(Clone)] problem: https://stackoverflow.com/questions/27883509/can-you-clone-a-closure
use crate::value::*;
use crate::vm::*;
use imbl::*;
use std::fmt;
// use imbl::*;
// use std::fmt;
type LResult<'src> = Result<Value<'src>, LudusError>;
@ -10,21 +10,21 @@ type LResult<'src> = Result<Value<'src>, LudusError>;
pub enum Base<'src> {
Unary(&'src str, fn(&Value<'src>) -> LResult<'src>),
Binary(&'src str, fn(&Value<'src>, &Value<'src>) -> LResult<'src>),
Ternary(
&'src str,
fn(&Value<'src>, &Value<'src>, &Value<'src>) -> LResult<'src>,
),
// Ternary(
// &'src str,
// fn(&Value<'src>, &Value<'src>, &Value<'src>) -> LResult<'src>,
// ),
}
impl<'src> Base<'src> {
pub fn name(&self) -> &'src str {
match self {
Base::Unary(name, _) => name,
Base::Binary(name, _) => name,
Base::Ternary(name, _) => name,
}
}
}
// impl<'src> Base<'src> {
// pub fn name(&self) -> &'src str {
// match self {
// Base::Unary(name, _) => name,
// Base::Binary(name, _) => name,
// Base::Ternary(name, _) => name,
// }
// }
// }
pub fn eq<'src>(x: &Value<'src>, y: &Value<'src>) -> LResult<'src> {
Ok(Value::Boolean(x == y))

View File

@ -36,7 +36,7 @@
// * [ ] perf testing
use chumsky::{input::Stream, prelude::*};
use std::rc::Rc;
// use std::rc::Rc;
mod spans;
@ -44,7 +44,7 @@ mod lexer;
use crate::lexer::*;
mod value;
use crate::value::*;
// use crate::value::*;
mod parser;
use crate::parser::*;

View File

@ -674,7 +674,7 @@ where
.collect()
.delimited_by(just(Token::Punctuation("{")), just(Token::Punctuation("}")));
let fn_single_clause = fn_clause.clone().map_with(|c, e| vec![c]);
let fn_single_clause = fn_clause.clone().map_with(|c, _| vec![c]);
let r#loop = just(Token::Reserved("loop"))
.ignore_then(tuple.clone())

View File

@ -110,7 +110,7 @@ impl<'src> fmt::Display for Value<'src> {
let name = match base {
Base::Unary(name, _) => name,
Base::Binary(name, _) => name,
Base::Ternary(name, _) => name,
// Base::Ternary(name, _) => name,
};
write!(f, "base fn {}", name)
}

View File

@ -275,16 +275,15 @@ pub fn apply<'src, 'a>(
} else {
r#fn(&args[0], &args[1])
}
}
Base::Ternary(_name, f) => {
if args.len() != 3 {
Err(LudusError {
msg: "wrong arity: expected 3 arguments".to_string(),
})
} else {
f(&args[0], &args[1], &args[2])
}
}
} // Base::Ternary(_name, f) => {
// if args.len() != 3 {
// Err(LudusError {
// msg: "wrong arity: expected 3 arguments".to_string(),
// })
// } else {
// f(&args[0], &args[1], &args[2])
// }
// }
},
_ => unreachable!(),
}
@ -454,17 +453,14 @@ pub fn eval<'src, 'a>(
})
}
Ast::Repeat(times, body) => {
let mut times_num = 0;
match eval(&times.0, ctx) {
Ok(Value::Number(n)) => {
times_num = n as usize;
}
let times_num = match eval(&times.0, ctx) {
Ok(Value::Number(n)) => n as usize,
_ => {
return Err(LudusError {
msg: "repeat may only take numbers".to_string(),
})
}
}
};
for _ in 0..times_num {
eval(&body.0, ctx)?;
}