Double Melo causes variable deletion

This commit is contained in:
Erin 2022-04-22 21:14:53 +02:00 committed by ondra05
parent 5ccc181f47
commit db3b56d798

View file

@ -276,9 +276,16 @@ impl ExecEnv {
Stmt::HopBack => { Stmt::HopBack => {
return Ok(HaltStatus::Hopback(stmt.span.clone())); return Ok(HaltStatus::Hopback(stmt.span.clone()));
} }
Stmt::Melo(ident) => { Stmt::Melo(ident) => match self.get_var_mut(ident)? {
*self.get_var_mut(ident)? = Variable::Melo; var @ Variable::Ref(_) => *var = Variable::Melo,
Variable::Melo => {
for s in &mut self.stack {
if s.variables.remove(&ident.item).is_some() {
break;
} }
}
}
},
Stmt::Rlyeh => { Stmt::Rlyeh => {
// Maybe print a creepy error message or something // Maybe print a creepy error message or something
// here at some point. ~~Alex // here at some point. ~~Alex
@ -366,7 +373,8 @@ impl ExecEnv {
.iter() .iter()
.map(|arg| { .map(|arg| {
if let Expr::Variable(name) = &arg.item { if let Expr::Variable(name) = &arg.item {
self.get_var_rc_mut(&Spanned::new(name.to_owned(), arg.span.clone())).cloned() self.get_var_rc_mut(&Spanned::new(name.to_owned(), arg.span.clone()))
.cloned()
} else { } else {
self.eval_expr(arg).map(ValueRef::new) self.eval_expr(arg).map(ValueRef::new)
} }
@ -536,8 +544,7 @@ impl ExecEnv {
} }
} }
/// Get a mutable reference to a variable. Throw an error if the /// Get a mutable reference to a variable.
/// variable is inaccessible or banned.
fn get_var_mut(&mut self, name: &Spanned<String>) -> Result<&mut Variable, Error> { fn get_var_mut(&mut self, name: &Spanned<String>) -> Result<&mut Variable, Error> {
// This function has a lot of duplicated code with `get_var`, // This function has a lot of duplicated code with `get_var`,
// which I feel like is a bad sign... // which I feel like is a bad sign...