starting bindings
This commit is contained in:
parent
9cf5260d4b
commit
01986e7474
@ -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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)?)),
|
||||||
|
Loading…
Reference in New Issue
Block a user