blob: aac733eff257f45d214f94b43be2818cc3cb5a3c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
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)];
}
|