From 3aaefc3000dd80b88d30aefd9e58ceee5a1eddee Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 7 Aug 2022 23:41:07 +0300 Subject: feat(tvix/eval): add initial chunk representation Change-Id: I53202e93938bede421c8f1c98901e4c67544e257 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6069 Tested-by: BuildkiteCI Reviewed-by: grfn --- tvix/eval/src/chunk.rs | 26 ++++++++++++++++++++++++++ tvix/eval/src/main.rs | 1 + 2 files changed, 27 insertions(+) create mode 100644 tvix/eval/src/chunk.rs diff --git a/tvix/eval/src/chunk.rs b/tvix/eval/src/chunk.rs new file mode 100644 index 0000000000..3475e58f18 --- /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, + constants: Vec, +} + +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 fc366961b5..c55f48a543 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; -- cgit 1.4.1