Mercurial > lbo > hg > ylisp
changeset 149:df0e17d18c80
value: Implement yref_eq
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Tue, 03 Sep 2019 12:17:19 +0200 |
parents | 1620bde57dcb |
children | a4a714456110 |
files | src/value.c src/value.h |
diffstat | 2 files changed, 20 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/value.c Tue Sep 03 12:16:44 2019 +0200 +++ b/src/value.c Tue Sep 03 12:17:19 2019 +0200 @@ -89,6 +89,21 @@ return ref; } +bool yref_eq(yref_t* a, yref_t* b) { + if (yref_type(a) != yref_type(b)) return false; + YREF_TYPE t = yref_type(a); + switch (t) { + case YREF_SYM: + return 0 == ystr_cmp(&a->ref.sym, &b->ref.sym); + case YREF_ID: + return a->ref.id == b->ref.id; + case YREF_STACK: + return a->ref.cix == b->ref.cix; + default: + return false; + } +} + uint64_t yref_cix(yref_t* ref) { return ref->ref.cix ^ YVALUE_CIX_MARKER; } yref_t yref_clone(yref_t* ref) { @@ -274,6 +289,5 @@ } hdestroy_r(&yvalue_name_table); yvec_destroy(&yvalue_table); - fprintf(stderr, "freed %llu values\n", freed); }
--- a/src/value.h Tue Sep 03 12:16:44 2019 +0200 +++ b/src/value.h Tue Sep 03 12:17:19 2019 +0200 @@ -83,6 +83,11 @@ uint64_t yref_cix(yref_t* ref); /** + * Return true if the references are identical. + */ +bool yref_eq(yref_t* a, yref_t* b); + +/** * Create a debug description of ref. */ ystr_t yref_debug(yref_t* ref);