eval!
This commit is contained in:
parent
25dc5ab228
commit
1e889cc604
|
|
@ -359,11 +359,23 @@ impl Eval for Statement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn new_var(value: &types::Value) -> VariableRef {
|
||||||
|
Rc::new(Variable(RefCell::new(value.clone())))
|
||||||
|
}
|
||||||
|
|
||||||
impl Function {
|
impl Function {
|
||||||
fn call(&self, upvalues: &[types::Value], args: &[types::Value]) -> types::Value {
|
fn call(&self, upvalues: &[VariableRef], args: &[types::Value]) -> types::Value {
|
||||||
assert_eq!(upvalues.len(), self.upvalues.len());
|
assert_eq!(upvalues.len(), self.upvalues.len());
|
||||||
assert_eq!(args.len(), self.args.len());
|
assert_eq!(args.len(), self.args.len());
|
||||||
todo!()
|
let ctx = RunContext {
|
||||||
|
args: args.iter().map(new_var).collect(),
|
||||||
|
locals: (0..self.locals.len()).map(|_| new_var(&None)).collect(),
|
||||||
|
upvalues: upvalues.to_vec(),
|
||||||
|
};
|
||||||
|
for statement in &self.body {
|
||||||
|
statement.eval(&ctx);
|
||||||
|
}
|
||||||
|
self.ret.eval(&ctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -371,7 +383,7 @@ impl OpenFunction {
|
||||||
pub fn call(&self, env: types::Value, args: &[types::Value]) -> types::Value {
|
pub fn call(&self, env: types::Value, args: &[types::Value]) -> types::Value {
|
||||||
match self.0.upvalues.as_slice() {
|
match self.0.upvalues.as_slice() {
|
||||||
[] => self.0.call(&[], args),
|
[] => self.0.call(&[], args),
|
||||||
[up] if up.0 == "_ENV" => self.0.call(&[env], args),
|
[up] if up.0 == "_ENV" => self.0.call(&[new_var(&env)], args),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user