1
0

Implement new function syntax

This commit is contained in:
Jeff 2023-12-05 17:40:22 -05:00
parent ed4dd6a819
commit 984b66b0aa
2 changed files with 15 additions and 5 deletions

View File

@ -43,7 +43,7 @@ impl AbstractTree for FunctionCall {
if let Type::Function { if let Type::Function {
parameter_types, parameter_types,
return_type, return_type: _,
} = function_type } = function_type
{ {
let argument_type_pairs = arguments.iter().zip(parameter_types.iter()); let argument_type_pairs = arguments.iter().zip(parameter_types.iter());
@ -51,9 +51,13 @@ impl AbstractTree for FunctionCall {
for (argument, r#type) in argument_type_pairs { for (argument, r#type) in argument_type_pairs {
let argument_type = argument.expected_type(context)?; let argument_type = argument.expected_type(context)?;
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)?; r#type.check(&argument_type, context, node, source)?;
} }
} }
}
let function_call = FunctionCall { let function_call = FunctionCall {
function_expression, function_expression,
@ -84,6 +88,7 @@ impl AbstractTree for FunctionCall {
} }
let variables = context.variables()?; let variables = context.variables()?;
if let Some(value) = variables.get(key) { if let Some(value) = variables.get(key) {
value.clone() value.clone()
} else { } else {

View File

@ -196,12 +196,17 @@ impl Display for Type {
parameter_types, parameter_types,
return_type, return_type,
} => { } => {
write!(f, "fn ")?; write!(f, "(")?;
for parameter_type in parameter_types { 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, ")")?;
write!(f, " -> {return_type}") write!(f, " -> {return_type}")
} }
Type::Integer => write!(f, "int"), Type::Integer => write!(f, "int"),