refactor(tvix/eval): introduce Closure struct in Value type

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
This commit is contained in:
Vincent Ambo 2022-08-24 22:08:26 +03:00 committed by tazjin
parent af9dca3663
commit 6ce2c666c3
5 changed files with 17 additions and 10 deletions

View file

@ -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) {