about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2021-01-14T00·47+0300
committertazjin <mail@tazj.in>2021-01-14T00·52+0000
commit0c1c4584cb46cc3564f4d18bd3f451e648c413b6 (patch)
tree0c653692e0b4355308d92d3d95998505d70bb31f
parent9b477975d4d26bdbb7f2a54d8fe9eee76bdc0ca9 (diff)
feat(tazjin/rlox): Implement PartialEq for interpreter::Value r/2099
Values have equality, unless they're functions.

Change-Id: Ie5c623081a1fa556e6b7a5251b0ce85af68dd31a
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2385
Reviewed-by: tazjin <mail@tazj.in>
Tested-by: BuildkiteCI
-rw-r--r--users/tazjin/rlox/src/interpreter.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/users/tazjin/rlox/src/interpreter.rs b/users/tazjin/rlox/src/interpreter.rs
index ef76af9168..744e6ea895 100644
--- a/users/tazjin/rlox/src/interpreter.rs
+++ b/users/tazjin/rlox/src/interpreter.rs
@@ -38,6 +38,16 @@ pub enum Value {
     Callable(Callable),
 }
 
+impl PartialEq for Value {
+    fn eq(&self, other: &Self) -> bool {
+        match (self, other) {
+            (Value::Literal(lhs), Value::Literal(rhs)) => lhs == rhs,
+            // functions do not have equality
+            _ => false,
+        }
+    }
+}
+
 impl From<Literal> for Value {
     fn from(lit: Literal) -> Value {
         Value::Literal(lit)