From 5ccc181f476eb263170f8d1193b6db05f4f3b619 Mon Sep 17 00:00:00 2001 From: Erin Date: Fri, 22 Apr 2022 21:09:03 +0200 Subject: [PATCH] Rc is got by reference by default --- ablescript/src/interpret.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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(),