Continue built-in function revision
This commit is contained in:
parent
dbbb912b82
commit
4726288b9a
@ -40,8 +40,8 @@ impl AbstractNode for BuiltInFunctionCall {
|
|||||||
Ok(Action::Return(Value::string(buffer)))
|
Ok(Action::Return(Value::string(buffer)))
|
||||||
}
|
}
|
||||||
BuiltInFunctionCall::Sleep(expression) => {
|
BuiltInFunctionCall::Sleep(expression) => {
|
||||||
let expression_run = expression.clone().run(context)?;
|
let action = expression.clone().run(context)?;
|
||||||
let expression_value = if let Action::Return(value) = expression_run {
|
let value = if let Action::Return(value) = action {
|
||||||
value
|
value
|
||||||
} else {
|
} else {
|
||||||
return Err(RuntimeError::ValidationFailure(
|
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));
|
thread::sleep(Duration::from_millis(*milliseconds as u64));
|
||||||
|
|
||||||
Ok(Action::None)
|
|
||||||
} else {
|
|
||||||
panic!("Expected an integer.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(Action::None)
|
||||||
|
}
|
||||||
|
BuiltInFunctionCall::WriteLine(expression) => {
|
||||||
|
let action = expression.clone().run(context)?;
|
||||||
|
let value = if let Action::Return(value) = action {
|
||||||
|
value
|
||||||
|
} else {
|
||||||
|
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!(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,6 +109,7 @@ impl AbstractTree {
|
|||||||
match run {
|
match run {
|
||||||
Ok(action) => match action {
|
Ok(action) => match action {
|
||||||
Action::Return(value) => previous_value = Some(value),
|
Action::Return(value) => previous_value = Some(value),
|
||||||
|
Action::None => previous_value = None,
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
Err(runtime_error) => {
|
Err(runtime_error) => {
|
||||||
|
@ -160,9 +160,6 @@ impl Display for Value {
|
|||||||
|
|
||||||
write!(f, "): {} {:?}", return_type.node, body.node)
|
write!(f, "): {} {:?}", return_type.node, body.node)
|
||||||
}
|
}
|
||||||
ValueInner::Function(function) => {
|
|
||||||
write!(f, "{function}")
|
|
||||||
}
|
|
||||||
ValueInner::Structure { name, fields } => {
|
ValueInner::Structure { name, fields } => {
|
||||||
let mut table = create_table();
|
let mut table = create_table();
|
||||||
|
|
||||||
@ -329,9 +326,3 @@ impl Function {
|
|||||||
self.body.node.run(&context)
|
self.body.node.run(&context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for Function {
|
|
||||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user