diff --git a/src/twopass.rs b/src/twopass.rs index 2770c6e..591805e 100644 --- a/src/twopass.rs +++ b/src/twopass.rs @@ -334,6 +334,31 @@ impl Eval for Expression { } } +impl Eval for Statement { + fn eval(&self, ctx: &RunContext) -> types::Value { + match self { + Statement::Assign { target, source } => { + let source = source.eval(ctx); + match target { + Location::Variable { id } => ctx.var(*id).set(source), + Location::Field { table, index } => { + let table = table.eval(ctx).expect("attempt to index a nil value"); + let index = index.eval(ctx).expect("attempt to index with a nil value"); + let types::ValueInner::Table(table) = table else { + panic!("attempt to index a non-table"); + }; + table.set(index, source) + } + } + } + Statement::Call(call) => { + call.eval(ctx); + } + }; + None + } +} + impl Function { fn call(&self, upvalues: &[types::Value], args: &[types::Value]) -> types::Value { assert_eq!(upvalues.len(), self.upvalues.len());