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:
parent
af9dca3663
commit
6ce2c666c3
5 changed files with 17 additions and 10 deletions
28
tvix/eval/src/value/function.rs
Normal file
28
tvix/eval/src/value/function.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
//! This module implements the runtime representation of functions.
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::chunk::Chunk;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Lambda {
|
||||
// name: Option<NixString>,
|
||||
pub(crate) chunk: Rc<Chunk>,
|
||||
}
|
||||
|
||||
impl Lambda {
|
||||
pub fn new_anonymous() -> Self {
|
||||
Lambda {
|
||||
// name: None,
|
||||
chunk: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chunk(&mut self) -> &mut Rc<Chunk> {
|
||||
&mut self.chunk
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Closure {
|
||||
pub lambda: Lambda,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue