Remove useless function call "name" argument

This commit is contained in:
Jeff 2024-01-17 15:12:37 -05:00
parent f04adfc661
commit 7642b23553
5 changed files with 12 additions and 31 deletions

View File

@ -88,13 +88,13 @@ impl AbstractTree for FunctionCall {
}
fn run(&self, source: &str, context: &Map) -> Result<Value> {
let (name, value) = match &self.function_expression {
let value = match &self.function_expression {
FunctionExpression::Identifier(identifier) => {
let key = identifier.inner();
let variables = context.variables()?;
if let Some((value, _)) = variables.get(key) {
(Some(key.clone()), value.clone())
value.clone()
} else {
return Err(Error::FunctionIdentifierNotFound(
identifier.inner().clone(),
@ -102,11 +102,11 @@ impl AbstractTree for FunctionCall {
}
}
FunctionExpression::FunctionCall(function_call) => {
(None, function_call.run(source, context)?)
function_call.run(source, context)?
}
FunctionExpression::Value(value_node) => (None, value_node.run(source, context)?),
FunctionExpression::Index(index) => (None, index.run(source, context)?),
FunctionExpression::Yield(r#yield) => (None, r#yield.run(source, context)?),
FunctionExpression::Value(value_node) => value_node.run(source, context)?,
FunctionExpression::Index(index) => index.run(source, context)?,
FunctionExpression::Yield(r#yield) => r#yield.run(source, context)?,
};
let mut arguments = Vec::with_capacity(self.arguments.len());
@ -117,7 +117,7 @@ impl AbstractTree for FunctionCall {
arguments.push(value);
}
value.as_function()?.call(name, &arguments, source, context)
value.as_function()?.call(&arguments, source, context)
}
fn expected_type(&self, context: &Map) -> Result<Type> {

View File

@ -54,13 +54,7 @@ impl FunctionNode {
}
}
pub fn call(
&self,
name: Option<String>,
arguments: &[Value],
source: &str,
outer_context: &Map,
) -> Result<Value> {
pub fn call(&self, arguments: &[Value], source: &str, outer_context: &Map) -> Result<Value> {
self.context.clone_complex_values_from(outer_context)?;
let parameter_argument_pairs = self.parameters.iter().zip(arguments.iter());
@ -71,13 +65,6 @@ impl FunctionNode {
self.context.set(key, value.clone())?;
}
if let Some(name) = name {
self.context.set(
name,
Value::Function(Function::ContextDefined(self.clone())),
)?;
}
let return_value = self.body.run(source, &self.context)?;
Ok(return_value)

View File

@ -298,7 +298,7 @@ impl StringFunction {
string.retain(|char| {
predicate
.call(None, &[Value::string(char)], _source, _outer_context)
.call(&[Value::string(char)], _source, _outer_context)
.unwrap()
.as_boolean()
.unwrap()

View File

@ -11,19 +11,13 @@ pub enum Function {
}
impl Function {
pub fn call(
&self,
name: Option<String>,
arguments: &[Value],
source: &str,
outer_context: &Map,
) -> Result<Value> {
pub fn call(&self, arguments: &[Value], source: &str, outer_context: &Map) -> Result<Value> {
match self {
Function::BuiltIn(built_in_function) => {
built_in_function.call(arguments, source, outer_context)
}
Function::ContextDefined(context_defined_function) => {
context_defined_function.call(name, arguments, source, outer_context)
context_defined_function.call(arguments, source, outer_context)
}
}
}

View File

@ -154,7 +154,7 @@ impl Value {
}
pub fn is_function(&self) -> bool {
matches!(self, Value::Map(_))
matches!(self, Value::Function(_))
}
/// Borrows the value stored in `self` as `&String`, or returns `Err` if `self` is not a `Value::String`.