1
0
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"))? { let value = if let Some(value) = context.get_value(&Identifier::new("input"))? {
value value
} else { } 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"))? { let value = if let Some(value) = context.get_value(&Identifier::new("path"))? {
value value
} else { } 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(); let mut user_input = String::new();
stdin().read_line(&mut user_input)?; 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"))? { let value = if let Some(value) = context.get_value(&Identifier::new("milliseconds"))? {
value value
} else { } 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"))? { let value = if let Some(value) = context.get_value(&Identifier::new("output"))? {
value value
} else { } 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"))? { let target_type = if let Some(r#type) = context.get_type(&Identifier::new("T"))? {
r#type r#type
} else { } else {

View File

@ -1,4 +1,3 @@
use chumsky::container::Container;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{ use crate::{
@ -56,19 +55,14 @@ impl AbstractNode for FunctionCall {
} }
} }
let function_node_type = if let Expression::Value(WithPosition { let function_node_type =
node: ValueNode::BuiltInFunction(function), if let Some(r#type) = self.function_expression.expected_type(context)? {
.. r#type
}) = self.function_expression.as_ref() } else {
{ return Err(ValidationError::ExpectedExpression(
function.r#type() self.function_expression.position(),
} else 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 { if let Type::Function {
type_parameters, type_parameters,

View File

@ -264,7 +264,7 @@ impl Display for Type {
value_parameters, value_parameters,
return_type, return_type,
} => { } => {
write!(f, "(")?; write!(f, "fn (")?;
if let Some(type_parameters) = type_parameters { if let Some(type_parameters) = type_parameters {
for identifier in 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>); pub struct Identifier(Arc<String>);
impl Identifier { impl Identifier {
pub fn new(string: &str) -> Self { pub fn new(text: &str) -> Self {
let cache = identifier_cache(); 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(); return identifier.clone();
} }
let identifier = Identifier(Arc::new(string.to_string())); let identifier = Identifier(Arc::new(text.to_string()));
cache cache
.write() .write()
.unwrap() .unwrap()
.insert(string.to_string(), identifier.clone()); .insert(text.to_string(), identifier.clone());
identifier identifier
} }