summaryrefslogtreecommitdiff
path: root/val.c
diff options
context:
space:
mode:
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) {