From: Jay Freeman (saurik) Date: Sun, 6 Jul 2008 20:57:29 +0000 (+0000) Subject: Added a bunch of new keywords to stdlib. X-Git-Url: https://git.saurik.com/minimal.git/commitdiff_plain/a5a4895492871e3b42f6c7224244b937c8be083a Added a bunch of new keywords to stdlib. --- diff --git a/stdlib.h b/stdlib.h index 0f24d7d..6c3c491 100644 --- a/stdlib.h +++ b/stdlib.h @@ -38,10 +38,26 @@ #ifndef MINIMAL_STDLIB_H #define MINIMAL_STDLIB_H +#ifdef __i386__ +#define _breakpoint() \ + __asm__ ("int $0x03") +#else +#define _breakpoint() +#endif + +#ifdef __cplusplus +#define _assert_(e) \ + throw e +#else +#define _assert_(e) \ + exit(1) +#endif + #define _assert(expr) \ do if (!(expr)) { \ fprintf(stderr, "%s(%u): _assert(%u:%s)\n", __FILE__, __LINE__, errno, #expr); \ - exit(1); \ + _breakpoint(); \ + _assert_(#expr); \ } while (false) #define _syscall(expr) \ @@ -63,12 +79,30 @@ #define _not(type) \ ((type) ~ (type) 0) -#define _breakpoint() \ - __asm__ { int 0x3 } - #define _disused \ __attribute__((unused)) +#define _label__(x) _label ## x +#define _label_(y) _label__(y) +#define _label _label_(__LINE__) + +#define _packed \ + __attribute__((packed)) + +#ifdef __cplusplus + +template +struct Iterator_ { + typedef typename Type_::const_iterator Result; +}; + +#define _foreach(item, list) \ + for (bool _stop(true); _stop; ) \ + for (const __typeof__(list) &_list = (list); _stop; _stop = false) \ + for (Iterator_<__typeof__(list)>::Result item = _list.begin(); item != _list.end(); ++item) + +#endif + #include #include #include