1
0

Get built-in functions working

This commit is contained in:
Jeff 2024-08-07 18:39:28 -04:00
parent 4d7f59aee2
commit b17da5ad3c
2 changed files with 6 additions and 30 deletions

View File

@ -256,26 +256,8 @@ impl<'src> Parser<'src> {
(Token::IsEven, left_span) => {
self.next_token()?;
let mut value_parameters = None;
if let (Token::LeftParenthesis, _) = self.current {
self.next_token()?;
value_parameters = Some(vec![self.parse_node(0)?]);
loop {
self.next_token()?;
if let (Token::RightParenthesis, _) = self.current {
break;
}
if let (Token::Comma, _) = self.current {
self.next_token()?;
}
value_parameters.as_mut().unwrap().push(self.parse_node(0)?);
}
} else {
return Err(ParseError::ExpectedOpeningParenthesis {
actual: self.current.0.clone(),
@ -296,7 +278,7 @@ impl<'src> Parser<'src> {
Statement::BuiltInFunctionCall {
function: BuiltInFunction::IsEven,
type_arguments: None,
value_arguments: value_parameters,
value_arguments: None,
},
left_span,
))

View File

@ -213,13 +213,11 @@ impl<P: Copy> Vm<P> {
},
) = (left_value, right.statement)
{
if let Some(mut nodes) = value_argument_nodes.take() {
nodes.insert(0, Node::new(Statement::Constant(value), right_span));
}
let value_arguments = if let Some(value_nodes) = value_argument_nodes {
let mut value_arguments = Vec::new();
value_arguments.push(value);
if let Some(value_nodes) = value_argument_nodes {
for node in value_nodes {
let position = node.position;
let value = if let Some(value) = self.run_node(node, variables)? {
@ -230,13 +228,9 @@ impl<P: Copy> Vm<P> {
value_arguments.push(value);
}
}
Some(value_arguments)
} else {
None
};
let function_call_return = function.call(None, value_arguments)?;
let function_call_return = function.call(None, Some(value_arguments))?;
return Ok(Some(function_call_return));
}