starting bindings

This commit is contained in:
greg 2018-05-11 02:24:38 -07:00
parent 9cf5260d4b
commit 01986e7474
2 changed files with 10 additions and 3 deletions

View File

@ -10,6 +10,7 @@ pub struct ReducedAST(pub Vec<Stmt>);
pub enum Stmt { pub enum Stmt {
Binding { Binding {
name: Rc<String>, name: Rc<String>,
constant: bool,
expr: Expr, expr: Expr,
}, },
Expr(Expr), Expr(Expr),
@ -76,7 +77,11 @@ impl Expression {
impl Declaration { impl Declaration {
fn reduce(&self) -> Stmt { 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)
}
} }
} }

View File

@ -19,6 +19,7 @@ impl<'a> State<'a> {
#[derive(Debug)] #[derive(Debug)]
enum ValueEntry { enum ValueEntry {
Binding { Binding {
constant: bool,
val: /*FullyEvaluatedExpr*/ Expr, val: /*FullyEvaluatedExpr*/ Expr,
}, },
/* /*
@ -364,8 +365,9 @@ impl<'a> State<'a> {
fn statement(&mut self, stmt: Stmt) -> EvalResult<Option<Expr>> { fn statement(&mut self, stmt: Stmt) -> EvalResult<Option<Expr>> {
match stmt { match stmt {
Stmt::Binding { .. } => { Stmt::Binding { name, constant, expr } => {
//TODO mutate some state here let val = self.expression(expr)?;
self.values.insert(name.clone(), ValueEntry::Binding { constant, val });
Ok(None) Ok(None)
}, },
Stmt::Expr(expr) => Ok(Some(self.expression(expr)?)), Stmt::Expr(expr) => Ok(Some(self.expression(expr)?)),