From 01986e7474f169a95a4279af1b8318ac52864af8 Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 11 May 2018 02:24:38 -0700 Subject: [PATCH] starting bindings --- schala-lang/src/ast_reducing.rs | 7 ++++++- schala-lang/src/eval.rs | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/schala-lang/src/ast_reducing.rs b/schala-lang/src/ast_reducing.rs index fd660f5..3555907 100644 --- a/schala-lang/src/ast_reducing.rs +++ b/schala-lang/src/ast_reducing.rs @@ -10,6 +10,7 @@ pub struct ReducedAST(pub Vec); pub enum Stmt { Binding { name: Rc, + constant: bool, expr: Expr, }, Expr(Expr), @@ -76,7 +77,11 @@ impl Expression { impl Declaration { fn reduce(&self) -> Stmt { - Stmt::Expr(Expr::UnimplementedSigilValue) + use self::Declaration::*; + match self { + &Binding { ref name, ref constant, ref expr } => Stmt::Binding { name: name.clone(), constant: *constant, expr: expr.reduce() }, + _ => Stmt::Expr(Expr::UnimplementedSigilValue) + } } } diff --git a/schala-lang/src/eval.rs b/schala-lang/src/eval.rs index 65452ba..8354cf3 100644 --- a/schala-lang/src/eval.rs +++ b/schala-lang/src/eval.rs @@ -19,6 +19,7 @@ impl<'a> State<'a> { #[derive(Debug)] enum ValueEntry { Binding { + constant: bool, val: /*FullyEvaluatedExpr*/ Expr, }, /* @@ -364,8 +365,9 @@ impl<'a> State<'a> { fn statement(&mut self, stmt: Stmt) -> EvalResult> { match stmt { - Stmt::Binding { .. } => { - //TODO mutate some state here + Stmt::Binding { name, constant, expr } => { + let val = self.expression(expr)?; + self.values.insert(name.clone(), ValueEntry::Binding { constant, val }); Ok(None) }, Stmt::Expr(expr) => Ok(Some(self.expression(expr)?)),