about summary refs log tree commit diff
path: root/tvix/eval/src/compiler/mod.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-08-24T19·08+0300
committertazjin <tazjin@tvl.su>2022-09-03T00·47+0000
commit6ce2c666c32a3ecb5512a5b186896ae1a1f84838 (patch)
treea78a11e2f9080dc59e87470b3b11f14a6c653dac /tvix/eval/src/compiler/mod.rs
parentaf9dca36635df677fce559c5fdd3f08680d84557 (diff)
refactor(tvix/eval): introduce Closure struct in Value type r/4605
This struct will carry the upvalue machinery in addition to the lambda
itself. For now, all lambdas are wrapped in closures (though
technically analysis of the environment can later remove innermost
Closure wrapper, but this optimisation may not be worth it).

Change-Id: If2b68549ec1ea4ab838fdc47a2181c694ac937f2
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6269
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/compiler/mod.rs')
-rw-r--r--tvix/eval/src/compiler/mod.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs
index 5cb02a66b9..3160c68c6e 100644
--- a/tvix/eval/src/compiler/mod.rs
+++ b/tvix/eval/src/compiler/mod.rs
@@ -23,7 +23,7 @@ use std::rc::Rc;
 use crate::chunk::Chunk;
 use crate::errors::{Error, ErrorKind, EvalResult};
 use crate::opcode::{CodeIdx, OpCode};
-use crate::value::{Lambda, Value};
+use crate::value::{Closure, Lambda, Value};
 use crate::warnings::{EvalWarning, WarningKind};
 
 /// Represents the result of compiling a piece of Nix code. If
@@ -822,7 +822,9 @@ impl Compiler {
             crate::disassembler::disassemble_chunk(&compiled.lambda.chunk);
         }
 
-        self.emit_constant(Value::Lambda(compiled.lambda));
+        self.emit_constant(Value::Closure(Closure {
+            lambda: compiled.lambda,
+        }));
     }
 
     fn compile_apply(&mut self, node: ast::Apply) {