From 5298940fc7798455d701d075b910e0545d3f6048 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Fri, 21 Jun 2024 01:05:00 +0100 Subject: proper equality for values; deduplicate constants in compilation --- val.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'val.c') diff --git a/val.c b/val.c index 19f96a0..5a20d09 100644 --- a/val.c +++ b/val.c @@ -81,6 +81,17 @@ bool is_truthy(Val v) { return true; } +bool val_equal(Val a, Val b) { + if (a.ty != b.ty) return false; + switch (a.ty) { + case TY_NIL: return true; + case TY_NUM: return AS_NUM(a) == AS_NUM(b); + case TY_BOOL: return AS_BOOL(a) == AS_BOOL(b); + case TY_OBJ: return AS_OBJ(a) == AS_OBJ(b); + default: return false; + } +} + const char *typename_str(Val v) { switch(v.ty) { -- cgit v1.2.3