diff options
author | Griffin Smith <root@gws.fyi> | 2021-03-13T18·12-0500 |
---|---|---|
committer | Griffin Smith <root@gws.fyi> | 2021-03-13T18·12-0500 |
commit | f8beda81fbe8d04883aee71ff4ea078f897c6de4 (patch) | |
tree | ad61046d7e86c8a71381ee6b936fcd46ec3a89ac /src/interpreter/mod.rs | |
parent | 3dff189499af1ddd60d8fc128b794d15f1cb19ae (diff) |
Allow exprs+bindings to optionally be ascripted
Diffstat (limited to 'src/interpreter/mod.rs')
-rw-r--r-- | src/interpreter/mod.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index fc1556d1c292..00421ee90dc8 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -3,7 +3,9 @@ mod value; pub use self::error::{Error, Result}; pub use self::value::{Function, Value}; -use crate::ast::{BinaryOperator, Expr, FunctionType, Ident, Literal, Type, UnaryOperator}; +use crate::ast::{ + BinaryOperator, Binding, Expr, FunctionType, Ident, Literal, Type, UnaryOperator, +}; use crate::common::env::Env; #[derive(Debug, Default)] @@ -49,9 +51,9 @@ impl<'a> Interpreter<'a> { } Expr::Let { bindings, body } => { self.env.push(); - for (id, val) in bindings { - let val = self.eval(val)?; - self.env.set(id, val); + for Binding { ident, body, .. } in bindings { + let val = self.eval(body)?; + self.env.set(ident, val); } let res = self.eval(body)?; self.env.pop(); @@ -101,6 +103,7 @@ impl<'a> Interpreter<'a> { args: fun.args.iter().map(|arg| arg.to_owned()).collect(), body: fun.body.to_owned(), })), + Expr::Ascription { expr, .. } => self.eval(expr), } } } |