refactor(tvix/eval): add opcode::JumpOffset type for less ambiguity

This adds a transparent wrapper around `usize` used for jump offsets
in the opcodes. This is a step towards getting rid of ambiguous plain
`usize` usage in the opcode.

Change-Id: I21e35e67d94b32d68251908b96c7f62b6f56a8bb
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6282
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
Vincent Ambo 2022-08-26 20:46:43 +03:00 committed by tazjin
parent 3b64b7eb2e
commit 4f00f75e31
3 changed files with 27 additions and 18 deletions

View file

@ -1,12 +1,18 @@
//! This module implements the instruction set running on the abstract
//! machine implemented by tvix.
#[repr(transparent)]
#[derive(Clone, Copy, Debug)]
pub struct ConstantIdx(pub usize);
#[repr(transparent)]
#[derive(Clone, Copy, Debug)]
pub struct CodeIdx(pub usize);
#[repr(transparent)]
#[derive(Clone, Copy, Debug)]
pub struct JumpOffset(pub usize);
#[allow(clippy::enum_variant_names)]
#[warn(variant_size_differences)]
#[derive(Clone, Copy, Debug)]
@ -40,10 +46,10 @@ pub enum OpCode {
OpMoreOrEq,
// Logical operators & generic jumps
OpJump(usize),
OpJumpIfTrue(usize),
OpJumpIfFalse(usize),
OpJumpIfNotFound(usize),
OpJump(JumpOffset),
OpJumpIfTrue(JumpOffset),
OpJumpIfFalse(JumpOffset),
OpJumpIfNotFound(JumpOffset),
// Attribute sets
OpAttrs(usize),