Files
libcdsb/src/__internal/include.h
T

104 lines
3.0 KiB
C
Raw Normal View History

2022-06-02 14:20:55 +03:00
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
2022-06-05 18:32:57 +03:00
#include <float.h>
#include <math.h>
2022-06-02 14:20:55 +03:00
#include <stddef.h>
#include <stdlib.h>
#include "../../include/vtype.h"
2022-08-22 11:56:16 +03:00
#include "__attributes.h"
2022-06-02 14:20:55 +03:00
#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
2022-06-09 16:29:10 +03:00
#define true ((bool)1)
#define false ((bool)0)
2022-06-02 14:20:55 +03:00
2022-06-05 18:32:57 +03:00
#define abs(v) _Generic((v), ldbl_t: fabsl, dbl_t: fabs, fl_t: fabsf)(v)
2022-06-08 21:01:12 +03:00
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;
2022-08-14 18:18:34 +03:00
typedef vtype_dict dict_t;
typedef vtype_hash hash_t;
2022-06-08 21:01:12 +03:00
2022-06-02 14:20:55 +03:00
2022-08-22 14:18:38 +03:00
extern const size_t LIBCDSB_BUILTIN_VTYPE_SIZES[19];
2022-08-14 18:18:34 +03:00
2022-08-22 14:18:38 +03:00
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__;
2022-08-14 18:18:34 +03:00
2022-08-24 12:28:45 +03:00
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;
}
2022-08-22 11:56:16 +03:00
#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
2022-08-24 12:28:45 +03:00
#define stack_insert libcdsb_builtin_stack_insert
2022-08-22 11:56:16 +03:00
#define stack_pop libcdsb_stack_pop
2022-08-24 12:28:45 +03:00
#define stack_reverse libcdsb_stack_reverse
2022-08-22 11:56:16 +03:00
#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
2022-08-22 14:18:38 +03:00
#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])
2022-06-02 14:20:55 +03:00
#endif /* LIBCDSB_SRC_INTERNAL_INCLUDE */