diff options
author | Vincent Ambo <mail@tazj.in> | 2021-01-14T00·47+0300 |
---|---|---|
committer | tazjin <mail@tazj.in> | 2021-01-14T00·52+0000 |
commit | 0c1c4584cb46cc3564f4d18bd3f451e648c413b6 (patch) | |
tree | 0c653692e0b4355308d92d3d95998505d70bb31f /users/tazjin | |
parent | 9b477975d4d26bdbb7f2a54d8fe9eee76bdc0ca9 (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
Diffstat (limited to 'users/tazjin')
-rw-r--r-- | users/tazjin/rlox/src/interpreter.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/users/tazjin/rlox/src/interpreter.rs b/users/tazjin/rlox/src/interpreter.rs index ef76af916838..744e6ea89552 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) |