aboutsummaryrefslogtreecommitdiff
path: root/src/env.cff
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2022-08-13 20:53:39 +0200
committerlemon <lsof@mailbox.org>2022-08-13 20:53:39 +0200
commitddcca62a276c528a4390c8e3d58403b865f81869 (patch)
tree3d563e173a18095501f61f3b30e39cf62b4ff521 /src/env.cff
parenta4ddca68662f4bc0531763357b4bc00b6c50b456 (diff)
ok..
Diffstat (limited to 'src/env.cff')
-rw-r--r--src/env.cff28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/env.cff b/src/env.cff
new file mode 100644
index 0000000..8878238
--- /dev/null
+++ b/src/env.cff
@@ -0,0 +1,28 @@
+import "map.hff";
+import "all.hff";
+
+struct StringKeyTraits {
+ fn hash(s *const u8) u32 { return fnv1a_s(FNV1A_INI, s); }
+ fn eq(a *const u8, b *const u8) bool { return streq(a, b); }
+}
+
+struct Env {
+ parent *Env,
+ alloc *Allocator,
+ decls Map<*const u8, *DeclList, StringKeyTraits>,
+}
+
+extern fn mkenv(parent *Env, alloc *Allocator) *Env {
+ let env *Env = xmalloc(sizeof Env);
+ *env = { parent, alloc };
+ return env;
+}
+
+extern fn envput(env *Env, decl *const Decl) *Decl {
+ let l **DeclList = env.decls->get_slot(decl.name);
+ let n *DeclList = env.alloc->alloc(sizeof *DeclList);
+ n.link = *l;
+ n.decl = *decl;
+ *l = n;
+ return &n.decl;
+}