From 9cc9c5977d443e0c5b82639a5c9d2479a868b36f Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 29 Dec 2016 15:53:48 -0800 Subject: [PATCH] Fixed evaluation of function calls This bit still isn't quite small-step but maybe that's okay for functions --- main.schala | 16 +++++++++++++--- src/eval.rs | 11 ++--------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/main.schala b/main.schala index eed299c..bd6c1d1 100644 --- a/main.schala +++ b/main.schala @@ -1,7 +1,17 @@ +fn add(a, b) + a + b +end + +fn subtract(a, b) + a - b +end fn main() -a = 4 -b = 20 -a + b + first_value = add(20, 20) + second_value = subtract(700, 650) + first_value + second_value end + +main() + diff --git a/src/eval.rs b/src/eval.rs index 8ab3e6e..c322dbd 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -8,7 +8,6 @@ type Reduction = (T, Option); #[derive(Debug)] enum SideEffect { Print(String), - Bundle(Vec), AddBinding(String, Expression), } @@ -128,11 +127,6 @@ impl Evaluator { use self::SideEffect::*; match side_effect { Print(s) => println!("{}", s), - Bundle(l) => { - for side_effect in l { - self.perform_side_effect(side_effect); - } - } AddBinding(var, value) => { self.add_binding(var, value); } @@ -285,19 +279,18 @@ impl Evaluator { self.frames.push(frame); let mut retval = Null; - let mut side_effects = Vec::new(); for expr in function.body.iter() { retval = expr.clone(); while retval.is_reducible() { let r = self.reduce_expr(retval); retval = r.0; if let Some(s) = r.1 { - side_effects.push(s); + self.perform_side_effect(s); } } } self.frames.pop(); - (retval, Some(SideEffect::Bundle(side_effects))) + (retval, None) } }