This commit is contained in:
Jeff 2024-06-24 11:06:12 -04:00
parent fbaf640fce
commit 2cbeb4b551
4 changed files with 20 additions and 26 deletions

View File

@ -71,7 +71,7 @@ impl FunctionLogic for Length {
}
}
fn call(context: &Context, manage_memory: bool) -> Result<Option<Value>, RuntimeError> {
fn call(context: &Context, _: bool) -> Result<Option<Value>, 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<Option<Value>, RuntimeError> {
fn call(context: &Context, _: bool) -> Result<Option<Value>, 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<Option<Value>, RuntimeError> {
fn call(_: &Context, _: bool) -> Result<Option<Value>, 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<Option<Value>, RuntimeError> {
fn call(context: &Context, _: bool) -> Result<Option<Value>, 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<Option<Value>, RuntimeError> {
fn call(context: &Context, _: bool) -> Result<Option<Value>, 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<Option<Value>, RuntimeError> {
fn call(context: &Context, _: bool) -> Result<Option<Value>, RuntimeError> {
let target_type = if let Some(r#type) = context.get_type(&Identifier::new("T"))? {
r#type
} else {

View File

@ -1,4 +1,3 @@
use chumsky::container::Container;
use serde::{Deserialize, Serialize};
use crate::{
@ -56,13 +55,8 @@ 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)? {
let function_node_type =
if let Some(r#type) = self.function_expression.expected_type(context)? {
r#type
} else {
return Err(ValidationError::ExpectedExpression(

View File

@ -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 {

View File

@ -16,19 +16,19 @@ fn identifier_cache<'a>() -> &'a RwLock<HashMap<String, Identifier>> {
pub struct Identifier(Arc<String>);
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
}