ref: 53bc10145695df7160e374bca21f4a9510e3fd7d
parent: 0b58f43116b059473c24999e488f6471123dcdf8
author: Ori Bernstein <ori@eigenstate.org>
date: Thu Sep 24 17:39:40 EDT 2015
Capture and dump function environments in parse. We can now dump the closure of a function correctly. We still don't compile it, though.
--- a/parse/dump.c
+++ b/parse/dump.c
@@ -84,6 +84,17 @@
outsym(getdcl(st, k[i]), fd, 0);
}
free(k);
+
+ /* dump closure */
+ if (st->closure) {
+ k = htkeys(st->closure, &n);
+ for (i = 0; i < n; i++) {
+ findentf(fd, depth + 1, "U ");
+ /* already indented */
+ outsym(getdcl(st, k[i]), fd, 0);
+ }
+ free(k);
+ }
}
void dumpstab(Stab *st, FILE *fd)
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -486,6 +486,7 @@
Stab *getns(Node *file, char *n);
Node *getdcl(Stab *st, Node *n);
+Node *getcapture(Stab *st, Node *n);
Type *gettype_l(Stab *st, Node *n);
Type *gettype(Stab *st, Node *n);
Node *getimpl(Stab *st, Node *impl);
--- a/parse/stab.c
+++ b/parse/stab.c
@@ -98,6 +98,13 @@
return st;
}
+Node *getcapture(Stab *st, Node *n)
+{
+ if (!st->closure)
+ return NULL;
+ return htget(st->closure, n);
+}
+
/*
* Searches for declarations from current
* scope, and all enclosing scopes. Does
@@ -118,10 +125,10 @@
s = htget(st->dcl, n);
if (s) {
/* record that this is in the closure of this scope */
- if (!st->closure)
- st->closure = mkht(nsnamehash, nsnameeq);
+ if (!orig->closure)
+ orig->closure = mkht(nsnamehash, nsnameeq);
if (st != orig && !n->decl.isglobl)
- htput(st->closure, s->decl.name, s);
+ htput(orig->closure, s->decl.name, s);
return s;
}
st = st->super;