Evaluate while loop

This commit is contained in:
greg 2017-01-05 04:00:29 -08:00
parent dc81d237c5
commit 538f0b18f4
2 changed files with 13 additions and 2 deletions

View File

@ -1,6 +1,7 @@
extern crate take_mut;
use std::collections::HashMap;
use std::collections::VecDeque;
use parser::{AST, Statement, Expression, Function};
use std::rc::Rc;
@ -206,8 +207,11 @@ impl<'a> Evaluator<'a> {
(Call(name, args), None)
}
}
While(box test, body) => {
unimplemented!()
While(test, body) => {
let mut block = VecDeque::from(body.clone());
block.push_back(While(test.clone(), body.clone()));
let reduction = Conditional(test, Box::new(Block(block)), None);
(reduction, None)
}
Conditional(box test, then_block, else_block) => {
if test.is_reducible() {

7
while.schala Normal file
View File

@ -0,0 +1,7 @@
a = 0
while a < 10
print("hello", a)
a = a + 1
end