Get/Set variables from the environment
This commit is contained in:
parent
2a7db71ded
commit
5436a706d7
@ -31,12 +31,17 @@ impl<'a> Env<'a> {
|
|||||||
panic!("Variable {} not in scope.", id)
|
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) {
|
pub fn eval(ast: &parser::Stmt, env: &mut Env) {
|
||||||
match &ast {
|
match &ast {
|
||||||
parser::Stmt::ReplPrint(expr) =>
|
parser::Stmt::ReplPrint(expr) =>
|
||||||
println!("{}", eval_expr(expr, env)),
|
println!("{}", eval_expr(expr, env)),
|
||||||
|
parser::Stmt::Assignment(id, expr) =>
|
||||||
|
env.set(id.clone(), eval_expr(expr, env)),
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user