summaryrefslogtreecommitdiff
path: root/src/util/typedef.h
diff options
context:
space:
mode:
authornavewindre <boneyaard@gmail.com>2025-09-03 20:10:09 +0200
committernavewindre <boneyaard@gmail.com>2025-09-03 20:10:09 +0200
commitf8b92ce3aa08b1445c9f956d8166830946562d12 (patch)
tree94e63a5aec9f8f52b577f56799e0c9201fd976a5 /src/util/typedef.h
a
Diffstat (limited to 'src/util/typedef.h')
-rw-r--r--src/util/typedef.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/util/typedef.h b/src/util/typedef.h
new file mode 100644
index 0000000..53c4010
--- /dev/null
+++ b/src/util/typedef.h
@@ -0,0 +1,58 @@
+#pragma once
+#ifdef DEBUG
+#include <stdio.h>
+#endif
+
+enum STAT {
+ STAT_OK,
+ STAT_ERR,
+ STAT_BREAK,
+ STAT_ALREADYEXISTS,
+};
+
+#define OK( x ) ( (STAT)( x ) == STAT_OK )
+
+typedef char I8;
+typedef short I16;
+typedef int I32;
+typedef long long I64;
+
+typedef unsigned char U8;
+typedef unsigned short U16;
+typedef unsigned int U32;
+typedef unsigned long long U64;
+
+typedef unsigned long ULONG;
+
+typedef float F32;
+typedef double F64;
+
+typedef unsigned long PTR;
+
+#define fn( ... ) [&]( __VA_ARGS__ )
+#define pfn( ... ) []( __VA_ARGS__ )
+
+template <typename T>
+struct __defer_t {
+ T f;
+ __defer_t( T f ) : f( f ) {};
+ ~__defer_t() { f(); }
+};
+
+template <typename T>
+__defer_t<T> __defer_func( T f ) {
+ return __defer_t<T>( f );
+}
+
+#define DEFER_1( x, y ) x##y
+#define DEFER_2( x, y ) DEFER_1( x, y )
+#define DEFER_3( x ) DEFER_2( x, __COUNTER__ )
+#define defer( code ) auto DEFER_3( _defer_ ) = __defer_func( fn() { code; } )
+
+#ifdef DEBUG
+#define dlog( ... ) (void)printf( __VA_ARGS__ )
+#define ddef( x ) x
+#else
+#define dlog( ... ) {}
+#define ddef( x )
+#endif