diff options
Diffstat (limited to 'src/env.cff')
| -rw-r--r-- | src/env.cff | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/env.cff b/src/env.cff index d1eab07..0ae465a 100644 --- a/src/env.cff +++ b/src/env.cff @@ -1,6 +1,7 @@ import "cffc.hff"; import "map.hff"; import "util.hff"; +import "common.hff"; struct StringKeyTraits { fn hash(s *const u8) u32 { return fnv1a_s(FNV1A_INI, s); } @@ -19,11 +20,27 @@ extern fn mkenv(parent *Env, alloc *Allocator) *Env { return env; } -extern fn envput(env *Env, decl *const Decl) *Decl { +extern fn envput(env *Env, decl Decl, old **const Decl) *Decl { let l **DeclList = env.decls->get_slot(decl.name); - let n *DeclList = env.alloc->alloc(sizeof *DeclList); + let n *DeclList = anew(env.alloc, DeclList); + if *l { // decl with this name exists + *old = &(*l).decl; + return #null; + } n.link = *l; - n.decl = *decl; + n.decl = decl; *l = n; return &n.decl; } + +extern fn envfind(env *Env, name *const u8) *Decl { + let l **DeclList = env.decls->get(name); + if l == #null { return #null; } + let l = *l; + assert(l != #null, "l?"); + return &l.decl; +} + +extern fn envfree(env *Env) void { + env.decls->clear(); +} |