From 2cbeb4b5510f1407d7d91404e3056d8a6ef39da3 Mon Sep 17 00:00:00 2001 From: Jeff Date: Mon, 24 Jun 2024 11:06:12 -0400 Subject: [PATCH] Clean up --- .../src/abstract_tree/built_in_function.rs | 14 ++++++------ dust-lang/src/abstract_tree/function_call.rs | 22 +++++++------------ dust-lang/src/abstract_tree/type.rs | 2 +- dust-lang/src/identifier.rs | 8 +++---- 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/dust-lang/src/abstract_tree/built_in_function.rs b/dust-lang/src/abstract_tree/built_in_function.rs index 4616c41..7a156d6 100644 --- a/dust-lang/src/abstract_tree/built_in_function.rs +++ b/dust-lang/src/abstract_tree/built_in_function.rs @@ -71,7 +71,7 @@ impl FunctionLogic for Length { } } - fn call(context: &Context, manage_memory: bool) -> Result, RuntimeError> { + fn call(context: &Context, _: bool) -> Result, RuntimeError> { let value = if let Some(value) = context.get_value(&Identifier::new("input"))? { value } else { @@ -103,7 +103,7 @@ impl FunctionLogic for ReadFile { } } - fn call(context: &Context, manage_memory: bool) -> Result, RuntimeError> { + fn call(context: &Context, _: bool) -> Result, RuntimeError> { let value = if let Some(value) = context.get_value(&Identifier::new("path"))? { value } else { @@ -136,12 +136,12 @@ impl FunctionLogic for ReadLine { } } - fn call(context: &Context, manage_memory: bool) -> Result, RuntimeError> { + fn call(_: &Context, _: bool) -> Result, RuntimeError> { let mut user_input = String::new(); stdin().read_line(&mut user_input)?; - Ok(Some(Value::string(user_input))) + Ok(Some(Value::string(user_input.trim_end_matches('\n')))) } } @@ -157,7 +157,7 @@ impl FunctionLogic for Sleep { } } - fn call(context: &Context, manage_memory: bool) -> Result, RuntimeError> { + fn call(context: &Context, _: bool) -> Result, RuntimeError> { let value = if let Some(value) = context.get_value(&Identifier::new("milliseconds"))? { value } else { @@ -191,7 +191,7 @@ impl FunctionLogic for WriteLine { } } - fn call(context: &Context, manage_memory: bool) -> Result, RuntimeError> { + fn call(context: &Context, _: bool) -> Result, RuntimeError> { let value = if let Some(value) = context.get_value(&Identifier::new("output"))? { value } else { @@ -230,7 +230,7 @@ impl FunctionLogic for JsonParse { } } - fn call(context: &Context, manage_memory: bool) -> Result, RuntimeError> { + fn call(context: &Context, _: bool) -> Result, RuntimeError> { let target_type = if let Some(r#type) = context.get_type(&Identifier::new("T"))? { r#type } else { diff --git a/dust-lang/src/abstract_tree/function_call.rs b/dust-lang/src/abstract_tree/function_call.rs index ec9a419..d7751cd 100644 --- a/dust-lang/src/abstract_tree/function_call.rs +++ b/dust-lang/src/abstract_tree/function_call.rs @@ -1,4 +1,3 @@ -use chumsky::container::Container; use serde::{Deserialize, Serialize}; use crate::{ @@ -56,19 +55,14 @@ impl AbstractNode for FunctionCall { } } - let function_node_type = if let Expression::Value(WithPosition { - node: ValueNode::BuiltInFunction(function), - .. - }) = self.function_expression.as_ref() - { - function.r#type() - } else if let Some(r#type) = self.function_expression.expected_type(context)? { - r#type - } else { - return Err(ValidationError::ExpectedExpression( - self.function_expression.position(), - )); - }; + let function_node_type = + if let Some(r#type) = self.function_expression.expected_type(context)? { + r#type + } else { + return Err(ValidationError::ExpectedExpression( + self.function_expression.position(), + )); + }; if let Type::Function { type_parameters, diff --git a/dust-lang/src/abstract_tree/type.rs b/dust-lang/src/abstract_tree/type.rs index 04b76bc..c39c75c 100644 --- a/dust-lang/src/abstract_tree/type.rs +++ b/dust-lang/src/abstract_tree/type.rs @@ -264,7 +264,7 @@ impl Display for Type { value_parameters, return_type, } => { - write!(f, "(")?; + write!(f, "fn (")?; if let Some(type_parameters) = type_parameters { for identifier in type_parameters { diff --git a/dust-lang/src/identifier.rs b/dust-lang/src/identifier.rs index ac8999f..9362c20 100644 --- a/dust-lang/src/identifier.rs +++ b/dust-lang/src/identifier.rs @@ -16,19 +16,19 @@ fn identifier_cache<'a>() -> &'a RwLock> { pub struct Identifier(Arc); impl Identifier { - pub fn new(string: &str) -> Self { + pub fn new(text: &str) -> Self { let cache = identifier_cache(); - if let Some(identifier) = cache.read().unwrap().get(string) { + if let Some(identifier) = cache.read().unwrap().get(text) { return identifier.clone(); } - let identifier = Identifier(Arc::new(string.to_string())); + let identifier = Identifier(Arc::new(text.to_string())); cache .write() .unwrap() - .insert(string.to_string(), identifier.clone()); + .insert(text.to_string(), identifier.clone()); identifier }