From f906d0b350b0b4ceb747669c9a9845d11bd0e486 Mon Sep 17 00:00:00 2001 From: lemon Date: Mon, 15 Aug 2022 12:22:47 +0200 Subject: self hosted progress --- src/env.cff | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src/env.cff') 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(); +} -- cgit v1.2.3