Sort of fix cart assignments

This commit is contained in:
Alex Bethel 2021-10-12 14:33:23 -06:00
parent cdf4c5a308
commit 31fe3f53be

View file

@ -19,7 +19,7 @@ use std::{
use rand::random; use rand::random;
use crate::{ use crate::{
ast::{Expr, ExprKind, Ident, Stmt, StmtKind}, ast::{AssignableKind, Expr, ExprKind, Ident, Stmt, StmtKind},
base_55, base_55,
consts::ablescript_consts, consts::ablescript_consts,
error::{Error, ErrorKind}, error::{Error, ErrorKind},
@ -246,13 +246,20 @@ impl ExecEnv {
}, },
StmtKind::Assign { assignable, value } => { StmtKind::Assign { assignable, value } => {
let value = self.eval_expr(value)?; let value = self.eval_expr(value)?;
match &assignable.kind { match assignable.kind {
crate::ast::AssignableKind::Variable => { AssignableKind::Variable => {
&self.get_var_mut(&assignable.ident)?.value &self.get_var_mut(&assignable.ident)?.value.replace(value);
}
AssignableKind::Cart { ref indices } => {
let mut cell = self.get_var_rc(&assignable.ident)?;
for index in indices {
let index = self.eval_expr(index)?;
let value = cell.borrow().to_owned();
cell = Rc::clone(value.into_cart().get(&index).unwrap());
}
cell.replace(value);
} }
crate::ast::AssignableKind::Cart { indices } => todo!("assigning to carts"),
} }
.replace(value);
} }
StmtKind::Break => { StmtKind::Break => {
return Ok(HaltStatus::Break(stmt.span.clone())); return Ok(HaltStatus::Break(stmt.span.clone()));