From 29d9e50311c11fb301562f5b4be7e63e1d7c4cb5 Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 29 Dec 2016 04:31:25 -0800 Subject: [PATCH] All environment changes represented explicitly Start the work of rewriting the evluator to be a true small-step evaluator - that is, all state changes are represented explicitly as SideEffect types, and not as methods called on the evaluator, except at the very top of the evaluation loop --- src/eval.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/eval.rs b/src/eval.rs index 0b77991..f5401f3 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -3,6 +3,8 @@ extern crate take_mut; use std::collections::HashMap; use parser::{AST, ASTNode, Expression, Function}; +type Reduction = (T, Option); + #[derive(Debug)] enum SideEffect { Print(String), @@ -136,7 +138,7 @@ impl Evaluator { } } - fn reduce_astnode(&mut self, node: ASTNode) -> (ASTNode, Option) { + fn reduce_astnode(&mut self, node: ASTNode) -> Reduction { use parser::ASTNode::*; match node { ExprNode(expr) => { @@ -155,7 +157,7 @@ impl Evaluator { } } - fn reduce_expr(&mut self, expression: Expression) -> (Expression, Option) { + fn reduce_expr(&mut self, expression: Expression) -> Reduction { use parser::Expression::*; match expression { Null => (Null, None), @@ -262,7 +264,7 @@ impl Evaluator { fn reduce_call(&mut self, name: String, arguments: Vec) - -> (Expression, Option) { + -> Reduction { use parser::Expression::*; // ugly hack for now