Mercurial > lbo > hg > ylisp
changeset 89:50cbad7d31da
value: Create symbolic reference if it doesn't exist in yvalue_set
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Mon, 26 Aug 2019 14:56:17 +0200 |
parents | d197a9c11953 |
children | 340408c24a6e |
files | src/value.c src/value.h |
diffstat | 2 files changed, 9 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/value.c Mon Aug 26 14:54:21 2019 +0200 +++ b/src/value.c Mon Aug 26 14:56:17 2019 +0200 @@ -188,6 +188,7 @@ assert(new_index == (yvalue_counter - YVALUE_COUNTER_OFFSET - 1)); return ref; } else { + yvalue_resolve_or_create_ref(&ref); yvalue_t* valp = yvalue_get(ref); assert(valp != NULL); *valp = *val;
--- a/src/value.h Mon Aug 26 14:54:21 2019 +0200 +++ b/src/value.h Mon Aug 26 14:56:17 2019 +0200 @@ -92,7 +92,7 @@ typedef struct { union { /// A function to be called. Functions are immutable, they can not be - //updated once set. + // updated once set. yfunc_t func; /// An expression (often a scalar number/string/atom) yexpr_t expr; @@ -130,9 +130,13 @@ void yvalue_resolve_or_create_ref(yref_t* ref); /** - * @brief Set a value referenced by `ref`. If a new value should be created, use - * the special ref value `YVALUE_INSERT`. The value pointed to by val may not be - * destroyed afterwards (the variable itself can be deallocated though). + * @brief Set a value referenced by `ref`. If a new anonymous reference should + * be created, use the special ref value `YVALUE_INSERT`. The value pointed to + * by val may not be destroyed afterwards (the variable itself can be + * deallocated though). If the reference is a symbolic reference that does not + * exist yet, it is resolved and created first. + * + * The reference at which the value was insertes is returned. */ yref_t yvalue_set(yref_t ref, yvalue_t* val);