From 538f0b18f471c36671b50598ac9204535734ba28 Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 5 Jan 2017 04:00:29 -0800 Subject: [PATCH] Evaluate while loop --- src/eval.rs | 8 ++++++-- while.schala | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 while.schala 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