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
This commit is contained in:
greg 2016-12-29 04:31:25 -08:00
parent e84550f3ec
commit 29d9e50311
1 changed files with 5 additions and 3 deletions

View File

@ -3,6 +3,8 @@ extern crate take_mut;
use std::collections::HashMap;
use parser::{AST, ASTNode, Expression, Function};
type Reduction<T> = (T, Option<SideEffect>);
#[derive(Debug)]
enum SideEffect {
Print(String),
@ -136,7 +138,7 @@ impl Evaluator {
}
}
fn reduce_astnode(&mut self, node: ASTNode) -> (ASTNode, Option<SideEffect>) {
fn reduce_astnode(&mut self, node: ASTNode) -> Reduction<ASTNode> {
use parser::ASTNode::*;
match node {
ExprNode(expr) => {
@ -155,7 +157,7 @@ impl Evaluator {
}
}
fn reduce_expr(&mut self, expression: Expression) -> (Expression, Option<SideEffect>) {
fn reduce_expr(&mut self, expression: Expression) -> Reduction<Expression> {
use parser::Expression::*;
match expression {
Null => (Null, None),
@ -262,7 +264,7 @@ impl Evaluator {
fn reduce_call(&mut self,
name: String,
arguments: Vec<Expression>)
-> (Expression, Option<SideEffect>) {
-> Reduction<Expression> {
use parser::Expression::*;
// ugly hack for now