feat(tvix/eval): add initial representation of builtins

Builtins are represented as a Rust function pointer that accepts a
vector of arguments, which represents variable arity builtins.

Change-Id: Ibab7e662a646caf1172695d876d2f55e187c03dd
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6251
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
This commit is contained in:
Vincent Ambo 2022-08-24 11:00:30 +03:00 committed by tazjin
parent 64746388e2
commit e0f1356ae3
3 changed files with 76 additions and 1 deletions

View file

@ -358,6 +358,11 @@ impl VM {
let callable = self.pop();
match callable {
Value::Lambda(lambda) => self.call(lambda, 1),
Value::Builtin(builtin) => {
let arg = self.pop();
let result = builtin.apply(arg)?;
self.push(result);
}
_ => return Err(ErrorKind::NotCallable.into()),
};
}