From 6ce2c666c32a3ecb5512a5b186896ae1a1f84838 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Wed, 24 Aug 2022 22:08:26 +0300 Subject: 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 Tested-by: BuildkiteCI --- tvix/eval/src/value/function.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tvix/eval/src/value/function.rs (limited to 'tvix/eval/src/value/function.rs') diff --git a/tvix/eval/src/value/function.rs b/tvix/eval/src/value/function.rs new file mode 100644 index 000000000000..45efc24f09f8 --- /dev/null +++ b/tvix/eval/src/value/function.rs @@ -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, + pub(crate) chunk: Rc, +} + +impl Lambda { + pub fn new_anonymous() -> Self { + Lambda { + // name: None, + chunk: Default::default(), + } + } + + pub fn chunk(&mut self) -> &mut Rc { + &mut self.chunk + } +} + +#[derive(Clone, Debug)] +pub struct Closure { + pub lambda: Lambda, +} -- cgit 1.4.1