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 {
Binding {
name: Rc<String>,
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)
}
}
}

View File

@ -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<Option<Expr>> {
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)?)),