From 984b66b0aa80133942399881eda97aeb41fd80cf Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 5 Dec 2023 17:40:22 -0500 Subject: [PATCH] Implement new function syntax --- src/abstract_tree/function_call.rs | 9 +++++++-- src/abstract_tree/type_defintion.rs | 11 ++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/abstract_tree/function_call.rs b/src/abstract_tree/function_call.rs index c01682c..2444c9b 100644 --- a/src/abstract_tree/function_call.rs +++ b/src/abstract_tree/function_call.rs @@ -43,7 +43,7 @@ impl AbstractTree for FunctionCall { if let Type::Function { parameter_types, - return_type, + return_type: _, } = function_type { let argument_type_pairs = arguments.iter().zip(parameter_types.iter()); @@ -51,7 +51,11 @@ impl AbstractTree for FunctionCall { for (argument, r#type) in argument_type_pairs { let argument_type = argument.expected_type(context)?; - r#type.check(&argument_type, context, node, source)?; + if let Type::Function { return_type, .. } = argument_type { + r#type.check(&return_type, context, node, source)?; + } else { + r#type.check(&argument_type, context, node, source)?; + } } } @@ -84,6 +88,7 @@ impl AbstractTree for FunctionCall { } let variables = context.variables()?; + if let Some(value) = variables.get(key) { value.clone() } else { diff --git a/src/abstract_tree/type_defintion.rs b/src/abstract_tree/type_defintion.rs index 75f2ac6..46bb084 100644 --- a/src/abstract_tree/type_defintion.rs +++ b/src/abstract_tree/type_defintion.rs @@ -196,13 +196,18 @@ impl Display for Type { parameter_types, return_type, } => { - write!(f, "fn ")?; + write!(f, "(")?; for parameter_type in parameter_types { - write!(f, "{parameter_type} ")?; + write!(f, "{parameter_type}")?; + + if parameter_type != parameter_types.last().unwrap() { + write!(f, " ")?; + } } - write!(f, "-> {return_type}") + write!(f, ")")?; + write!(f, " -> {return_type}") } Type::Integer => write!(f, "int"), Type::List(item_type) => write!(f, "[{item_type}]"),