/* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ #include #include #include #include #include "../../include/vtype.h" #include "__attributes.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) #define abs(v) _Generic((v), ldbl_t: fabsl, dbl_t: fabs, fl_t: fabsf)(v) 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_dict dict_t; typedef vtype_hash hash_t; extern const size_t LIBCDSB_BUILTIN_VTYPE_SIZES[19]; extern int libcdsb_builtin_vtype_compare_values (const void* s0, vtype t0, const void* s1, vtype t1) pure__ wur__; extern int libcdsb_builtin_vtype_compare_values_eq(const void* s0, const void* s1, vtype t) pure__ wur__; extern hash_t libcdsb_builtin_vtype_hash (const void* value, vtype type) pure__ wur__; ainline(stack_t* libcdsb_builtin_stack_insert(stack_t* x, void* v)) { stack_t* p = x->prev; if (!is_null(x->prev = malloc(sizeof(*x)))) { x->prev->prev = p; x->prev->value = v; } else abort(); return x->prev; } #define aligned_alloc libcdsb_aalloc #define malloc libcdsb_malloc #define calloc libcdsb_calloc #define realloc libcdsb_realloc #define free libcdsb_free #define stack_init libcdsb_stack_init #define stack_push libcdsb_stack_push #define stack_push_many libcdsb_stack_push_many #define stack_insert libcdsb_builtin_stack_insert #define stack_pop libcdsb_stack_pop #define stack_reverse libcdsb_stack_reverse #define stack_flush libcdsb_stack_flush #define strlen libcdsb_strlen #define strasciilen libcdsb_strasciilen #define strdup libcdsb_strdup #define strndup libcdsb_strndup #define memndup libcdsb_memndup #define vtype_stringify libcdsb_vtype_stringify #define vtype_name libcdsb_vtype_name #define vtype_compare libcdsb_builtin_vtype_compare_values #define vtype_compare_eq libcdsb_builtin_vtype_compare_values_eq #define vtype_hash libcdsb_builtin_vtype_hash #define vtype_size(type) (LIBCDSB_BUILTIN_VTYPE_SIZES[type]) #endif /* LIBCDSB_SRC_INTERNAL_INCLUDE */