diff --git a/andy-cpp-macros/src/function.rs b/andy-cpp-macros/src/function.rs index 2194539..f0a8490 100644 --- a/andy-cpp-macros/src/function.rs +++ b/andy-cpp-macros/src/function.rs @@ -98,7 +98,7 @@ pub fn wrap_function(function: syn::ItemFn) -> WrappedFunction { #inner // Initialize the arguments and map them from the Andy C types to the rust types - let [#(#arguments, )*] = values else { panic!("unable to unpack arguments") }; + let [#(#arguments, )*] = values else { panic!("actual argument count did not match expected argument count when calling native method, this should be prevented by the runtime") }; #(#argument_init_code_blocks; )* // Call the inner function with the unpacked arguments @@ -202,7 +202,7 @@ fn create_temp_variable( let crate::interpreter::value::Value::Function(#temp_var) = #argument_var_name else { panic!("Value #position needed to be a Sequence::Map but wasn't"); }; - let #argument_var_name = Callable { + let #argument_var_name = &Callable { function: Rc::clone(#temp_var), environment: environment }; diff --git a/src/ast/expression.rs b/src/ast/expression.rs index fba0ac8..83bdaff 100644 --- a/src/ast/expression.rs +++ b/src/ast/expression.rs @@ -186,7 +186,7 @@ impl ExpressionLocation { values: tuple_values, } => tuple_values .iter() - .map(|it| it.try_into_identifier().map(|ident| ident.to_string())) + .map(|it| it.try_into_identifier().map(std::string::ToString::to_string)) .collect::, EvaluationError>>(), _ => Err(EvaluationError::syntax_error( "expected a parameter list".to_string(), diff --git a/src/interpreter/evaluate.rs b/src/interpreter/evaluate.rs index 7c71cab..93ab46b 100644 --- a/src/interpreter/evaluate.rs +++ b/src/interpreter/evaluate.rs @@ -361,7 +361,7 @@ pub(crate) fn evaluate_expression( if let Some(name) = name { environment .borrow_mut() - .declare_function(&name, user_function); + .declare_function(name, user_function); Value::Unit } else { @@ -627,7 +627,7 @@ fn declare_or_assign_variable( environment.borrow_mut().declare(identifier, value.clone()); } else { if !environment.borrow().contains(identifier) { - return Err(EvaluationError::undefined_variable(identifier, span))?; + Err(EvaluationError::undefined_variable(identifier, span))?; } environment.borrow_mut().assign(identifier, value.clone()); diff --git a/src/interpreter/function.rs b/src/interpreter/function.rs index 17a88e5..05fb714 100644 --- a/src/interpreter/function.rs +++ b/src/interpreter/function.rs @@ -13,7 +13,7 @@ use crate::interpreter::sequence::Sequence; use crate::interpreter::value::{Value, ValueType}; use crate::lexer::Span; -/// Callable is a wrapper aroudn a OverloadedFunction pointer and the environment to make it +/// Callable is a wrapper aroudn a `OverloadedFunction` pointer and the environment to make it /// easy to have an executable fucntion as a method signature in the standard library pub struct Callable<'a> { pub function: Rc>, diff --git a/src/stdlib/hash_map.rs b/src/stdlib/hash_map.rs index 60407f7..7866b7f 100644 --- a/src/stdlib/hash_map.rs +++ b/src/stdlib/hash_map.rs @@ -75,7 +75,7 @@ mod inner { Sequence::Iterator(rc) => { let mut iter = rc.borrow_mut(); let mut out = HashMap::new(); - while let Some(item) = iter.next() { + for item in iter.by_ref() { out.insert(item, Value::Unit); } out diff --git a/src/stdlib/sequence.rs b/src/stdlib/sequence.rs index d97c870..1df2ab9 100644 --- a/src/stdlib/sequence.rs +++ b/src/stdlib/sequence.rs @@ -167,11 +167,11 @@ mod inner { } } - pub fn fold(seq: &mut Sequence, initial: Value, function: Callable) -> EvaluationResult { + pub fn fold(seq: &mut Sequence, initial: Value, function: &Callable) -> EvaluationResult { fold_iterator(mut_seq_into_iterator(seq), initial, function) } - pub fn reduce(seq: &mut Sequence, function: Callable) -> EvaluationResult { + pub fn reduce(seq: &mut Sequence, function: &Callable) -> EvaluationResult { let mut iterator = mut_seq_into_iterator(seq); let fst = iterator .next() @@ -180,7 +180,7 @@ mod inner { fold_iterator(iterator, fst, function) } - pub fn filter(seq: &mut Sequence, predicate: Callable) -> EvaluationResult { + pub fn filter(seq: &mut Sequence, predicate: &Callable) -> EvaluationResult { let iterator = mut_seq_into_iterator(seq); let mut out = Vec::new(); for element in iterator { @@ -199,7 +199,7 @@ mod inner { Ok(out.into()) } - pub fn none(seq: &mut Sequence, function: Callable) -> EvaluationResult { + pub fn none(seq: &mut Sequence, function: &Callable) -> EvaluationResult { for item in mut_seq_into_iterator(seq) { match function.call(&mut [item?])? { Value::Bool(true) => return Ok(Value::Bool(false)), @@ -216,7 +216,7 @@ mod inner { Ok(Value::Bool(true)) } - pub fn all(seq: &mut Sequence, function: Callable) -> EvaluationResult { + pub fn all(seq: &mut Sequence, function: &Callable) -> EvaluationResult { for item in mut_seq_into_iterator(seq) { match function.call(&mut [item?])? { Value::Bool(true) => {} @@ -234,7 +234,7 @@ mod inner { Ok(Value::Bool(true)) } - pub fn any(seq: &mut Sequence, function: Callable) -> EvaluationResult { + pub fn any(seq: &mut Sequence, function: &Callable) -> EvaluationResult { for item in mut_seq_into_iterator(seq) { match function.call(&mut [item?])? { Value::Bool(true) => return Ok(Value::Bool(true)), @@ -252,11 +252,11 @@ mod inner { Ok(Value::Bool(false)) } - pub fn map(seq: &mut Sequence, function: Callable) -> EvaluationResult { - let mut iterator = mut_seq_into_iterator(seq); + pub fn map(seq: &mut Sequence, function: &Callable) -> EvaluationResult { + let iterator = mut_seq_into_iterator(seq); let mut out = Vec::new(); - while let Some(item) = iterator.next() { + for item in iterator { let item = item?; out.push(function.call(&mut [item])?); } @@ -273,7 +273,7 @@ mod inner { }) } - pub fn first_or_else(seq: &mut Sequence, default: Callable) -> EvaluationResult { + pub fn first_or_else(seq: &mut Sequence, default: &Callable) -> EvaluationResult { let mut iterator = mut_seq_into_iterator(seq); Ok(if let Some(item) = iterator.next() { item? @@ -284,12 +284,12 @@ mod inner { } fn fold_iterator( - mut iterator: MutableValueIntoIterator, + iterator: MutableValueIntoIterator, initial: Value, - function: Callable, + function: &Callable, ) -> EvaluationResult { let mut acc = initial; - while let Some(item) = iterator.next() { + for item in iterator { acc = function.call(&mut [acc, item?])?; }