Fix built-in function bug
This commit is contained in:
parent
ff5c4972eb
commit
fbcb28ce24
@ -191,9 +191,11 @@ where
|
|||||||
|
|
||||||
fn evaluate(
|
fn evaluate(
|
||||||
self,
|
self,
|
||||||
_: &Context,
|
context: &Context,
|
||||||
manage_memory: bool,
|
manage_memory: bool,
|
||||||
) -> Result<Option<Evaluation>, RuntimeError> {
|
) -> Result<Option<Evaluation>, RuntimeError> {
|
||||||
|
self.context.set_parent(context.clone())?;
|
||||||
|
|
||||||
self.function.call(&self.context, manage_memory)
|
self.function.call(&self.context, manage_memory)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -350,7 +352,7 @@ impl FunctionLogic for WriteLine {
|
|||||||
) {
|
) {
|
||||||
(
|
(
|
||||||
None::<array::IntoIter<Identifier, 0>>,
|
None::<array::IntoIter<Identifier, 0>>,
|
||||||
Some([(Identifier::new("message"), Type::String)].into_iter()),
|
Some([(Identifier::new("output"), Type::Any)].into_iter()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,18 +360,24 @@ impl FunctionLogic for WriteLine {
|
|||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call(self, context: &Context, _: bool) -> Result<Option<Evaluation>, RuntimeError> {
|
fn call(
|
||||||
let message = context.get_value(&Identifier::new("message"))?;
|
self,
|
||||||
|
context: &Context,
|
||||||
|
manage_memory: bool,
|
||||||
|
) -> Result<Option<Evaluation>, RuntimeError> {
|
||||||
|
let position = self.0.position();
|
||||||
|
let evaluation = self.0.evaluate(context, manage_memory)?;
|
||||||
|
let value = if let Some(Evaluation::Return(value)) = evaluation {
|
||||||
|
value
|
||||||
|
} else {
|
||||||
|
return Err(RuntimeError::ValidationFailure(
|
||||||
|
ValidationError::ExpectedExpression(position),
|
||||||
|
));
|
||||||
|
};
|
||||||
|
|
||||||
if let Some(message) = message {
|
println!("{value}");
|
||||||
println!("{message}");
|
|
||||||
|
|
||||||
Ok(None)
|
Ok(None)
|
||||||
} else {
|
|
||||||
Err(RuntimeError::ValidationFailure(
|
|
||||||
ValidationError::BuiltInFunctionFailure(self.0.position()),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,12 @@ impl Context {
|
|||||||
Context::new(Some(self.clone()))
|
Context::new(Some(self.clone()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_parent(&self, parent: Context) -> Result<(), PoisonError> {
|
||||||
|
self.data.write()?.parent = Some(parent);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn contains(&self, identifier: &Identifier) -> Result<bool, PoisonError> {
|
pub fn contains(&self, identifier: &Identifier) -> Result<bool, PoisonError> {
|
||||||
log::trace!("Checking that {identifier} exists.");
|
log::trace!("Checking that {identifier} exists.");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user