refactor(tvix/eval): use CodeIdx wrapper for instruction pointer
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
This commit is contained in:
parent
a9914a79a0
commit
d5ee893fb1
3 changed files with 34 additions and 9 deletions
|
|
@ -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)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue