diff --git a/core/Cargo.toml b/core/Cargo.toml index 6cd542c..edeeb49 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -4,10 +4,6 @@ version = "0.4.0" authors = ["Ava "] edition = "2021" -[dependencies] -# cant have math without libc I guess... -libm = "0.2.8" - [lib] name = "flesh" diff --git a/core/src/stl/math.rs b/core/src/stl/math.rs index 3d0d481..c0626f2 100644 --- a/core/src/stl/math.rs +++ b/core/src/stl/math.rs @@ -19,16 +19,16 @@ use crate::segment::{Ctr, Seg}; use crate::sym::{SymTable, ValueType, Symbol, Args}; use crate::error::{Traceback, start_trace}; -use libm::pow; - use alloc::rc::Rc; use alloc::boxed::Box; use alloc::string::{String, ToString}; +#[inline] fn isnumeric(arg: &Ctr) -> bool { matches!(arg, Ctr::Integer(_) | Ctr::Float(_)) } + const ADD_DOCSTRING: &str = "traverses over N args, which must all evaluate to an Integer or Float. Adds each arg up to a final result. WARNING: does not acocunt for under/overflows. @@ -192,52 +192,6 @@ fn floatcast_callback(ast: &Seg, _: &mut SymTable) -> Result { } } -const EXP_DOCSTRING: &str = "Takes two args, both expected to be numeric. -Returns the first arg to the power of the second arg. -Does not handle overflow or underflow."; -fn exp_callback(ast: &Seg, _: &mut SymTable) -> Result { - let first = *ast.car.clone(); - if !isnumeric(&first) { - return Err(start_trace( - ("exp", format!("{} is not a number!", first)) - .into())) - } - let second: Ctr; - if let Ctr::Seg(ref s) = *ast.cdr { - second = *s.car.clone(); - } else { - return Err(start_trace( - ("exp", "expected at least two inputs") - .into())) - } - if !isnumeric(&second) { - return Err(start_trace( - ("exp", format!("{} is not a number!", second)) - .into())) - } - - match first { - Ctr::Float(lf) => match second { - Ctr::Float(rf) => Ok(Ctr::Float(pow(lf, rf))), - Ctr::Integer(ri) => Ok(Ctr::Float(pow(lf as f64, ri as f64))), - _ => Err(start_trace( - ("exp", "not implemented for these input types") - .into())), - }, - Ctr::Integer(li) => match second { - Ctr::Float(rf) => Ok(Ctr::Float(pow(li as f64, rf))), - Ctr::Integer(ri) => Ok(Ctr::Float(pow(li as f64, ri as f64))), - _ => Err(start_trace( - ("exp", "not implemented for these input types") - .into())), - }, - - _ => Err(start_trace( - ("exp", "not implemented for these input types") - .into())), - } -} - const MOD_DOCSTRING: &str = "Takes two args, both expected to be numeric. Returns a list of two values: the modulus and the remainder. Example: (mod 5 3) -> (1 2) @@ -602,19 +556,6 @@ pub fn add_math_lib(syms: &mut SymTable) { }, ); - syms.insert( - "exp".to_string(), - Symbol { - name: String::from("exp"), - args: Args::Lazy(2), - conditional_branches: false, - docs: EXP_DOCSTRING.to_string(), - optimizable: true, - value: ValueType::Internal(Rc::new(exp_callback)), - ..Default::default() - }, - ); - syms.insert( "mod".to_string(), Symbol { diff --git a/core/tests/test_lib_math.rs b/core/tests/test_lib_math.rs index 54dbeff..71f06aa 100644 --- a/core/tests/test_lib_math.rs +++ b/core/tests/test_lib_math.rs @@ -1,7 +1,6 @@ mod math_lib_tests { use flesh::ast::{eval, lex, Ctr, SymTable}; use flesh::stdlib::static_stdlib; - use libm::pow; #[test] fn test_add_chain() { @@ -138,66 +137,6 @@ mod math_lib_tests { ); } - #[test] - fn test_ii_exp() { - let document = "(exp 7 20)"; - let result = pow(7 as f64, 20 as f64); - - let mut syms = SymTable::new(); - static_stdlib(&mut syms, |_: &String| (), || String::new()); - assert_eq!( - *eval(&lex(&document.to_string()).unwrap(), &mut syms) - .unwrap() - .to_string(), - result.to_string(), - ); - } - - #[test] - fn test_if_exp() { - let document = "(exp 1 10.2)"; - let result = f64::powf(1f64, 10.2); - - let mut syms = SymTable::new(); - static_stdlib(&mut syms, |_: &String| (), || String::new()); - assert_eq!( - *eval(&lex(&document.to_string()).unwrap(), &mut syms) - .unwrap() - .to_string(), - result.to_string(), - ); - } - - #[test] - fn test_fi_exp() { - let document = "(exp 10.2 1)"; - let result = pow(10.2 as f64, 1 as f64); - - let mut syms = SymTable::new(); - static_stdlib(&mut syms, |_: &String| (), || String::new()); - assert_eq!( - *eval(&lex(&document.to_string()).unwrap(), &mut syms) - .unwrap() - .to_string(), - result.to_string(), - ); - } - - #[test] - fn test_ff_exp() { - let document = "(exp 1.4 1.5)"; - let result = pow(1.4, 1.5); - - let mut syms = SymTable::new(); - static_stdlib(&mut syms, |_: &String| (), || String::new()); - assert_eq!( - *eval(&lex(&document.to_string()).unwrap(), &mut syms) - .unwrap() - .to_string(), - result.to_string(), - ); - } - #[test] fn test_ii_mod() { let document = "(def test \"\" (mod 7 3))";