From 5634a8ad2b4b2cca797b4341fc89d9c8d70bb7d4 Mon Sep 17 00:00:00 2001 From: Alex Bethel Date: Sat, 23 Oct 2021 15:08:10 -0600 Subject: [PATCH] Get cart assignments working --- ablescript/src/interpret.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/ablescript/src/interpret.rs b/ablescript/src/interpret.rs index 3bd8c788..d7db46be 100644 --- a/ablescript/src/interpret.rs +++ b/ablescript/src/interpret.rs @@ -255,14 +255,20 @@ impl ExecEnv { for index in indices { let index = self.eval_expr(index)?; - let value = cell.borrow().to_owned(); - let mut value = value.into_cart(); - if let Some(x) = value.get(&index) { - cell = Rc::clone(x); - } else { - cell = Rc::new(RefCell::new(Value::Cart(Default::default()))); - value.insert(index, Rc::clone(&cell)); + let next_cell; + match &mut *cell.borrow_mut() { + Value::Cart(c) => { + if let Some(x) = c.get(&index) { + next_cell = Rc::clone(x); + } else { + next_cell = + Rc::new(RefCell::new(Value::Cart(Default::default()))); + c.insert(index, Rc::clone(&next_cell)); + } + } + _ => todo!(), } + cell = next_cell; } cell.replace(value); }