diff options
| author | 2022-08-18 17:39:25 +0200 | |
|---|---|---|
| committer | 2022-08-18 17:39:25 +0200 | |
| commit | 9c485da5e1d955031fa2a3654bfc2ef814898167 (patch) | |
| tree | 44e841ced0479d5ec82cca28733413784eedf52c /src/common.hff | |
| parent | f0214ff61b5a94b9629db6f43d7a5b010bd4ffbc (diff) | |
lots of goodnes
Diffstat (limited to 'src/common.hff')
| -rw-r--r-- | src/common.hff | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/common.hff b/src/common.hff index 4da1398..6643dda 100644 --- a/src/common.hff +++ b/src/common.hff @@ -25,6 +25,16 @@ defmacro foreach(x, i, a, &body) [ } ] +defmacro foreach_ptr(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) ] defmacro strcieq(a,b) [ (strcasecmp(a,b) == 0) ] @@ -42,6 +52,13 @@ defmacro with_tmpchange(var,x,&body) [ defmacro MAX(a,b) [((a) > (b) ? (a) : (b))] +defmacro offsetof_(T, fld) [ + (as(isize)(&(as(*T)#null).fld)) +] +defmacro container_of(x, T, fld) [ + (as(*T)(as(*void)(x) - offsetof_(T, fld))) +] + // Inline functions fn bswap32(x u32) u32 { return (x >> 24) |