aboutsummaryrefslogtreecommitdiff
path: root/src/env.cff
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2022-08-15 12:22:47 +0200
committerlemon <lsof@mailbox.org>2022-08-15 12:22:47 +0200
commitf906d0b350b0b4ceb747669c9a9845d11bd0e486 (patch)
tree5f09a7b714e6ce93f6094a06e5f736513110fb8d /src/env.cff
parentf802bb99263aaa5be492999babd44cd2fdb1c65f (diff)
self hosted progress
Diffstat (limited to 'src/env.cff')
-rw-r--r--src/env.cff23
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();
+}