import "libc.hff"; /// Macros defmacro assert { (ex, s, ...args) [ (do if not (ex) { fprintf(stderr, "%s:%d: assertion failed: ", #FILE, #LINE); fprintf(stderr, s, args); fprintf(stderr, "\n"); abort(); } ) ] } defmacro foreach(x, i, a, ...body) [ { let $a = a; for let i = 0; i < $a.#len; ++i { let x = $a[i]; { body } } } ] defmacro streq(a,b) [ (strcmp(a,b) == 0) ] // Inline functions fn bswap32(x u32) u32 { return (x >> 24) | ((x >> 8) & 0x00FF00) | ((x << 8) & 0xFF0000) | (x << 24); } fn bswap64(x u64) u64 { return (as(u64)bswap32(x) << 32) | (bswap32(x >> 32)); } fn spanz(x *const u8) [#]const u8 { return x[0::strlen(x)]; }