about summary refs log tree commit diff
path: root/tvix/eval/src
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/eval/src')
-rw-r--r--tvix/eval/src/chunk.rs26
-rw-r--r--tvix/eval/src/main.rs1
2 files changed, 27 insertions, 0 deletions
diff --git a/tvix/eval/src/chunk.rs b/tvix/eval/src/chunk.rs
new file mode 100644
index 000000000000..3475e58f1870
--- /dev/null
+++ b/tvix/eval/src/chunk.rs
@@ -0,0 +1,26 @@
+use crate::opcode::{CodeIdx, ConstantIdx, OpCode};
+use crate::value::Value;
+
+#[derive(Debug, Default)]
+pub struct Chunk {
+    pub code: Vec<OpCode>,
+    constants: Vec<Value>,
+}
+
+impl Chunk {
+    pub fn add_op(&mut self, data: OpCode) -> CodeIdx {
+        let idx = self.code.len();
+        self.code.push(data);
+        CodeIdx(idx)
+    }
+
+    pub fn add_constant(&mut self, data: Value) -> ConstantIdx {
+        let idx = self.constants.len();
+        self.constants.push(data);
+        ConstantIdx(idx)
+    }
+
+    pub fn constant(&self, idx: ConstantIdx) -> &Value {
+        &self.constants[idx.0]
+    }
+}
diff --git a/tvix/eval/src/main.rs b/tvix/eval/src/main.rs
index fc366961b536..c55f48a5432e 100644
--- a/tvix/eval/src/main.rs
+++ b/tvix/eval/src/main.rs
@@ -4,6 +4,7 @@ use std::{
     mem, process,
 };
 
+mod chunk;
 mod errors;
 mod eval;
 mod opcode;