2019-12-18 13:33:42 +03:00
|
|
|
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
2019-03-04 01:23:13 +03:00
|
|
|
#include <windows.h>
|
2019-11-21 00:26:59 +03:00
|
|
|
#include <BaseTsd.h>
|
|
|
|
typedef SSIZE_T ssize_t;
|
2019-03-04 01:23:13 +03:00
|
|
|
#endif
|
2019-10-03 01:23:27 +03:00
|
|
|
#ifndef _WIN32
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2017-06-26 12:15:03 +03:00
|
|
|
|
2019-10-30 10:47:36 +03:00
|
|
|
typedef char *String;
|
|
|
|
typedef char *Pattern;
|
2017-11-22 18:25:05 +03:00
|
|
|
|
2019-06-20 23:13:18 +03:00
|
|
|
#if defined NDEBUG
|
2019-10-30 10:47:36 +03:00
|
|
|
#define CHK_INDEX(i, n)
|
2019-06-20 23:13:18 +03:00
|
|
|
#else
|
2019-12-18 13:33:42 +03:00
|
|
|
|
|
|
|
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
|
|
|
// The %zd format flag doesn't seem to work on Windows?
|
|
|
|
#define CHK_INDEX_FORMAT_STRING ":%u: bad index: %ld < %ld\n"
|
|
|
|
#else
|
|
|
|
#define CHK_INDEX_FORMAT_STRING ":%u: bad index: %zd < %zd\n"
|
|
|
|
#endif
|
|
|
|
|
2019-10-30 10:47:36 +03:00
|
|
|
#define CHK_INDEX(i, n) \
|
|
|
|
do { \
|
|
|
|
size_t __si = (size_t)i; \
|
|
|
|
size_t __ni = (size_t)n; \
|
|
|
|
if (!(__si < __ni)) { \
|
2019-12-18 13:33:42 +03:00
|
|
|
printf(__FILE__ CHK_INDEX_FORMAT_STRING, __LINE__, \
|
2019-10-30 10:47:36 +03:00
|
|
|
(ssize_t)i, (ssize_t)n); \
|
|
|
|
abort(); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2019-06-20 23:13:18 +03:00
|
|
|
#endif
|
|
|
|
|
2017-10-13 13:48:18 +03:00
|
|
|
// Array
|
|
|
|
typedef struct {
|
2017-12-03 21:14:58 +03:00
|
|
|
size_t len;
|
2018-03-07 14:03:59 +03:00
|
|
|
size_t capacity;
|
2017-10-13 13:48:18 +03:00
|
|
|
void *data;
|
|
|
|
} Array;
|
|
|
|
|
2018-06-18 18:22:20 +03:00
|
|
|
// Lambdas
|
|
|
|
typedef struct {
|
|
|
|
void *callback;
|
|
|
|
void *env;
|
2018-08-29 16:10:41 +03:00
|
|
|
void *delete;
|
|
|
|
void *copy;
|
2018-06-18 18:22:20 +03:00
|
|
|
} Lambda;
|
|
|
|
|
2019-10-30 10:47:36 +03:00
|
|
|
typedef void *LambdaEnv;
|