diff --git a/ablescript/src/interpret.rs b/ablescript/src/interpret.rs index febd1c7..d0885d0 100644 --- a/ablescript/src/interpret.rs +++ b/ablescript/src/interpret.rs @@ -307,10 +307,10 @@ impl ExecEnv { fn assign(&mut self, dest: &Assignable, value: Value) -> Result<(), Error> { match dest.kind { AssignableKind::Variable => { - self.get_var_rc(&dest.ident)?.replace(value); + self.get_var_rc_mut(&dest.ident)?.replace(value); } AssignableKind::Index { ref indices } => { - let mut cell = self.get_var_rc(&dest.ident)?; + let mut cell = self.get_var_rc_mut(&dest.ident)?.clone(); for index in indices { let index = self.eval_expr(index)?; @@ -366,7 +366,7 @@ impl ExecEnv { .iter() .map(|arg| { if let Expr::Variable(name) = &arg.item { - self.get_var_rc(&Spanned::new(name.to_owned(), arg.span.clone())) + self.get_var_rc_mut(&Spanned::new(name.to_owned(), arg.span.clone())).cloned() } else { self.eval_expr(arg).map(ValueRef::new) } @@ -555,11 +555,11 @@ impl ExecEnv { } } - /// Get an Rc'd pointer to the value of a variable. Throw an error + /// Get an reference to an Rc'd pointer to the value of a variable. Throw an error /// if the variable is inaccessible or banned. - fn get_var_rc(&mut self, name: &Spanned) -> Result { + fn get_var_rc_mut(&mut self, name: &Spanned) -> Result<&mut ValueRef, Error> { match self.get_var_mut(name)? { - Variable::Ref(r) => Ok(r.clone()), + Variable::Ref(r) => Ok(r), Variable::Melo => Err(Error { kind: ErrorKind::MeloVariable(name.item.to_owned()), span: name.span.clone(),