eval statements
At this point there isn’t any real difference between expressions and statements
This commit is contained in:
parent
6af1dff560
commit
25dc5ab228
|
|
@ -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 {
|
impl Function {
|
||||||
fn call(&self, upvalues: &[types::Value], args: &[types::Value]) -> types::Value {
|
fn call(&self, upvalues: &[types::Value], args: &[types::Value]) -> types::Value {
|
||||||
assert_eq!(upvalues.len(), self.upvalues.len());
|
assert_eq!(upvalues.len(), self.upvalues.len());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user