From 3c104f5312604a6a1a0dd80528cc937159bc57ef Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Fri, 29 Jul 2022 12:27:09 +0200 Subject: types: resolve upvalue references on stringification When stringifying upvalue references, resolve their target value and convert it to a string. Only yield the abstract string representation if the target value cannot be resolved. Signed-off-by: Jo-Philipp Wich --- types.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'types.c') diff --git a/types.c b/types.c index 9700d8f..e7c9afa 100644 --- a/types.c +++ b/types.c @@ -1487,6 +1487,7 @@ ucv_to_stringbuf_formatted(uc_vm_t *vm, uc_stringbuf_t *pb, uc_value_t *uv, size uc_closure_t *closure; uc_regexp_t *regexp; uc_value_t *argname; + uc_upvalref_t *ref; uc_array_t *array; size_t i, l; double d; @@ -1686,10 +1687,17 @@ ucv_to_stringbuf_formatted(uc_vm_t *vm, uc_stringbuf_t *pb, uc_value_t *uv, size break; case UC_UPVALUE: - ucv_stringbuf_printf(pb, "%s%s", - json ? "\"" : "", - uv, - json ? "\"" : ""); + ref = (uc_upvalref_t *)uv; + + if (ref->closed) + ucv_to_stringbuf_formatted(vm, pb, ref->value, depth, pad_char, pad_size); + else if (vm != NULL && ref->slot < vm->stack.count) + ucv_to_stringbuf_formatted(vm, pb, vm->stack.entries[ref->slot], depth, pad_char, pad_size); + else + ucv_stringbuf_printf(pb, "%s%s", + json ? "\"" : "", + uv, + json ? "\"" : ""); break; -- cgit v1.2.3