about summary refs log tree commit diff
path: root/tvix/eval/src
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-08-12T16·27+0300
committertazjin <tazjin@tvl.su>2022-08-28T17·50+0000
commitbbad338017c94efbf3fa966528b8e9c751449328 (patch)
tree5224bdbc7fc5f271c7e7929a12802795a6d09f1f /tvix/eval/src
parentde21d201ba7bca518ebbcfa091cdff94d7ea152e (diff)
feat(tvix/eval): prepare structures for simulating locals stack r/4521
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 <grfn@gws.fyi>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src')
-rw-r--r--tvix/eval/src/compiler.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/tvix/eval/src/compiler.rs b/tvix/eval/src/compiler.rs
index c840056b48f3..a0c62b112869 100644
--- a/tvix/eval/src/compiler.rs
+++ b/tvix/eval/src/compiler.rs
@@ -32,6 +32,30 @@ pub struct CompilationResult {
     pub warnings: Vec<EvalWarning>,
 }
 
+// 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<Local>,
+
+    // How many scopes "deep" are these locals?
+    scope_depth: usize,
+}
+
 struct Compiler {
     chunk: Chunk,
     warnings: Vec<EvalWarning>,