about summary refs log tree commit diff
path: root/tvix/eval/src/vm.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-08-07T23·51+0300
committertazjin <tazjin@tvl.su>2022-08-12T14·09+0000
commitded0fb9e21d4b8794fa668941474b26d45ef6f3d (patch)
tree84cb0a335888dcf9f050ed1b916e3b6b2027afe7 /tvix/eval/src/vm.rs
parent28f57abac1e4fc97b983af1b891d553db0a628d9 (diff)
feat(tvix/eval): implement equality operator r/4414
Change-Id: I9dd54aed72cd7e67593dc76f5a046ebbda40c26f
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6078
Tested-by: BuildkiteCI
Autosubmit: tazjin <tazjin@tvl.su>
Reviewed-by: grfn <grfn@gws.fyi>
Diffstat (limited to 'tvix/eval/src/vm.rs')
-rw-r--r--tvix/eval/src/vm.rs22
1 files changed, 18 insertions, 4 deletions
diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs
index da79867ef3f0..25a9074c7592 100644
--- a/tvix/eval/src/vm.rs
+++ b/tvix/eval/src/vm.rs
@@ -92,10 +92,24 @@ impl VM {
                     }
                 },
 
-                OpCode::OpInvert => todo!(),
-                OpCode::OpNull => todo!(),
-                OpCode::OpTrue => todo!(),
-                OpCode::OpFalse => todo!(),
+                OpCode::OpEqual => {
+                    let v2 = self.pop();
+                    let v1 = self.pop();
+
+                    let eq = match (v1, v2) {
+                        (Value::Float(f), Value::Integer(i))
+                        | (Value::Integer(i), Value::Float(f)) => f == (i as f64),
+
+                        _ => v2 == v2,
+                    };
+
+                    self.push(Value::Bool(eq))
+                }
+
+                OpCode::OpInvert => todo!("invert"),
+                OpCode::OpNull => todo!("null"),
+                OpCode::OpTrue => todo!("true"),
+                OpCode::OpFalse => todo!("false"),
             }
 
             if self.ip == self.chunk.code.len() {