about summary refs log tree commit diff
path: root/tvix/eval/src/opcode.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-08-26T21·21+0300
committertazjin <tazjin@tvl.su>2022-09-03T21·55+0000
commit69d8f17a26db50e7b76297dbf588aafc23425c71 (patch)
tree227759e59cfc419b3cdc8a4b6de38e2301f6b38a /tvix/eval/src/opcode.rs
parente4fadfaaf8b7e821b77ce4dc41b915ff83f8e240 (diff)
feat(tvix/eval): compile creation of closure objects r/4625
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>
Diffstat (limited to 'tvix/eval/src/opcode.rs')
-rw-r--r--tvix/eval/src/opcode.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/tvix/eval/src/opcode.rs b/tvix/eval/src/opcode.rs
index 6cce7ea9b1..ca99602862 100644
--- a/tvix/eval/src/opcode.rs
+++ b/tvix/eval/src/opcode.rs
@@ -102,7 +102,17 @@ pub enum OpCode {
     // Asserts stack top is a boolean, and true.
     OpAssert,
 
-    // Lambdas
+    // Lambdas & closures
     OpCall,
     OpGetUpvalue(UpvalueIdx),
+    OpClosure(ConstantIdx),
+
+    // The closure and thunk creation instructions have a variable
+    // number of arguments to the instruction, which is represented
+    // here by making their data part of the opcodes.
+    //
+    // The VM skips over these by advancing the instruction pointer
+    // according to the count.
+    DataLocalIdx(StackIdx),
+    DataUpvalueIdx(UpvalueIdx),
 }