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

@ -6,7 +6,7 @@ use std::rc::Rc;
use crate::{
chunk::Chunk,
errors::{ErrorKind, EvalResult},
opcode::OpCode,
opcode::{JumpOffset, OpCode},
value::{Closure, Lambda, NixAttrs, NixList, Value},
};
@ -266,23 +266,23 @@ impl VM {
OpCode::OpInterpolate(count) => self.run_interpolate(count)?,
OpCode::OpJump(offset) => {
OpCode::OpJump(JumpOffset(offset)) => {
self.frame_mut().ip += offset;
}
OpCode::OpJumpIfTrue(offset) => {
OpCode::OpJumpIfTrue(JumpOffset(offset)) => {
if self.peek(0).as_bool()? {
self.frame_mut().ip += offset;
}
}
OpCode::OpJumpIfFalse(offset) => {
OpCode::OpJumpIfFalse(JumpOffset(offset)) => {
if !self.peek(0).as_bool()? {
self.frame_mut().ip += offset;
}
}
OpCode::OpJumpIfNotFound(offset) => {
OpCode::OpJumpIfNotFound(JumpOffset(offset)) => {
if matches!(self.peek(0), Value::AttrNotFound) {
self.pop();
self.frame_mut().ip += offset;