Implement functions, both top-level and anonymous

Implement both top-level and anonymous functions, but not closures in
either case.
This commit is contained in:
Griffin Smith 2021-03-08 00:04:44 -05:00
parent 80f8ede0bb
commit 1ea2d8ba9f
10 changed files with 503 additions and 127 deletions

View file

@ -1,4 +1,5 @@
use std::collections::HashMap;
use std::mem;
use crate::ast::Ident;
@ -25,6 +26,14 @@ impl<'ast, V> Env<'ast, V> {
self.0.pop();
}
pub fn save(&mut self) -> Self {
mem::take(self)
}
pub fn restore(&mut self, saved: Self) {
*self = saved;
}
pub fn set(&mut self, k: &'ast Ident<'ast>, v: V) {
self.0.last_mut().unwrap().insert(k, v);
}