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)?)),