diff options
author | ubq323 <ubq323@ubq323.website> | 2024-06-21 01:05:00 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2024-06-21 01:05:00 +0100 |
commit | 5298940fc7798455d701d075b910e0545d3f6048 (patch) | |
tree | ebdded23f23468d164dd3c073c27185360b3f66c /val.c | |
parent | a03973653262fbbfed7ce42dfa39646d16bdc98f (diff) |
proper equality for values; deduplicate constants in compilation
Diffstat (limited to 'val.c')
-rw-r--r-- | val.c | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -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) { |