aboutsummaryrefslogtreecommitdiff
path: root/src/tables.c
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-07-06 03:33:04 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-07-06 03:49:03 +0200
commitd3c95ef09fd493241273d6e63aca31d703c2503c (patch)
tree94dc719ed4eb4a3bc67c35b19bca69916b56fc32 /src/tables.c
parentb0b7d209fa978ff4a6b9c8cc5a8e4a3207cdd63f (diff)
Implement booleans
Diffstat (limited to 'src/tables.c')
-rw-r--r--src/tables.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/tables.c b/src/tables.c
new file mode 100644
index 0000000..61adff7
--- /dev/null
+++ b/src/tables.c
@@ -0,0 +1,48 @@
+#include <stddef.h>
+#include <stdint.h>
+
+#include "alloc.h"
+#include "strview.h"
+#include "tables.h"
+
+struct symtab {
+ symtab_t *child[4];
+ strview_t key;
+ symval_t val;
+};
+
+struct typetab {
+ typetab_t *child[4];
+ strview_t key;
+ type_t *val;
+};
+
+symval_t *
+symtab_insert(symtab_t **m, strview_t sv, arena_t *a)
+{
+ for (uint64_t h = strview_hash(sv); *m; h <<= 2) {
+ if (strview_eq(sv, (*m)->key))
+ return &(*m)->val;
+ m = &(*m)->child[h >> 62];
+ }
+ if (a == NULL)
+ return NULL;
+ *m = arena_new(a, symtab_t, 1);
+ (*m)->key = sv;
+ return &(*m)->val;
+}
+
+type_t **
+typetab_insert(typetab_t **m, strview_t sv, arena_t *a)
+{
+ for (uint64_t h = strview_hash(sv); *m; h <<= 2) {
+ if (strview_eq(sv, (*m)->key))
+ return &(*m)->val;
+ m = &(*m)->child[h >> 62];
+ }
+ if (a == NULL)
+ return NULL;
+ *m = arena_new(a, typetab_t, 1);
+ (*m)->key = sv;
+ return &(*m)->val;
+}