about summary refs log tree commit diff
path: root/tvix
diff options
context:
space:
mode:
Diffstat (limited to 'tvix')
-rw-r--r--tvix/eval/src/compiler.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/tvix/eval/src/compiler.rs b/tvix/eval/src/compiler.rs
index d7d6bb38a757..ce3642b585e6 100644
--- a/tvix/eval/src/compiler.rs
+++ b/tvix/eval/src/compiler.rs
@@ -52,6 +52,11 @@ impl Compiler {
                 self.compile_attr_set(node)
             }
 
+            rnix::SyntaxKind::NODE_LIST => {
+                let node = rnix::types::List::cast(node).unwrap();
+                self.compile_list(node)
+            }
+
             kind => {
                 println!("visiting unsupported node: {:?}", kind);
                 Ok(())
@@ -190,6 +195,24 @@ impl Compiler {
         self.chunk.add_op(OpCode::OpAttrs(count));
         Ok(())
     }
+
+    // Compile list literals into equivalent bytecode. List
+    // construction is fairly simple, composing of pushing code for
+    // each literal element and an instruction with the element count.
+    //
+    // The VM, after evaluating the code for each element, simply
+    // constructs the list from the given number of elements.
+    fn compile_list(&mut self, node: rnix::types::List) -> EvalResult<()> {
+        let mut count = 0;
+
+        for item in node.items() {
+            count += 1;
+            self.compile(item)?;
+        }
+
+        self.chunk.add_op(OpCode::OpList(count));
+        Ok(())
+    }
 }
 
 pub fn compile(ast: rnix::AST) -> EvalResult<Chunk> {