Carp/core/core.h

67 lines
1.8 KiB
C
Raw Normal View History

2020-05-12 21:24:40 +03:00
#if defined _WIN32
#ifdef __TINYC__
// missing definitions for tcc-0.9.27-win32-bin.zip => 32bit TCC
#define CP_UTF8 65001
#define strtof strtod
#endif
2020-01-22 14:18:03 +03:00
#include <windows.h>
2020-05-12 21:24:40 +03:00
#if !defined __CYGWIN__ && !defined __MINGW32__
typedef intptr_t ssize_t;
#endif
2019-03-04 01:23:13 +03:00
#endif
#ifndef _WIN32
#include <unistd.h>
#endif
#include <inttypes.h>
2020-05-09 13:21:14 +03:00
#include <locale.h>
2017-06-26 12:15:03 +03:00
typedef char *String;
typedef char *Pattern;
typedef int64_t Long;
2020-05-11 17:10:35 +03:00
typedef uint32_t Char;
typedef char CChar;
typedef void *c_code;
2019-06-20 23:13:18 +03:00
#if defined NDEBUG
#define CHK_INDEX(i, n)
2019-06-20 23:13:18 +03:00
#else
2020-04-26 23:05:13 +03:00
#define CHK_INDEX_FORMAT_STRING ":%u: bad index: %zd < %zd\n"
2020-01-22 14:18:03 +03:00
#define CHK_INDEX(i, n) \
do { \
size_t __si = (size_t)i; \
size_t __ni = (size_t)n; \
if (!(__si < __ni)) { \
printf(__FILE__ CHK_INDEX_FORMAT_STRING, __LINE__, (ssize_t)i, \
(ssize_t)n); \
abort(); \
} \
} while (0)
2019-06-20 23:13:18 +03:00
#endif
#define UNHANDLED(file, line) \
do { \
printf("Unhandled case in 'match' expression at %s:%d\n", file, line); \
abort(); \
} while (0)
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;
// Lambdas
typedef struct {
void *callback;
void *env;
void *delete;
void *copy;
} Lambda;
typedef void *LambdaEnv;