From bbad338017c94efbf3fa966528b8e9c751449328 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Fri, 12 Aug 2022 19:27:21 +0300 Subject: feat(tvix/eval): prepare structures for simulating locals stack These are going to be used during compilation of `let`-expressions to determine stack offsets for local variables. Change-Id: Ibb79f3f1ae86650303f88eacf623ae456458de87 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6187 Reviewed-by: grfn Tested-by: BuildkiteCI --- tvix/eval/src/compiler.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tvix/eval/src') diff --git a/tvix/eval/src/compiler.rs b/tvix/eval/src/compiler.rs index c840056b48..a0c62b1128 100644 --- a/tvix/eval/src/compiler.rs +++ b/tvix/eval/src/compiler.rs @@ -32,6 +32,30 @@ pub struct CompilationResult { pub warnings: Vec, } +// Represents a single local already known to the compiler. +struct Local { + // Definition name, which can be different kinds of tokens (plain + // string or identifier). Nix does not allow dynamic names inside + // of `let`-expressions. + name: rnix::SyntaxNode, + + // Scope depth of this local. + depth: usize, +} + +/// Represents locals known during compilation, which can be resolved +/// directly to stack indices. +/// +/// TODO(tazjin): `with`-stack +/// TODO(tazjin): flag "specials" (e.g. note depth if builtins are +/// overridden) +struct Locals { + locals: Vec, + + // How many scopes "deep" are these locals? + scope_depth: usize, +} + struct Compiler { chunk: Chunk, warnings: Vec, -- cgit 1.4.1