Get/Set variables from the environment

This commit is contained in:
Dane Johnson 2022-06-01 16:35:35 -05:00
parent 2a7db71ded
commit 5436a706d7

View File

@ -31,12 +31,17 @@ impl<'a> Env<'a> {
panic!("Variable {} not in scope.", id)
}
}
pub fn set(&mut self, id: String, atom: Atom) {
self.values.insert(id, atom);
}
}
pub fn eval(ast: &parser::Stmt, env: &mut Env) {
match &ast {
parser::Stmt::ReplPrint(expr) =>
println!("{}", eval_expr(expr, env)),
parser::Stmt::Assignment(id, expr) =>
env.set(id.clone(), eval_expr(expr, env)),
_ => todo!(),
}
}