1
0

Continue built-in function revision

This commit is contained in:
Jeff 2024-04-21 18:22:59 -04:00
parent dbbb912b82
commit 4726288b9a
3 changed files with 22 additions and 17 deletions

View File

@ -40,8 +40,8 @@ impl AbstractNode for BuiltInFunctionCall {
Ok(Action::Return(Value::string(buffer)))
}
BuiltInFunctionCall::Sleep(expression) => {
let expression_run = expression.clone().run(context)?;
let expression_value = if let Action::Return(value) = expression_run {
let action = expression.clone().run(context)?;
let value = if let Action::Return(value) = action {
value
} else {
return Err(RuntimeError::ValidationFailure(
@ -49,15 +49,28 @@ impl AbstractNode for BuiltInFunctionCall {
));
};
if let ValueInner::Integer(milliseconds) = expression_value.inner().as_ref() {
if let ValueInner::Integer(milliseconds) = value.inner().as_ref() {
thread::sleep(Duration::from_millis(*milliseconds as u64));
}
Ok(Action::None)
}
BuiltInFunctionCall::WriteLine(expression) => {
let action = expression.clone().run(context)?;
let value = if let Action::Return(value) = action {
value
} else {
panic!("Expected an integer.");
return Err(RuntimeError::ValidationFailure(
ValidationError::InterpreterExpectedReturn(expression.position()),
));
};
if let ValueInner::String(output) = value.inner().as_ref() {
println!("{output}");
}
Ok(Action::None)
}
BuiltInFunctionCall::WriteLine(_) => todo!(),
}
}
}

View File

@ -109,6 +109,7 @@ impl AbstractTree {
match run {
Ok(action) => match action {
Action::Return(value) => previous_value = Some(value),
Action::None => previous_value = None,
_ => {}
},
Err(runtime_error) => {

View File

@ -160,9 +160,6 @@ impl Display for Value {
write!(f, "): {} {:?}", return_type.node, body.node)
}
ValueInner::Function(function) => {
write!(f, "{function}")
}
ValueInner::Structure { name, fields } => {
let mut table = create_table();
@ -329,9 +326,3 @@ impl Function {
self.body.node.run(&context)
}
}
impl Display for Function {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
todo!()
}
}