feat(tvix/eval): compile creation of closure objects

Fully implements the instructions for compiling closure
objects (without runtime handling yet).

Closure (and thunk) objects are created at runtime by capturing all
known upvalues. To represent this, the instructions for creating them
need to have a variable number of arguments. Due to that, this commit
introduces new variants in OpCode that are not actually operations,
but data.

If the VM is implemented correctly, the instruction pointer should
never point at these. Due to this, the VM will panic if it sees a data
operand during an execution run.

Change-Id: Ic56b49b3a42736dc437751e76df0e89c8d0619c6
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6291
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
This commit is contained in:
Vincent Ambo 2022-08-27 00:21:08 +03:00 committed by tazjin
parent e4fadfaaf8
commit 69d8f17a26
4 changed files with 51 additions and 6 deletions

View file

@ -357,7 +357,7 @@ impl VM {
OpCode::OpCall => {
let callable = self.pop();
match callable {
Value::Closure(Closure { lambda }) => self.call(lambda, 1),
Value::Closure(Closure { lambda, .. }) => self.call(lambda, 1),
Value::Builtin(builtin) => {
let arg = self.pop();
let result = builtin.apply(arg)?;
@ -368,6 +368,13 @@ impl VM {
}
OpCode::OpGetUpvalue(_) => todo!("getting upvalues"),
OpCode::OpClosure(_) => todo!("creating closure objects"),
// Data-carrying operands should never be executed,
// that is a critical error in the VM.
OpCode::DataLocalIdx(_) | OpCode::DataUpvalueIdx(_) => {
panic!("VM bug: attempted to execute data-carrying operand")
}
}
#[cfg(feature = "disassembler")]