1
0

Add while loops

This commit is contained in:
Jeff 2024-03-11 18:21:40 -04:00
parent 346d9ba878
commit 4be32d0a5d
2 changed files with 18 additions and 4 deletions

View File

@ -40,7 +40,8 @@ impl AbstractTree for Block {
let action = statement.run(_context)?; let action = statement.run(_context)?;
previous = match action { previous = match action {
Action::Return(value) => Action::Return(value), Action::Return(value) => Action::Return(value),
r#break => return Ok(r#break), Action::None => Action::None,
Action::Break => return Ok(action),
}; };
} }

View File

@ -19,14 +19,27 @@ impl While {
impl AbstractTree for While { impl AbstractTree for While {
fn expected_type(&self, _context: &Context) -> Result<Type, ValidationError> { fn expected_type(&self, _context: &Context) -> Result<Type, ValidationError> {
todo!() Ok(Type::None)
} }
fn validate(&self, _context: &Context) -> Result<(), ValidationError> { fn validate(&self, _context: &Context) -> Result<(), ValidationError> {
todo!() self.expression.validate(_context)?;
self.block.validate(_context)
} }
fn run(self, _context: &Context) -> Result<Action, RuntimeError> { fn run(self, _context: &Context) -> Result<Action, RuntimeError> {
todo!() while self
.expression
.clone()
.run(_context)?
.as_return_value()?
.as_boolean()?
{
if let Action::Break = self.block.clone().run(_context)? {
break;
}
}
Ok(Action::None)
} }
} }