From 2f93ed297e3cef8486e9160f5d3d68be1939d7d5 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Fri, 26 Aug 2022 20:58:18 +0300 Subject: refactor(tvix/eval): add opcode::Count type for less ambiguity Change-Id: Ibde0b2baa1128a74c1364ee9a6330b62db3da699 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6288 Autosubmit: tazjin Tested-by: BuildkiteCI Reviewed-by: sterni --- tvix/eval/src/opcode.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'tvix/eval/src/opcode.rs') diff --git a/tvix/eval/src/opcode.rs b/tvix/eval/src/opcode.rs index 82b72952d6..f2daf9bd8e 100644 --- a/tvix/eval/src/opcode.rs +++ b/tvix/eval/src/opcode.rs @@ -21,6 +21,12 @@ pub struct StackIdx(pub usize); #[derive(Clone, Copy, Debug)] pub struct JumpOffset(pub usize); +/// Provided count for an instruction (could represent e.g. a number +/// of elements). +#[repr(transparent)] +#[derive(Clone, Copy, Debug)] +pub struct Count(pub usize); + #[allow(clippy::enum_variant_names)] #[warn(variant_size_differences)] #[derive(Clone, Copy, Debug)] @@ -60,8 +66,8 @@ pub enum OpCode { OpJumpIfNotFound(JumpOffset), // Attribute sets - OpAttrs(usize), - OpAttrPath(usize), + OpAttrs(Count), + OpAttrPath(Count), OpAttrsUpdate, OpAttrsSelect, OpAttrsTrySelect, @@ -73,11 +79,11 @@ pub enum OpCode { OpResolveWith, // Lists - OpList(usize), + OpList(Count), OpConcat, // Strings - OpInterpolate(usize), + OpInterpolate(Count), // Type assertion operators OpAssertBool, @@ -86,7 +92,7 @@ pub enum OpCode { OpGetLocal(StackIdx), // Close scopes while leaving their expression value around. - OpCloseScope(usize), // number of locals to pop + OpCloseScope(Count), // number of locals to pop // Asserts stack top is a boolean, and true. OpAssert, -- cgit 1.4.1