about summary refs log tree commit diff
path: root/tvix/eval/src/vm.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/eval/src/vm.rs')
-rw-r--r--tvix/eval/src/vm.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs
index 9a718500b5f1..e8c0551caf67 100644
--- a/tvix/eval/src/vm.rs
+++ b/tvix/eval/src/vm.rs
@@ -1,11 +1,13 @@
 //! This module implements the virtual (or abstract) machine that runs
 //! Tvix bytecode.
 
+use std::{collections::BTreeMap, rc::Rc};
+
 use crate::{
     chunk::Chunk,
     errors::{Error, EvalResult},
     opcode::OpCode,
-    value::Value,
+    value::{NixAttrs, NixString, Value},
 };
 
 pub struct VM {
@@ -114,6 +116,7 @@ impl VM {
                 OpCode::OpNull => self.push(Value::Null),
                 OpCode::OpTrue => self.push(Value::Bool(true)),
                 OpCode::OpFalse => self.push(Value::Bool(false)),
+                OpCode::OpAttrs(count) => self.run_attrset(count)?,
             }
 
             if self.ip == self.chunk.code.len() {
@@ -121,6 +124,20 @@ impl VM {
             }
         }
     }
+
+    fn run_attrset(&mut self, count: usize) -> EvalResult<()> {
+        let mut attrs: BTreeMap<NixString, Value> = BTreeMap::new();
+
+        for _ in 0..count {
+            let value = self.pop();
+            let key = self.pop().as_string()?; // TODO(tazjin): attrpath
+            attrs.insert(key, value);
+        }
+        // TODO(tazjin): extend_reserve(count) (rust#72631)
+
+        self.push(Value::Attrs(Rc::new(NixAttrs::Map(attrs))));
+        Ok(())
+    }
 }
 
 #[derive(Clone, Copy, Debug, PartialEq)]