diff --git a/src/eval.rs b/src/eval.rs index 9fad776..1ab93fc 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -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() { diff --git a/while.schala b/while.schala new file mode 100644 index 0000000..5eb0866 --- /dev/null +++ b/while.schala @@ -0,0 +1,7 @@ + + +a = 0 +while a < 10 + print("hello", a) + a = a + 1 +end