summaryrefslogtreecommitdiffhomepage
path: root/compiler.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-07-20 09:38:16 +0200
committerJo-Philipp Wich <jo@mein.io>2022-07-30 00:41:56 +0200
commit862e49de33bd07daea129d553968579019c79b59 (patch)
tree1c0b1410ae47606cf5710c3b0c83898b74fa898b /compiler.c
parent78dfb08f7569904394249758b2d7a563366b60ff (diff)
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 <jo@mein.io>
Diffstat (limited to 'compiler.c')
-rw-r--r--compiler.c14
1 files changed, 13 insertions, 1 deletions
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);