Carp/core/core.h

54 lines
962 B
C
Raw Normal View History

2017-06-26 12:15:03 +03:00
#ifndef PRELUDE_H
#define PRELUDE_H
#include <assert.h>
#include <stddef.h>
2019-06-20 23:13:18 +03:00
#include "carp_stdbool.h"
2019-03-04 01:23:13 +03:00
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
#include <windows.h>
#endif
2017-06-26 12:15:03 +03:00
2018-03-18 16:53:03 +03:00
typedef char* String;
typedef char* Pattern;
2019-06-20 23:13:18 +03:00
#if defined NDEBUG
#define CHK_INDEX(i,n)
#else
#define CHK_INDEX(i,n) \
do { \
size_t __si = (size_t)i; \
size_t __ni = (size_t)n; \
if (!(__si < __ni)) { \
printf(__FILE__ ":%u: bad index: %zd < %zd\n", \
__LINE__, (ssize_t)i, (ssize_t)n); \
abort(); \
} \
}while (0)
#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;
// Lambdas
typedef struct {
void *callback;
void *env;
void *delete;
void *copy;
} Lambda;
2018-06-19 10:19:54 +03:00
typedef void* LambdaEnv;
2017-06-26 12:15:03 +03:00
bool not(bool b) {
return !b;
}
2017-10-24 15:13:45 +03:00
bool and(bool x, bool y) { return x && y; }
bool or(bool x, bool y) { return x || y; }
2017-06-26 12:15:03 +03:00
#endif