From 1ea2d8ba9fef3bee2c757d19d8b42e541e3fe390 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Mon, 8 Mar 2021 00:04:44 -0500 Subject: Implement functions, both top-level and anonymous Implement both top-level and anonymous functions, but not closures in either case. --- src/common/env.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/common') diff --git a/src/common/env.rs b/src/common/env.rs index 8b5cde49e9e4..f499323639e3 100644 --- a/src/common/env.rs +++ b/src/common/env.rs @@ -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); } -- cgit 1.4.1