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-08-26T17·58+0300
committerclbot <clbot@tvl.fyi>2022-09-03T13·27+0000
commit2f93ed297e3cef8486e9160f5d3d68be1939d7d5 (patch)
tree70b54f27eccbc6a5d4a709ade21b2f5c0ca17a0a /tvix/eval/src/opcode.rs
parentc73e84d95777c304f1b208cbc43b01012df73262 (diff)
refactor(tvix/eval): add opcode::Count type for less ambiguity r/4622
Change-Id: Ibde0b2baa1128a74c1364ee9a6330b62db3da699
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6288
Autosubmit: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'tvix/eval/src/opcode.rs')
-rw-r--r--tvix/eval/src/opcode.rs16
1 files changed, 11 insertions, 5 deletions
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,