huh/src/base.c
2026-02-18 23:34:54 -07:00

45 lines
1.1 KiB
C

#include <stdint.h>
#include <stddef.h>
#include <Block.h>
#define capture __block
#define closure Block_copy
typedef void (^__defer_block_t)(void);
static inline void __defer_exec(__defer_block_t *blk) { (*blk)(); }
#define __concat__2(a, b) a##b
#define __concat(a, b) __concat__2(a, b)
#define scope_exit \
__attribute__((cleanup(__defer_exec), unused)) \
__defer_block_t __concat(_defer_, __LINE__) = ^
#define auto __auto_type
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;
typedef float f32;
typedef double f64;
typedef uintptr_t uptr;
typedef intptr_t sptr;
typedef uptr ureg;
typedef sptr sreg;
// Thanks AZMR
#define cast(to_type, expr) ((to_type)(expr))
#define chkcast(to_type, from_type, expr) _Generic(expr, from_type: (to_type)(expr))
#define ptrcast(to_type, from_type, expr) _Generic(expr, from_type: (to_type)(uintptr_t)(expr))
#define bitcast(to_type, from_type, expr) (((union { from_type from; to_type to; }){_Generic(expr, from_type: expr)}).to)