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

View File

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

View File

@ -674,7 +674,7 @@ where
.collect() .collect()
.delimited_by(just(Token::Punctuation("{")), just(Token::Punctuation("}"))); .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")) let r#loop = just(Token::Reserved("loop"))
.ignore_then(tuple.clone()) .ignore_then(tuple.clone())

View File

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

View File

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