libcdsb/src/__internal/include.h

105 lines
3.9 KiB
C

/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include <stddef.h>
#include <stdlib.h>
#include "../../include/vtype.h"
#include "../../include/extra/memory.h"
#include "../../include/extra/cstring.h"
#include "../../include/extra/vtype.h"
#ifndef LIBCDSB_SRC_INTERNAL_INCLUDE
#define LIBCDSB_SRC_INTERNAL_INCLUDE
#define is_x64 (sizeof(void*) == sizeof(vtype_uint64))
#define is_big_endian (*((unsigned int*)"\0\0\0\1") < (unsigned int)0xffff)
#define is_little_endian (!is_big_endian)
#define is_null(x) (((void*)(x)) == nullptr)
#ifdef true
# undef true
#endif
#ifdef false
# undef false
#endif
#ifndef nullptr
# define nullptr ((void*)0)
#endif
#define true ((_Bool)1)
#define false ((_Bool)0)
#include "__attributes.h"
typedef vtype_uint8 u8_t;
typedef vtype_uint16 u16_t;
typedef vtype_uint32 u32_t;
typedef vtype_uint64 u64_t;
typedef vtype_int8 s8_t;
typedef vtype_int16 s16_t;
typedef vtype_int32 s32_t;
typedef vtype_int64 s64_t;
typedef vtype_float fl_t;
typedef vtype_double dbl_t;
typedef vtype_ldouble ldbl_t;
typedef vtype_string str_t;
typedef vtype_array arr_t;
typedef vtype_list list_t;
typedef vtype_map map_t;
typedef vtype_set set_t;
typedef vtype_value val_t;
typedef vtype_kvpair kvp_t;
typedef vtype_iterator iter_t;
typedef enum {
VF_UNDEFINED = 0x00,
VF_WRITEABLE = 0x01,
VF_CHANGEABLE = 0x02,
VF_REMOVABLE = 0x0f
} vtype_value_flags;
ainline(val_t* value_set(val_t* d, void* ptr, vtype type, int flags)) {
d->mem = ptr;
d->type = type;
d->flags = flags;
return d;
}
extern int libcdsb_vtype_compare_values(const void* s0, vtype t0, const void* s1, vtype t1);
extern int libcdsb_vtype_compare_values_eq(const void* s0, const void* s1, vtype t);
#define vtype_compare libcdsb_vtype_compare_values
#define vtype_compare_eq libcdsb_vtype_compare_values_eq
#define vtype_size(type) (LIBCDSB_VTYPE_SIZES[type])
#define vtypeof(x) (vtype)(_Generic((x),\
const void**: VTYPE_POINTER, void**: VTYPE_POINTER, const void*: VTYPE_POINTER, void*: VTYPE_POINTER,\
const char**: VTYPE_STRING, char**: VTYPE_STRING, const char*: VTYPE_STRING, char*: VTYPE_STRING,\
const str_t*: VTYPE_STRING, str_t*: VTYPE_STRING, str_t: VTYPE_STRING,\
const arr_t*: VTYPE_ARRAY, arr_t*: VTYPE_ARRAY, arr_t: VTYPE_ARRAY,\
const list_t*: VTYPE_LIST, list_t*: VTYPE_LIST, list_t: VTYPE_LIST,\
const map_t*: VTYPE_MAP, map_t*: VTYPE_MAP, map_t: VTYPE_MAP,\
const set_t*: VTYPE_SET, set_t*: VTYPE_SET, set_t: VTYPE_SET,\
const vtype_bool*: VTYPE_BOOLEAN, vtype_bool*: VTYPE_BOOLEAN, vtype_bool: VTYPE_BOOLEAN,\
const vtype_uint8*: VTYPE_UINT8, vtype_uint8*: VTYPE_UINT8, vtype_uint8: VTYPE_UINT8,\
const vtype_uint16*: VTYPE_UINT16, vtype_uint16*: VTYPE_UINT16, vtype_uint16: VTYPE_UINT16,\
const vtype_uint32*: VTYPE_UINT32, vtype_uint32*: VTYPE_UINT32, vtype_uint32: VTYPE_UINT32,\
const vtype_uint64*: VTYPE_UINT64, vtype_uint64*: VTYPE_UINT64, vtype_uint64: VTYPE_UINT64,\
const vtype_int8*: VTYPE_INT8, vtype_int8*: VTYPE_INT8, vtype_int8: VTYPE_INT8,\
const vtype_int16*: VTYPE_INT16, vtype_int16*: VTYPE_INT16, vtype_int16: VTYPE_INT16,\
const vtype_int32*: VTYPE_INT32, vtype_int32*: VTYPE_INT32, vtype_int32: VTYPE_INT32,\
const vtype_int64*: VTYPE_INT64, vtype_int64*: VTYPE_INT64, vtype_int64: VTYPE_INT64,\
const vtype_float*: VTYPE_FLOAT, vtype_float*: VTYPE_FLOAT, vtype_float: VTYPE_FLOAT,\
const vtype_double*: VTYPE_DOUBLE, vtype_double*: VTYPE_DOUBLE, vtype_double: VTYPE_DOUBLE,\
const vtype_ldouble*: VTYPE_LDOUBLE, vtype_ldouble*: VTYPE_LDOUBLE, vtype_ldouble: VTYPE_LDOUBLE))
#endif /* LIBCDSB_SRC_INTERNAL_INCLUDE */