about summary refs log tree commit diff
path: root/tvix
diff options
context:
space:
mode:
Diffstat (limited to 'tvix')
-rw-r--r--tvix/eval/src/compiler.rs2
-rw-r--r--tvix/eval/src/opcode.rs9
-rw-r--r--tvix/eval/src/vm.rs22
3 files changed, 25 insertions, 8 deletions
diff --git a/tvix/eval/src/compiler.rs b/tvix/eval/src/compiler.rs
index acbf018f81e7..297d23d3d84f 100644
--- a/tvix/eval/src/compiler.rs
+++ b/tvix/eval/src/compiler.rs
@@ -78,7 +78,7 @@ impl Compiler {
             BinOpKind::Sub => OpCode::OpSub,
             BinOpKind::Mul => OpCode::OpMul,
             BinOpKind::Div => OpCode::OpDiv,
-
+            BinOpKind::Equal => OpCode::OpEqual,
             _ => todo!(),
         };
 
diff --git a/tvix/eval/src/opcode.rs b/tvix/eval/src/opcode.rs
index 0aa252c4cc08..a9f7f8904058 100644
--- a/tvix/eval/src/opcode.rs
+++ b/tvix/eval/src/opcode.rs
@@ -17,13 +17,16 @@ pub enum OpCode {
     OpTrue,
     OpFalse,
 
+    // Unary operators
+    OpInvert,
+    OpNegate,
+
     // Arithmetic binary operators
     OpAdd,
     OpSub,
     OpMul,
     OpDiv,
 
-    // Unary operators
-    OpInvert,
-    OpNegate,
+    // Logical binary operators
+    OpEqual,
 }
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() {