about summary refs log tree commit diff
path: root/tvix/eval/src/opcode.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-09-13T12·58+0300
committertazjin <tazjin@tvl.su>2022-09-13T14·41+0000
commitd5ee893fb15f9d2aae676763f12b507ad33243b0 (patch)
tree6731461c6ca5ff54982648b4372fac56d89b7ea9 /tvix/eval/src/opcode.rs
parenta9914a79a0e55741efc7f8b6d694c043248abf2c (diff)
refactor(tvix/eval): use CodeIdx wrapper for instruction pointer r/4838
As suggested by sterni in cl/6453.

Change-Id: I3cf80d97c11fd7d085ab510f6be4b5f937c791ec
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6562
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/opcode.rs')
-rw-r--r--tvix/eval/src/opcode.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/tvix/eval/src/opcode.rs b/tvix/eval/src/opcode.rs
index 27fceaf967..aee45d7a44 100644
--- a/tvix/eval/src/opcode.rs
+++ b/tvix/eval/src/opcode.rs
@@ -1,6 +1,8 @@
 //! This module implements the instruction set running on the abstract
 //! machine implemented by tvix.
 
+use std::ops::{AddAssign, Sub};
+
 /// Index of a constant in the current code chunk.
 #[repr(transparent)]
 #[derive(Clone, Copy, Debug)]
@@ -11,6 +13,20 @@ pub struct ConstantIdx(pub usize);
 #[derive(Clone, Copy, Debug)]
 pub struct CodeIdx(pub usize);
 
+impl AddAssign<usize> for CodeIdx {
+    fn add_assign(&mut self, rhs: usize) {
+        *self = CodeIdx(self.0 + rhs)
+    }
+}
+
+impl Sub<usize> for CodeIdx {
+    type Output = Self;
+
+    fn sub(self, rhs: usize) -> Self::Output {
+        CodeIdx(self.0 - rhs)
+    }
+}
+
 /// Index of a value in the runtime stack.
 #[repr(transparent)]
 #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd)]