summaryrefslogtreecommitdiff
path: root/parse/stab.c
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-09-24 23:21:08 -0700
committerOri Bernstein <ori@eigenstate.org>2015-09-24 23:21:08 -0700
commitd23b4a240fb0b8ad401081e29230737502d13ad4 (patch)
treec86d67aab2a3055c92194158e248e9f8d1d3dbd4 /parse/stab.c
parentdd1dcc663ada21c70e41003564e5c57d671981ac (diff)
downloadmc-d23b4a240fb0b8ad401081e29230737502d13ad4.tar.gz
Error out correctly with closures.
Diffstat (limited to 'parse/stab.c')
-rw-r--r--parse/stab.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/parse/stab.c b/parse/stab.c
index c28330f..f4c592a 100644
--- a/parse/stab.c
+++ b/parse/stab.c
@@ -109,6 +109,29 @@ Node *getclosed(Stab *st, Node *n)
return NULL;
}
+Node **getclosure(Stab *st, size_t *n)
+{
+ size_t nkeys, i;
+ void **keys;
+ Node **vals;
+
+ while (st && !st->env)
+ st = st->super;
+
+ if (!st) {
+ *n = 0;
+ return NULL;
+ }
+
+ vals = NULL;
+ *n = 0;
+ keys = htkeys(st->env, &nkeys);
+ for (i = 0; i < nkeys; i++)
+ lappend(&vals, n, htget(st->env, keys[i]));
+ free(keys);
+ return vals;
+}
+
/*
* Searches for declarations from current
* scope, and all enclosing scopes. Does
@@ -127,14 +150,14 @@ Node *getdcl(Stab *st, Node *n)
fn = NULL;
do {
s = htget(st->dcl, n);
- if (!fn && st->env)
- fn = st;
if (s) {
/* record that this is in the closure of this scope */
- if (fn && !n->decl.isglobl)
+ if (fn && !s->decl.isglobl)
htput(fn->env, s->decl.name, s);
return s;
}
+ if (!fn && st->env)
+ fn = st;
st = st->super;
} while (st);
return NULL;