diff --git a/src/__internal/include.h b/src/__internal/include.h index cd185c6..417c362 100644 --- a/src/__internal/include.h +++ b/src/__internal/include.h @@ -48,20 +48,21 @@ 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_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_variable var_t; typedef vtype_hash hash_t; extern const size_t LIBCDSB_BUILTIN_VTYPE_SIZES[19]; -extern int libcdsb_builtin_variable_compare(vtype_variable s0, vtype_variable s1) pure__ wur__; -extern hash_t libcdsb_builtin_variable_hash (vtype_variable value) pure__ wur__; +extern int libcdsb_builtin_variable_compare(var_t s0, var_t s1) pure__ wur__; +extern hash_t libcdsb_builtin_variable_hash (var_t value) pure__ wur__; ainline(stack_t* libcdsb_builtin_stack_insert(stack_t* x, void* v)) { stack_t* p = x->prev; diff --git a/src/__internal/vnode.h b/src/__internal/vnode.h index 8f8bb59..401711a 100644 --- a/src/__internal/vnode.h +++ b/src/__internal/vnode.h @@ -9,23 +9,15 @@ #define is_permissible(T) (sizeof(void*) >= sizeof(T) && _Alignof(void*) >= _Alignof(T)) -typedef union { - void* ptr; bool b; - str_t s; arr_t a; list_t l; - map_t m; set_t vs; dict_t vd; - u8_t u8; u16_t u16; u32_t u32; u64_t u64; - fl_t f; dbl_t d; ldbl_t ld; -} var_t; - typedef void* vnode_t; -extern vnode_t libcdsb_builtin_vnode_create ( vtype_variable) wur__; -extern vnode_t libcdsb_builtin_vnode_create_ex(vtype xt, vtype_variable) wur__; +extern vnode_t libcdsb_builtin_vnode_create ( var_t) wur__; +extern vnode_t libcdsb_builtin_vnode_create_ex(vtype xt, var_t) wur__; -extern vtype_variable libcdsb_builtin_vnode_peek(const vnode_t* x, vtype type) pure__ wur__ Nonnull__(1); -extern void libcdsb_builtin_vnode_free( vnode_t* x, vtype type) Nonnull__(1); +extern var_t libcdsb_builtin_vnode_peek(const vnode_t* x, vtype type) pure__ wur__ Nonnull__(1); +extern void libcdsb_builtin_vnode_free( vnode_t* x, vtype type) Nonnull__(1); -ainline(void libcdsb_builtin_vnode_attach(vnode_t* node, vtype_variable value)) { +ainline(void libcdsb_builtin_vnode_attach(vnode_t* node, var_t value)) { if (value.type < VTYPE_STRING) { *node = libcdsb_builtin_vnode_create(value); } else if (sizeof(str_t) == sizeof(void*) && value.type == VTYPE_STRING) { @@ -36,7 +28,7 @@ ainline(void libcdsb_builtin_vnode_attach(vnode_t* node, vtype_variable value)) } } -ainline(void libcdsb_builtin_vnode_attach_ex(vnode_t* node, vtype target, vtype_variable value)) { +ainline(void libcdsb_builtin_vnode_attach_ex(vnode_t* node, vtype target, var_t value)) { if (value.type < VTYPE_STRING) { *node = libcdsb_builtin_vnode_create_ex(target, value); } else { diff --git a/src/array/access.c b/src/array/access.c index 2f34201..3976b47 100644 --- a/src/array/access.c +++ b/src/array/access.c @@ -23,7 +23,7 @@ int libcdsb_array_get(vtype_array* x, ssize_t i, void* _, array_access_callback return r; } -int libcdsb_array_find(arr_t* x, vtype_variable var, void* _, array_access_callback callback, bool r, bool cut) { +int libcdsb_array_find(arr_t* x, var_t var, void* _, array_access_callback callback, bool r, bool cut) { void *p; ssize_t i; int cmp; diff --git a/src/array/compute.c b/src/array/compute.c index 2b2c215..a6daeb2 100644 --- a/src/array/compute.c +++ b/src/array/compute.c @@ -24,7 +24,7 @@ hash_t array_hash(const arr_t* s) { } -size_t libcdsb_array_count(const arr_t* s, vtype_variable var) { +size_t libcdsb_array_count(const arr_t* s, var_t var) { void *p; void *e; int cmp; diff --git a/src/array/modify.c b/src/array/modify.c index 96eaba4..550a9bf 100644 --- a/src/array/modify.c +++ b/src/array/modify.c @@ -5,7 +5,7 @@ #include "../__internal/assert.h" #include "../__internal/vnode.h" -ssize_t libcdsb_array_insert(arr_t* x, vtype_variable var) { +ssize_t libcdsb_array_insert(arr_t* x, var_t var) { ssize_t i; vnode_t n; @@ -29,7 +29,7 @@ ssize_t libcdsb_array_insert(arr_t* x, vtype_variable var) { } -ssize_t libcdsb_array_attach(arr_t* x, vtype_variable var) { +ssize_t libcdsb_array_attach(arr_t* x, var_t var) { ssize_t i; vnode_t n; diff --git a/src/dict/access.c b/src/dict/access.c index 81d2187..31ab0ef 100644 --- a/src/dict/access.c +++ b/src/dict/access.c @@ -3,10 +3,10 @@ #include "include.h" -int libcdsb_dict_find(dict_t* x, vtype_variable kvar, void* dt, dict_access_callback callback, bool cut) { - dnode_t *c, **p; - int r; - vtype_variable k, v; +int libcdsb_dict_find(dict_t* x, var_t kvar, void* dt, dict_access_callback callback, bool cut) { + dnode_t *c, **p; + int r; + var_t k, v; if (x->capacity) { c = *(p = x->nodes + (variable_hash(kvar) % x->capacity)); @@ -39,7 +39,7 @@ int libcdsb_dict_foreach(dict_t* x, void* dt, dict_access_callback callback, boo dnode_t *c; ssize_t i; int r; - vtype_variable k, v; + var_t k, v; r = 0; i = x->capacity; diff --git a/src/dict/modify.c b/src/dict/modify.c index 3febcf4..48be73f 100644 --- a/src/dict/modify.c +++ b/src/dict/modify.c @@ -50,9 +50,9 @@ bool libcdsb_dict_shrink_to_fit(dict_t* s) { } -bool libcdsb_dict_update(dict_t* x, vtype_variable key, vtype_variable value, void* dt, dict_access_callback callback) { - dnode_t *c, **p; - vtype_variable k; +bool libcdsb_dict_update(dict_t* x, var_t key, var_t value, void* dt, dict_access_callback callback) { + dnode_t *c, **p; + var_t k; if (!x->capacity || (double)x->size / x->capacity > REBUILD_POINT_MAX) libcdsb_builtin_rehash(x, x->capacity + CAPACITY_BLOCK); @@ -89,9 +89,9 @@ bool libcdsb_dict_update(dict_t* x, vtype_variable key, vtype_variable value, vo } -bool libcdsb_dict_inject(dict_t* x, vtype_variable key, vtype_variable value, void* dt, dict_access_callback callback) { - dnode_t *c, **p; - vtype_variable k; +bool libcdsb_dict_inject(dict_t* x, var_t key, var_t value, void* dt, dict_access_callback callback) { + dnode_t *c, **p; + var_t k; if (!x->capacity || (double)x->size / x->capacity > REBUILD_POINT_MAX) libcdsb_builtin_rehash(x, x->capacity + CAPACITY_BLOCK); diff --git a/src/list/access.c b/src/list/access.c index dcca0a9..6337a53 100644 --- a/src/list/access.c +++ b/src/list/access.c @@ -50,12 +50,12 @@ int libcdsb_list_get(vtype_list* x, ssize_t i, void* _, list_access_callback cal } -int libcdsb_list_find(vtype_list* x, vtype_variable value, void* _, list_access_callback callback, bool r, bool cut) { +int libcdsb_list_find(vtype_list* x, var_t value, void* _, list_access_callback callback, bool r, bool cut) { ldir_t dir; lnode_t* c; ssize_t i; int cmp; - vtype_variable v; + var_t v; dir = r ? LD_PREV : LD_NEXT; c = ldir_dir((lnode_t*)x, dir); diff --git a/src/list/compute.c b/src/list/compute.c index f408798..0aae992 100644 --- a/src/list/compute.c +++ b/src/list/compute.c @@ -36,7 +36,7 @@ hash_t list_hash(const list_t* s) { } -size_t libcdsb_list_count(const list_t* s, vtype_variable value) { +size_t libcdsb_list_count(const list_t* s, var_t value) { lnode_t* c; size_t n; int cmp; diff --git a/src/list/modify.c b/src/list/modify.c index 12b81f3..16f7fbd 100644 --- a/src/list/modify.c +++ b/src/list/modify.c @@ -3,7 +3,7 @@ #include "include.h" -bool libcdsb_list_insert(list_t* x, ssize_t i, vtype_variable value, int ins, void* dt, list_access_callback callback) { +bool libcdsb_list_insert(list_t* x, ssize_t i, var_t value, int ins, void* dt, list_access_callback callback) { ldir_t dir; lnode_t* c; @@ -52,7 +52,7 @@ bool libcdsb_list_insert(list_t* x, ssize_t i, vtype_variable value, int ins, vo } -bool libcdsb_list_attach(list_t* x, ssize_t i, vtype_variable value, int ins, void* dt, list_access_callback callback) { +bool libcdsb_list_attach(list_t* x, ssize_t i, var_t value, int ins, void* dt, list_access_callback callback) { ldir_t dir; lnode_t* c; diff --git a/src/map/access.c b/src/map/access.c index 6c51ab5..8bd4f85 100644 --- a/src/map/access.c +++ b/src/map/access.c @@ -45,10 +45,10 @@ static int libcdsb_builtin_foreach(map_t* x, void* data, map_access_callback cal /*#####################################################################################################################*/ -int libcdsb_map_find(map_t* x, vtype_variable key, void* _, map_access_callback callback, bool cut) { +int libcdsb_map_find(map_t* x, var_t key, void* _, map_access_callback callback, bool cut) { mnode_t* c; int cmp; - vtype_variable k; + var_t k; c = x->root; diff --git a/src/set/access.c b/src/set/access.c index 16c9dd2..ed7b41b 100644 --- a/src/set/access.c +++ b/src/set/access.c @@ -46,10 +46,10 @@ static int libcdsb_builtin_foreach(set_t* x, void* data, vset_access_callback ca /*#####################################################################################################################*/ -int libcdsb_vset_find(vtype_set* x, vtype_variable value, void* _, vset_access_callback callback, bool cut) { +int libcdsb_vset_find(vtype_set* x, var_t value, void* _, vset_access_callback callback, bool cut) { rbnode_t* c; int cmp; - vtype_variable v; + var_t v; c = x->root; diff --git a/src/stringify.c b/src/stringify.c index a1e3adb..0149113 100644 --- a/src/stringify.c +++ b/src/stringify.c @@ -62,7 +62,7 @@ const char* libcdsb_vtype_name(vtype t) { } -const char* libcdsb_variable_stringify(vtype_variable value) { +const char* libcdsb_variable_stringify(var_t value) { if (is_null(value.pointer) || (value.type == VTYPE_POINTER && is_null(*(void**)value.pointer))) return "null"; if (value.type == VTYPE_BOOLEAN) return (*(vtype_bool*)value.pointer) ? "true" : "false"; if (value.type == VTYPE_STRING) return *(char**)value.pointer; diff --git a/src/vnode.c b/src/vnode.c index 2aca342..6cd2768 100644 --- a/src/vnode.c +++ b/src/vnode.c @@ -5,6 +5,14 @@ #include "__internal/vnode.h" #include "../include/string.h" +typedef union { + void* ptr; bool b; + str_t s; arr_t a; list_t l; + map_t m; set_t vs; dict_t vd; + u8_t u8; u16_t u16; u32_t u32; u64_t u64; + fl_t f; dbl_t d; ldbl_t ld; +} any_t; + static vtype libcdsb_builtin_round(u64_t* x, ldbl_t v) { if (v > 0) { *x = (u64_t)(v + 0.5); @@ -16,7 +24,7 @@ static vtype libcdsb_builtin_round(u64_t* x, ldbl_t v) { } static vnode_t libcdsb_builtin_create_value(vtype xt, const void* v, vtype t) { - var_t _; + any_t _; if (t == VTYPE_FLOAT) { t = libcdsb_builtin_round(&_.u64, *(fl_t*)v); @@ -82,7 +90,7 @@ static vnode_t libcdsb_builtin_create_value(vtype xt, const void* v, vtype t) { } static vnode_t libcdsb_builtin_create_float(vtype xt, const void* v, vtype t) { - var_t _; + any_t _; if (t == VTYPE_UINT8 || t == VTYPE_BOOLEAN ) { _.ld = *(u8_t*)v; @@ -129,8 +137,8 @@ static vnode_t libcdsb_builtin_create_float(vtype xt, const void* v, vtype t) { /*#####################################################################################################################*/ -vnode_t libcdsb_builtin_vnode_create(vtype_variable var) { - var_t _ = { .ptr = 0 }; +vnode_t libcdsb_builtin_vnode_create(var_t var) { + any_t _ = { .ptr = 0 }; switch (var.type) { default: abort(); @@ -191,8 +199,8 @@ vnode_t libcdsb_builtin_vnode_create(vtype_variable var) { return _.ptr; } -vnode_t libcdsb_builtin_vnode_create_ex(vtype xt, vtype_variable var) { - var_t _ = { .ptr = 0 }; +vnode_t libcdsb_builtin_vnode_create_ex(vtype xt, var_t var) { + any_t _ = { .ptr = 0 }; if (xt <= VTYPE_LDOUBLE) { if (var.type >= VTYPE_STRING) var.type = VTYPE_POINTER; @@ -231,8 +239,8 @@ vnode_t libcdsb_builtin_vnode_create_ex(vtype xt, vtype_variable var) { return _.ptr; } -vtype_variable libcdsb_builtin_vnode_peek(const vnode_t* x, vtype t) { - vtype_variable var = { .type = t }; +var_t libcdsb_builtin_vnode_peek(const vnode_t* x, vtype t) { + var_t var = { .type = t }; switch (var.type) { default: abort(); diff --git a/src/vtype.c b/src/vtype.c index aff7252..bac6aae 100644 --- a/src/vtype.c +++ b/src/vtype.c @@ -99,7 +99,7 @@ static int libcdsb_builtin_vtype_compare_values_eq(const void* s0, const void* s /*#####################################################################################################################*/ -int libcdsb_builtin_variable_compare(vtype_variable s0, vtype_variable s1) { +int libcdsb_builtin_variable_compare(var_t s0, var_t s1) { if (s0.type == s1.type) return libcdsb_builtin_vtype_compare_values_eq(s0.pointer, s1.pointer, s0.type); if (s0.type <= VTYPE_LDOUBLE && s0.type <= VTYPE_LDOUBLE) { @@ -116,7 +116,7 @@ int libcdsb_builtin_variable_compare(vtype_variable s0, vtype_variable s1) { /*#####################################################################################################################*/ -hash_t libcdsb_builtin_variable_hash(vtype_variable value) { +hash_t libcdsb_builtin_variable_hash(var_t value) { switch (value.type) { default: abort(); case VTYPE_BOOLEAN: