aboutsummaryrefslogtreecommitdiff
path: root/util.h
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-02-04 15:23:59 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-02-04 15:23:59 -0500
commit98f0c51119f9d42d733f44cb516b1c2bcd9061af (patch)
tree39ab4fa635f858b76b9a8bbf84701c2788d5f498 /util.h
Initial commit
Diffstat (limited to 'util.h')
-rw-r--r--util.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/util.h b/util.h
new file mode 100644
index 00000000..416c0b3e
--- /dev/null
+++ b/util.h
@@ -0,0 +1,29 @@
+#pragma once
+
+#include <assert.h>
+#include <gc.h>
+#include <gc/cord.h>
+#include <stdio.h>
+#include <string.h>
+#include <err.h>
+
+#define streq(a, b) (((a) == NULL && (b) == NULL) || (((a) == NULL) == ((b) == NULL) && strcmp(a, b) == 0))
+#define new(t, ...) ((t*)memcpy(GC_MALLOC(sizeof(t)), &(t){__VA_ARGS__}, sizeof(t)))
+#define grow(arr, new_size) ((typeof (arr))GC_REALLOC(arr, (sizeof(arr[0]))*(new_size)))
+#define Match(x, _tag) ((x)->tag == _tag ? &(x)->__data._tag : (errx(1, __FILE__ ":%d This was supposed to be a " # _tag "\n", __LINE__), &(x)->__data._tag))
+#define Tagged(t, _tag, ...) new(t, .tag=_tag, .__data._tag={__VA_ARGS__})
+
+#ifndef auto
+#define auto __auto_type
+#endif
+
+#ifndef public
+#define public __attribute__ ((visibility ("default")))
+#endif
+
+char *heap_strn(const char *str, size_t len);
+char *heap_str(const char *str);
+char *heap_strf(const char *fmt, ...);
+CORD CORD_asprintf(const char *fmt, ...);
+
+// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0