summaryrefslogtreecommitdiff
path: root/val.c
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-06-21 01:05:00 +0100
committerubq323 <ubq323@ubq323.website>2024-06-21 01:05:00 +0100
commit5298940fc7798455d701d075b910e0545d3f6048 (patch)
treeebdded23f23468d164dd3c073c27185360b3f66c /val.c
parenta03973653262fbbfed7ce42dfa39646d16bdc98f (diff)
proper equality for values; deduplicate constants in compilation
Diffstat (limited to 'val.c')
-rw-r--r--val.c11
1 files changed, 11 insertions, 0 deletions
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) {