From 862e49de33bd07daea129d553968579019c79b59 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Wed, 20 Jul 2022 09:38:16 +0200 Subject: compiler: resolve predeclared upvalues Do not require a parent function compiler reference to lookup an already declared (potentially unresolved) upvalue in the current scope. Instead, search the named upvalues in the current function scope in case there is no parent compiler reference. This is required for the upcoming module support which will use unresolved upvalues to realize import/export functionality. Signed-off-by: Jo-Philipp Wich --- compiler.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/compiler.c b/compiler.c index db8917b..70d15d6 100644 --- a/compiler.c +++ b/compiler.c @@ -790,10 +790,22 @@ uc_compiler_add_upval(uc_compiler_t *compiler, size_t idx, bool local, uc_value_ static ssize_t uc_compiler_resolve_upval(uc_compiler_t *compiler, uc_value_t *name, bool *constant) { + uc_upvals_t *upvals = &compiler->upvals; + uc_upval_t *uv; ssize_t idx; + size_t i; + + if (!compiler->parent) { + for (i = 0, uv = upvals->entries; i < upvals->count; i++, uv = upvals->entries + i) { + if (ucv_is_equal(uv->name, name) && uv->local == false) { + *constant = uv->constant; + + return i; + } + } - if (!compiler->parent) return -1; + } idx = uc_compiler_resolve_local(compiler->parent, name, constant); -- cgit v1.2.3