Rc is got by reference by default
This commit is contained in:
parent
95e790d8e8
commit
5ccc181f47
|
@ -307,10 +307,10 @@ impl ExecEnv {
|
||||||
fn assign(&mut self, dest: &Assignable, value: Value) -> Result<(), Error> {
|
fn assign(&mut self, dest: &Assignable, value: Value) -> Result<(), Error> {
|
||||||
match dest.kind {
|
match dest.kind {
|
||||||
AssignableKind::Variable => {
|
AssignableKind::Variable => {
|
||||||
self.get_var_rc(&dest.ident)?.replace(value);
|
self.get_var_rc_mut(&dest.ident)?.replace(value);
|
||||||
}
|
}
|
||||||
AssignableKind::Index { ref indices } => {
|
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 {
|
for index in indices {
|
||||||
let index = self.eval_expr(index)?;
|
let index = self.eval_expr(index)?;
|
||||||
|
|
||||||
|
@ -366,7 +366,7 @@ 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(&Spanned::new(name.to_owned(), arg.span.clone()))
|
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)
|
||||||
}
|
}
|
||||||
|
@ -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.
|
/// if the variable is inaccessible or banned.
|
||||||
fn get_var_rc(&mut self, name: &Spanned<String>) -> Result<ValueRef, Error> {
|
fn get_var_rc_mut(&mut self, name: &Spanned<String>) -> Result<&mut ValueRef, Error> {
|
||||||
match self.get_var_mut(name)? {
|
match self.get_var_mut(name)? {
|
||||||
Variable::Ref(r) => Ok(r.clone()),
|
Variable::Ref(r) => Ok(r),
|
||||||
Variable::Melo => Err(Error {
|
Variable::Melo => Err(Error {
|
||||||
kind: ErrorKind::MeloVariable(name.item.to_owned()),
|
kind: ErrorKind::MeloVariable(name.item.to_owned()),
|
||||||
span: name.span.clone(),
|
span: name.span.clone(),
|
||||||
|
|
Loading…
Reference in a new issue