summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-07-29 12:27:09 +0200
committerJo-Philipp Wich <jo@mein.io>2022-07-30 00:41:51 +0200
commit3c104f5312604a6a1a0dd80528cc937159bc57ef (patch)
tree563a0d52974a71c44d502bfc922c5db09e2e32c2
parent3a6f9cbc8c1356ccf309f3bb8bdd5b895fb2e01a (diff)
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 <jo@mein.io>
-rw-r--r--types.c16
1 files changed, 12 insertions, 4 deletions
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<upvalref %p>%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<upvalref %p>%s",
+ json ? "\"" : "",
+ uv,
+ json ? "\"" : "");
break;