From 0751ef469f7b3e27884e66b128ba318eaae8e960 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Sat, 9 Aug 2025 19:57:42 +0100 Subject: [PATCH] meta: rename legacy object module to 'ds' --- CMakeLists.txt | 2 +- cmake/FindBluelib.cmake | 34 ++++---- cmd/CMakeLists.txt | 2 +- cmd/arg.c | 2 +- cmd/arglist.c | 2 +- cmd/command.c | 2 +- cmd/include/blue/cmd.h | 2 +- cmd/option.c | 2 +- cmd/report.c | 2 +- {object-test => ds-test}/arrays.c | 4 +- .../object-units.c => ds-test/ds-units.c | 2 +- {object-test => ds-test}/numbers.c | 2 +- {object-test => ds-test}/streams.c | 2 +- {object-test => ds-test}/strings.c | 2 +- {object-test => ds-test}/trees.c | 6 +- {object-test => ds-test}/uuids.c | 2 +- ds/CMakeLists.txt | 3 + {object => ds}/array.c | 70 ++++++++-------- {object => ds}/array.h | 4 +- {object => ds}/bitbuffer.c | 0 {object => ds}/bitbuffer.h | 0 {object => ds}/bitmap.c | 2 +- {object => ds}/buffer.c | 20 ++--- {object => ds}/buffer.h | 2 +- {object => ds}/dict.c | 36 ++++---- {object => ds}/dict.h | 4 +- {object => ds}/hashmap.c | 22 ++--- {object => ds}/hashmap.h | 4 +- .../blue/object.h => ds/include/blue/ds.h | 0 .../object => ds/include/blue/ds}/array.h | 34 ++++---- .../object => ds/include/blue/ds}/bitbuffer.h | 6 +- .../object => ds/include/blue/ds}/bitmap.h | 0 .../object => ds/include/blue/ds}/buffer.h | 8 +- .../blue/object => ds/include/blue/ds}/dict.h | 18 ++-- .../object => ds/include/blue/ds}/hashmap.h | 8 +- .../blue/object => ds/include/blue/ds}/list.h | 6 +- .../object => ds/include/blue/ds}/number.h | 8 +- ds/include/blue/ds/object.h | 40 +++++++++ .../object => ds/include/blue/ds}/string.h | 8 +- .../blue/object => ds/include/blue/ds}/tree.h | 6 +- ds/include/blue/ds/type.h | 53 ++++++++++++ .../blue/object => ds/include/blue/ds}/uuid.h | 8 +- {object => ds}/list.c | 14 ++-- {object => ds}/list.h | 2 +- {object => ds}/number.c | 18 ++-- {object => ds}/number.h | 4 +- {object => ds}/object.c | 22 ++--- ds/object.h | 6 ++ {object => ds}/string.c | 24 +++--- {object => ds}/string.h | 2 +- {object => ds}/tree.c | 18 ++-- {object => ds}/tree.h | 4 +- {object => ds}/type.c | 8 +- {object => ds}/uuid.c | 18 ++-- {object => ds}/uuid.h | 4 +- io-test/io-units.c | 6 +- io/CMakeLists.txt | 2 +- io/include/blue/io/directory.h | 4 +- io/include/blue/io/file.h | 6 +- io/include/blue/io/path.h | 6 +- io/sys/darwin/directory.c | 16 ++-- io/sys/darwin/file.c | 16 ++-- io/sys/darwin/path.c | 20 ++--- io/sys/windows/directory.c | 14 ++-- io/sys/windows/path.c | 20 ++--- object/CMakeLists.txt | 3 - object/include/blue/object/object.h | 40 --------- object/include/blue/object/type.h | 53 ------------ object/object.h | 6 -- serial-test/streams.c | 12 +-- serial/CMakeLists.txt | 2 +- serial/include/blue/serial.h | 6 +- serial/json.c | 84 +++++++++---------- serial/serial.c | 4 +- serial/serial.h | 4 +- term-test/printing.c | 2 +- term/CMakeLists.txt | 2 +- term/paragraph.c | 2 +- test/cat.c | 2 +- test/json-read.c | 4 +- 80 files changed, 460 insertions(+), 460 deletions(-) rename {object-test => ds-test}/arrays.c (83%) rename object-test/object-units.c => ds-test/ds-units.c (97%) rename {object-test => ds-test}/numbers.c (84%) rename {object-test => ds-test}/streams.c (93%) rename {object-test => ds-test}/strings.c (96%) rename {object-test => ds-test}/trees.c (96%) rename {object-test => ds-test}/uuids.c (88%) create mode 100644 ds/CMakeLists.txt rename {object => ds}/array.c (75%) rename {object => ds}/array.h (82%) rename {object => ds}/bitbuffer.c (100%) rename {object => ds}/bitbuffer.h (100%) rename {object => ds}/bitmap.c (99%) rename {object => ds}/buffer.c (93%) rename {object => ds}/buffer.h (92%) rename {object => ds}/dict.c (91%) rename {object => ds}/dict.h (86%) rename {object => ds}/hashmap.c (95%) rename {object => ds}/hashmap.h (89%) rename object/include/blue/object.h => ds/include/blue/ds.h (100%) rename {object/include/blue/object => ds/include/blue/ds}/array.h (92%) rename {object/include/blue/object => ds/include/blue/ds}/bitbuffer.h (88%) rename {object/include/blue/object => ds/include/blue/ds}/bitmap.h (100%) rename {object/include/blue/object => ds/include/blue/ds}/buffer.h (92%) rename {object/include/blue/object => ds/include/blue/ds}/dict.h (82%) rename {object/include/blue/object => ds/include/blue/ds}/hashmap.h (95%) rename {object/include/blue/object => ds/include/blue/ds}/list.h (95%) rename {object/include/blue/object => ds/include/blue/ds}/number.h (97%) create mode 100644 ds/include/blue/ds/object.h rename {object/include/blue/object => ds/include/blue/ds}/string.h (95%) rename {object/include/blue/object => ds/include/blue/ds}/tree.h (95%) create mode 100644 ds/include/blue/ds/type.h rename {object/include/blue/object => ds/include/blue/ds}/uuid.h (92%) rename {object => ds}/list.c (95%) rename {object => ds}/list.h (90%) rename {object => ds}/number.c (99%) rename {object => ds}/number.h (87%) rename {object => ds}/object.c (56%) create mode 100644 ds/object.h rename {object => ds}/string.c (95%) rename {object => ds}/string.h (95%) rename {object => ds}/tree.c (94%) rename {object => ds}/tree.h (73%) rename {object => ds}/type.c (56%) rename {object => ds}/uuid.c (92%) rename {object => ds}/uuid.h (67%) delete mode 100644 object/CMakeLists.txt delete mode 100644 object/include/blue/object/object.h delete mode 100644 object/include/blue/object/type.h delete mode 100644 object/object.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e5a402f..3964bc3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ set(CMAKE_C_EXTENSIONS OFF) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake) set_property(GLOBAL PROPERTY USE_FOLDERS ON) -set(b_modules core object serial term cmd io compress) +set(b_modules core ds serial term cmd io compress) set(b_system_name ${CMAKE_SYSTEM_NAME}) string(TOLOWER ${b_system_name} b_system_name) diff --git a/cmake/FindBluelib.cmake b/cmake/FindBluelib.cmake index 27c75ee..648ceaa 100644 --- a/cmake/FindBluelib.cmake +++ b/cmake/FindBluelib.cmake @@ -49,7 +49,7 @@ if (Bluelib_STATIC) set(_lib_suffix "-s") endif () -set(supported_components Core Object Term Cmd Io Serial Compress) +set(supported_components Core Ds Term Cmd Io Serial Compress) set(components ${Bluelib_FIND_COMPONENTS}) string(REPLACE ";" ", " supported_components_string_list "${supported_components}") @@ -118,12 +118,12 @@ if (Bluelib_FOUND) endforeach (component) foreach (component ${created_targets}) - if ("${component}" STREQUAL "Object") + if ("${component}" STREQUAL "Ds") if (NOT TARGET Bluelib::Core) - message(FATAL_ERROR "Bluelib: Module 'Object' depends on 'Core', which was not specified in find_package()") + message(FATAL_ERROR "Bluelib: Module 'Ds' depends on 'Core', which was not specified in find_package()") endif () - target_link_libraries(Bluelib::Object INTERFACE Bluelib::Core) + target_link_libraries(Bluelib::Ds INTERFACE Bluelib::Core) endif () if ("${component}" STREQUAL "Term") @@ -131,11 +131,11 @@ if (Bluelib_FOUND) message(FATAL_ERROR "Bluelib: Module 'Term' depends on 'Core', which was not specified in find_package()") endif () - if (NOT TARGET Bluelib::Object) - message(FATAL_ERROR "Bluelib: Module 'Term' depends on 'Object', which was not specified in find_package()") + if (NOT TARGET Bluelib::Ds) + message(FATAL_ERROR "Bluelib: Module 'Term' depends on 'Ds', which was not specified in find_package()") endif () - target_link_libraries(Bluelib::Term INTERFACE Bluelib::Core Bluelib::Object) + target_link_libraries(Bluelib::Term INTERFACE Bluelib::Core Bluelib::Ds) endif () if ("${component}" STREQUAL "Serial") @@ -143,11 +143,11 @@ if (Bluelib_FOUND) message(FATAL_ERROR "Bluelib: Module 'Serial' depends on 'Core', which was not specified in find_package()") endif () - if (NOT TARGET Bluelib::Object) - message(FATAL_ERROR "Bluelib: Module 'Serial' depends on 'Object', which was not specified in find_package()") + if (NOT TARGET Bluelib::Ds) + message(FATAL_ERROR "Bluelib: Module 'Serial' depends on 'Ds', which was not specified in find_package()") endif () - target_link_libraries(Bluelib::Serial INTERFACE Bluelib::Core Bluelib::Object) + target_link_libraries(Bluelib::Serial INTERFACE Bluelib::Core Bluelib::Ds) endif () if ("${component}" STREQUAL "Cmd") @@ -155,15 +155,15 @@ if (Bluelib_FOUND) message(FATAL_ERROR "Bluelib: Module 'Cmd' depends on 'Core', which was not specified in find_package()") endif () - if (NOT TARGET Bluelib::Object) - message(FATAL_ERROR "Bluelib: Module 'Cmd' depends on 'Object', which was not specified in find_package()") + if (NOT TARGET Bluelib::Ds) + message(FATAL_ERROR "Bluelib: Module 'Cmd' depends on 'Ds', which was not specified in find_package()") endif () if (NOT TARGET Bluelib::Term) message(FATAL_ERROR "Bluelib: Module 'Cmd' depends on 'Term', which was not specified in find_package()") endif () - target_link_libraries(Bluelib::Cmd INTERFACE Bluelib::Core Bluelib::Object Bluelib::Term) + target_link_libraries(Bluelib::Cmd INTERFACE Bluelib::Core Bluelib::Ds Bluelib::Term) endif () if ("${component}" STREQUAL "Io") @@ -171,11 +171,11 @@ if (Bluelib_FOUND) message(FATAL_ERROR "Bluelib: Module 'Io' depends on 'Core', which was not specified in find_package()") endif () - if (NOT TARGET Bluelib::Object) - message(FATAL_ERROR "Bluelib: Module 'Io' depends on 'Object', which was not specified in find_package()") + if (NOT TARGET Bluelib::Ds) + message(FATAL_ERROR "Bluelib: Module 'Io' depends on 'Ds', which was not specified in find_package()") endif () - target_link_libraries(Bluelib::Io INTERFACE Bluelib::Core Bluelib::Object) + target_link_libraries(Bluelib::Io INTERFACE Bluelib::Core Bluelib::Ds) endif () if ("${component}" STREQUAL "Compress") @@ -183,7 +183,7 @@ if (Bluelib_FOUND) message(FATAL_ERROR "Bluelib: Module 'Compress' depends on 'Core', which was not specified in find_package()") endif () - target_link_libraries(Bluelib::Compress INTERFACE Bluelib::Core Bluelib::Object) + target_link_libraries(Bluelib::Compress INTERFACE Bluelib::Core Bluelib::Ds) endif () endforeach (component) endif() diff --git a/cmd/CMakeLists.txt b/cmd/CMakeLists.txt index 9f56738..41fc4c0 100644 --- a/cmd/CMakeLists.txt +++ b/cmd/CMakeLists.txt @@ -1,3 +1,3 @@ include(../cmake/Templates.cmake) -add_bluelib_module(NAME cmd DEPENDENCIES core object term) +add_bluelib_module(NAME cmd DEPENDENCIES core ds term) diff --git a/cmd/arg.c b/cmd/arg.c index f7e4963..85bf16d 100644 --- a/cmd/arg.c +++ b/cmd/arg.c @@ -1,7 +1,7 @@ #include "command.h" #include -#include +#include #include #include diff --git a/cmd/arglist.c b/cmd/arglist.c index dc3d3c1..6f0de78 100644 --- a/cmd/arglist.c +++ b/cmd/arglist.c @@ -2,7 +2,7 @@ #include "command.h" #include -#include +#include #include #include #include diff --git a/cmd/command.c b/cmd/command.c index b305204..bd8dfcd 100644 --- a/cmd/command.c +++ b/cmd/command.c @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include #include diff --git a/cmd/include/blue/cmd.h b/cmd/include/blue/cmd.h index 445fa18..c0113f7 100644 --- a/cmd/include/blue/cmd.h +++ b/cmd/include/blue/cmd.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include diff --git a/cmd/option.c b/cmd/option.c index 7588d11..135400d 100644 --- a/cmd/option.c +++ b/cmd/option.c @@ -1,7 +1,7 @@ #include "command.h" #include -#include +#include #include #include diff --git a/cmd/report.c b/cmd/report.c index aebb08a..abdeb90 100644 --- a/cmd/report.c +++ b/cmd/report.c @@ -1,7 +1,7 @@ #include "command.h" #include -#include +#include #include #include diff --git a/object-test/arrays.c b/ds-test/arrays.c similarity index 83% rename from object-test/arrays.c rename to ds-test/arrays.c index 01573d9..b1c21c9 100644 --- a/object-test/arrays.c +++ b/ds-test/arrays.c @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include int main(void) diff --git a/object-test/object-units.c b/ds-test/ds-units.c similarity index 97% rename from object-test/object-units.c rename to ds-test/ds-units.c index 8dec8b8..157054f 100644 --- a/object-test/object-units.c +++ b/ds-test/ds-units.c @@ -1,5 +1,5 @@ #include -#include +#include static void test_string_create(CuTest *tc) { diff --git a/object-test/numbers.c b/ds-test/numbers.c similarity index 84% rename from object-test/numbers.c rename to ds-test/numbers.c index 874ff69..43d3160 100644 --- a/object-test/numbers.c +++ b/ds-test/numbers.c @@ -1,4 +1,4 @@ -#include +#include #include int main(void) diff --git a/object-test/streams.c b/ds-test/streams.c similarity index 93% rename from object-test/streams.c rename to ds-test/streams.c index 7d6b54a..91e2205 100644 --- a/object-test/streams.c +++ b/ds-test/streams.c @@ -1,5 +1,5 @@ #include -#include +#include #include int main(int argc, const char **argv) diff --git a/object-test/strings.c b/ds-test/strings.c similarity index 96% rename from object-test/strings.c rename to ds-test/strings.c index 62d1a66..e347741 100644 --- a/object-test/strings.c +++ b/ds-test/strings.c @@ -1,5 +1,5 @@ #include -#include +#include #include #include diff --git a/object-test/trees.c b/ds-test/trees.c similarity index 96% rename from object-test/trees.c rename to ds-test/trees.c index e3fd35c..d8cbea8 100644 --- a/object-test/trees.c +++ b/ds-test/trees.c @@ -1,7 +1,7 @@ #include -#include -#include -#include +#include +#include +#include #include #define NITEMS 16 diff --git a/object-test/uuids.c b/ds-test/uuids.c similarity index 88% rename from object-test/uuids.c rename to ds-test/uuids.c index 512bed9..01535f0 100644 --- a/object-test/uuids.c +++ b/ds-test/uuids.c @@ -1,4 +1,4 @@ -#include +#include #include int main(void) diff --git a/ds/CMakeLists.txt b/ds/CMakeLists.txt new file mode 100644 index 0000000..894e606 --- /dev/null +++ b/ds/CMakeLists.txt @@ -0,0 +1,3 @@ +include(../cmake/Templates.cmake) + +add_bluelib_module(NAME ds DEPENDENCIES core) diff --git a/object/array.c b/ds/array.c similarity index 75% rename from object/array.c rename to ds/array.c index b8cf20c..b1439b0 100644 --- a/object/array.c +++ b/ds/array.c @@ -2,17 +2,17 @@ #include #include -#include -#include +#include +#include #include #include -static void array_release(struct b_object *obj); -static void array_to_string(struct b_object *obj, struct b_stream *out); +static void array_release(struct b_dsref *obj); +static void array_to_string(struct b_dsref *obj, struct b_stream *out); -static struct b_object_type array_type = { - .t_flags = B_OBJECT_FUNDAMENTAL, - .t_id = B_OBJECT_TYPE_ARRAY, +static struct b_dsref_type array_type = { + .t_flags = B_DSREF_FUNDAMENTAL, + .t_id = B_DSREF_TYPE_ARRAY, .t_name = "corelib::array", .t_instance_size = sizeof(struct b_array), .t_release = array_release, @@ -22,7 +22,7 @@ static struct b_object_type array_type = { struct b_array *b_array_create(void) { struct b_array *array - = (struct b_array *)b_object_type_instantiate(&array_type); + = (struct b_array *)b_dsref_type_instantiate(&array_type); if (!array) { return NULL; } @@ -31,7 +31,7 @@ struct b_array *b_array_create(void) } struct b_array *b_array_create_with_values( - struct b_object *const *values, size_t nr_values) + struct b_dsref *const *values, size_t nr_values) { struct b_array *array = b_array_create(); if (!array) { @@ -47,7 +47,7 @@ struct b_array *b_array_create_with_values( array->ar_len = real_nr_values; array->ar_cap = real_nr_values; - array->ar_data = calloc(real_nr_values, sizeof(struct b_object *)); + array->ar_data = calloc(real_nr_values, sizeof(struct b_dsref *)); if (!array->ar_data) { b_array_release(array); return NULL; @@ -65,7 +65,7 @@ static b_status resize_array(struct b_array *array, size_t new_capacity) { if (array->ar_cap < new_capacity) { void *new_data = realloc( - array->ar_data, new_capacity * sizeof(struct b_object *)); + array->ar_data, new_capacity * sizeof(struct b_dsref *)); if (!new_data) { return B_ERR_NO_MEMORY; } @@ -77,7 +77,7 @@ static b_status resize_array(struct b_array *array, size_t new_capacity) } void *new_data = realloc( - array->ar_data, new_capacity * sizeof(struct b_object *)); + array->ar_data, new_capacity * sizeof(struct b_dsref *)); if (!new_data) { return B_ERR_NO_MEMORY; } @@ -93,17 +93,17 @@ static b_status resize_array(struct b_array *array, size_t new_capacity) return B_SUCCESS; } -b_status b_array_append(struct b_array *array, struct b_object *value) +b_status b_array_append(struct b_array *array, struct b_dsref *value) { return b_array_insert(array, value, B_NPOS); } -b_status b_array_prepend(struct b_array *array, struct b_object *value) +b_status b_array_prepend(struct b_array *array, struct b_dsref *value) { return b_array_insert(array, value, 0); } -b_status b_array_insert(struct b_array *array, struct b_object *value, size_t at) +b_status b_array_insert(struct b_array *array, struct b_dsref *value, size_t at) { if (at == B_NPOS) { at = array->ar_len; @@ -123,9 +123,9 @@ b_status b_array_insert(struct b_array *array, struct b_object *value, size_t at } } - struct b_object **src = array->ar_data + at; - struct b_object **dest = src + 1; - size_t move_len = (array->ar_len - at) * sizeof(struct b_object *); + struct b_dsref **src = array->ar_data + at; + struct b_dsref **dest = src + 1; + size_t move_len = (array->ar_len - at) * sizeof(struct b_dsref *); memmove(dest, src, move_len); @@ -141,9 +141,9 @@ b_status b_array_remove(struct b_array *array, size_t at) return B_ERR_OUT_OF_BOUNDS; } - struct b_object **src = array->ar_data + at; - struct b_object **dest = src + 1; - size_t move_len = array->ar_len * sizeof(struct b_object *); + struct b_dsref **src = array->ar_data + at; + struct b_dsref **dest = src + 1; + size_t move_len = array->ar_len * sizeof(struct b_dsref *); b_release(array->ar_data[at]); @@ -164,17 +164,17 @@ b_status b_array_remove_back(struct b_array *array) return b_array_remove(array, array->ar_len - 1); } -struct b_object *b_array_pop(b_array *array, size_t at) +struct b_dsref *b_array_pop(b_array *array, size_t at) { if (at >= array->ar_len) { return NULL; } - struct b_object **src = array->ar_data + at; - struct b_object **dest = src + 1; - size_t move_len = array->ar_len * sizeof(struct b_object *); + struct b_dsref **src = array->ar_data + at; + struct b_dsref **dest = src + 1; + size_t move_len = array->ar_len * sizeof(struct b_dsref *); - struct b_object *out = array->ar_data[at]; + struct b_dsref *out = array->ar_data[at]; memmove(dest, src, move_len); @@ -183,17 +183,17 @@ struct b_object *b_array_pop(b_array *array, size_t at) return out; } -struct b_object *b_array_pop_front(struct b_array *array) +struct b_dsref *b_array_pop_front(struct b_array *array) { return b_array_pop(array, 0); } -struct b_object *b_array_pop_back(struct b_array *array) +struct b_dsref *b_array_pop_back(struct b_array *array) { return b_array_pop(array, array->ar_len - 1); } -struct b_object *b_array_at(const struct b_array *array, size_t at) +struct b_dsref *b_array_at(const struct b_array *array, size_t at) { if (at >= array->ar_len) { return NULL; @@ -202,7 +202,7 @@ struct b_object *b_array_at(const struct b_array *array, size_t at) return array->ar_data[at]; } -struct b_object *b_array_get(struct b_array *array, size_t at) +struct b_dsref *b_array_get(struct b_array *array, size_t at) { if (at >= array->ar_len) { return NULL; @@ -221,7 +221,7 @@ size_t b_array_capacity(const struct b_array *array) return array->ar_cap; } -static void array_to_string(struct b_object *obj, struct b_stream *out) +static void array_to_string(struct b_dsref *obj, struct b_stream *out) { struct b_array *array = B_ARRAY(obj); @@ -238,7 +238,7 @@ static void array_to_string(struct b_object *obj, struct b_stream *out) b_array_iterator it; b_array_foreach(&it, array) { - bool is_string = b_typeid(it.value) == B_OBJECT_TYPE_STRING; + bool is_string = b_typeid(it.value) == B_DSREF_TYPE_STRING; if (is_string) { b_stream_write_char(out, '"'); @@ -261,7 +261,7 @@ static void array_to_string(struct b_object *obj, struct b_stream *out) b_stream_write_char(out, ']'); } -static void array_release(struct b_object *obj) +static void array_release(struct b_dsref *obj) { struct b_array *array = B_ARRAY(obj); @@ -374,7 +374,7 @@ bool b_array_iterator_is_valid(const struct b_array_iterator *it) return it->value != NULL; } -b_object_type_id b_array_type_id(void) +b_dsref_type_id b_array_type_id(void) { - return (b_object_type_id)&array_type; + return (b_dsref_type_id)&array_type; } diff --git a/object/array.h b/ds/array.h similarity index 82% rename from object/array.h rename to ds/array.h index 028fe2a..2c3fc0c 100644 --- a/object/array.h +++ b/ds/array.h @@ -4,12 +4,12 @@ #include "../object.h" struct b_array { - struct b_object ar_base; + struct b_dsref ar_base; /* number of items in array */ unsigned int ar_len; /* maximum number of items that can currently be stored in array */ unsigned int ar_cap; - struct b_object **ar_data; + struct b_dsref **ar_data; }; #endif diff --git a/object/bitbuffer.c b/ds/bitbuffer.c similarity index 100% rename from object/bitbuffer.c rename to ds/bitbuffer.c diff --git a/object/bitbuffer.h b/ds/bitbuffer.h similarity index 100% rename from object/bitbuffer.h rename to ds/bitbuffer.h diff --git a/object/bitmap.c b/ds/bitmap.c similarity index 99% rename from object/bitmap.c rename to ds/bitmap.c index c4a501f..14a7e0b 100644 --- a/object/bitmap.c +++ b/ds/bitmap.c @@ -1,5 +1,5 @@ #include -#include +#include #include void b_bitmap_zero(b_bitmap_word *map, unsigned long nbits) diff --git a/object/buffer.c b/ds/buffer.c similarity index 93% rename from object/buffer.c rename to ds/buffer.c index 32cb037..eb39439 100644 --- a/object/buffer.c +++ b/ds/buffer.c @@ -1,16 +1,16 @@ #include "buffer.h" #include -#include -#include +#include +#include #include #include -static void buffer_release(struct b_object *obj); +static void buffer_release(struct b_dsref *obj); -static struct b_object_type buffer_type = { - .t_flags = B_OBJECT_FUNDAMENTAL, - .t_id = B_OBJECT_TYPE_BUFFER, +static struct b_dsref_type buffer_type = { + .t_flags = B_DSREF_FUNDAMENTAL, + .t_id = B_DSREF_TYPE_BUFFER, .t_name = "corelib::buffer", .t_instance_size = sizeof(struct b_buffer), .t_release = buffer_release, @@ -19,7 +19,7 @@ static struct b_object_type buffer_type = { struct b_buffer *b_buffer_create(size_t item_sz) { struct b_buffer *buffer - = (struct b_buffer *)b_object_type_instantiate(&buffer_type); + = (struct b_buffer *)b_dsref_type_instantiate(&buffer_type); if (!buffer) { return NULL; } @@ -219,7 +219,7 @@ size_t b_buffer_capacity(const struct b_buffer *buffer) return buffer->buf_cap; } -void buffer_release(struct b_object *obj) +void buffer_release(struct b_dsref *obj) { struct b_buffer *buffer = B_BUFFER(obj); @@ -319,7 +319,7 @@ size_t b_buffer_get_capacity(const struct b_buffer *buf) return buf->buf_cap; } -b_object_type_id b_buffer_type_id(void) +b_dsref_type_id b_buffer_type_id(void) { - return (b_object_type_id)&buffer_type; + return (b_dsref_type_id)&buffer_type; } diff --git a/object/buffer.h b/ds/buffer.h similarity index 92% rename from object/buffer.h rename to ds/buffer.h index 8ca6ae2..223bbd8 100644 --- a/object/buffer.h +++ b/ds/buffer.h @@ -4,7 +4,7 @@ #include "../object.h" struct b_buffer { - struct b_object buf_base; + struct b_dsref buf_base; /* number of items in buffer */ unsigned int buf_len; /* maximum number of items that can currently be stored in array */ diff --git a/object/dict.c b/ds/dict.c similarity index 91% rename from object/dict.c rename to ds/dict.c index c6711ea..7c14ae6 100644 --- a/object/dict.c +++ b/ds/dict.c @@ -2,9 +2,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include #include @@ -23,13 +23,13 @@ uint64_t b_cstr_hash(const char *s) return hash; } -static void dict_release(struct b_object *obj); -static void dict_to_string(struct b_object *obj, struct b_stream *out); +static void dict_release(struct b_dsref *obj); +static void dict_to_string(struct b_dsref *obj, struct b_stream *out); -static struct b_object_type dict_type = { +static struct b_dsref_type dict_type = { .t_name = "corelib::dict", - .t_flags = B_OBJECT_FUNDAMENTAL, - .t_id = B_OBJECT_TYPE_DICT, + .t_flags = B_DSREF_FUNDAMENTAL, + .t_id = B_DSREF_TYPE_DICT, .t_instance_size = sizeof(struct b_dict), .t_release = dict_release, .t_to_string = dict_to_string, @@ -38,7 +38,7 @@ static struct b_object_type dict_type = { struct b_dict *b_dict_create(void) { struct b_dict *dict - = (struct b_dict *)b_object_type_instantiate(&dict_type); + = (struct b_dict *)b_dsref_type_instantiate(&dict_type); if (!dict) { return NULL; } @@ -86,7 +86,7 @@ static struct b_dict_bucket_item *create_bucket_item(void) return item; } -b_status b_dict_put(struct b_dict *dict, const char *key, b_object *value) +b_status b_dict_put(struct b_dict *dict, const char *key, b_dsref *value) { uint64_t hash = b_cstr_hash(key); struct b_dict_bucket *bucket = get_bucket(&dict->d_buckets, hash); @@ -113,7 +113,7 @@ b_status b_dict_put(struct b_dict *dict, const char *key, b_object *value) return B_SUCCESS; } -b_object *b_dict_at(const struct b_dict *dict, const char *key) +b_dsref *b_dict_at(const struct b_dict *dict, const char *key) { uint64_t hash = b_cstr_hash(key); struct b_dict_bucket *bucket = get_bucket(&dict->d_buckets, hash); @@ -134,9 +134,9 @@ b_object *b_dict_at(const struct b_dict *dict, const char *key) return NULL; } -b_object *b_dict_get(struct b_dict *dict, const char *key) +b_dsref *b_dict_get(struct b_dict *dict, const char *key) { - b_object *value = b_dict_at(dict, key); + b_dsref *value = b_dict_at(dict, key); if (value) { b_retain(value); } @@ -186,7 +186,7 @@ bool b_dict_is_empty(const b_dict *dict) return false; } -static void dict_to_string(struct b_object *obj, struct b_stream *out) +static void dict_to_string(struct b_dsref *obj, struct b_stream *out) { struct b_dict *dict = B_DICT(obj); @@ -205,7 +205,7 @@ static void dict_to_string(struct b_object *obj, struct b_stream *out) { b_stream_write_fmt(out, NULL, "%s: ", it.key); - bool is_string = b_typeid(it.value) == B_OBJECT_TYPE_STRING; + bool is_string = b_typeid(it.value) == B_DSREF_TYPE_STRING; if (is_string) { b_stream_write_char(out, '"'); @@ -433,7 +433,7 @@ bool b_dict_iterator_is_valid(const struct b_dict_iterator *it) return it->key != NULL; } -static void dict_release(struct b_object *obj) +static void dict_release(struct b_dsref *obj) { struct b_dict *dict = B_DICT(obj); @@ -477,7 +477,7 @@ static void dict_release(struct b_object *obj) #endif } -b_object_type_id b_dict_type_id(void) +b_dsref_type_id b_dict_type_id(void) { - return (b_object_type_id)&dict_type; + return (b_dsref_type_id)&dict_type; } diff --git a/object/dict.h b/ds/dict.h similarity index 86% rename from object/dict.h rename to ds/dict.h index e0bc013..ff3d84b 100644 --- a/object/dict.h +++ b/ds/dict.h @@ -9,7 +9,7 @@ struct b_dict_bucket_item { b_queue_entry bi_entry; char *bi_str; - struct b_object *bi_value; + struct b_dsref *bi_value; }; struct b_dict_bucket { @@ -19,7 +19,7 @@ struct b_dict_bucket { }; struct b_dict { - struct b_object d_base; + struct b_dsref d_base; b_btree d_buckets; }; diff --git a/object/hashmap.c b/ds/hashmap.c similarity index 95% rename from object/hashmap.c rename to ds/hashmap.c index 7f50283..43fd86c 100644 --- a/object/hashmap.c +++ b/ds/hashmap.c @@ -2,9 +2,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include #include @@ -38,12 +38,12 @@ static uint64_t hash_data(const void *p, size_t size) return hash; } -static void hashmap_release(struct b_object *obj); +static void hashmap_release(struct b_dsref *obj); -static struct b_object_type hashmap_type = { +static struct b_dsref_type hashmap_type = { .t_name = "corelib::hashmap", - .t_flags = B_OBJECT_FUNDAMENTAL, - .t_id = B_OBJECT_TYPE_HASHMAP, + .t_flags = B_DSREF_FUNDAMENTAL, + .t_id = B_DSREF_TYPE_HASHMAP, .t_instance_size = sizeof(struct b_hashmap), .t_release = hashmap_release, }; @@ -52,7 +52,7 @@ struct b_hashmap *b_hashmap_create( b_hashmap_key_destructor key_dtor, b_hashmap_value_destructor value_dtor) { struct b_hashmap *hashmap - = (struct b_hashmap *)b_object_type_instantiate(&hashmap_type); + = (struct b_hashmap *)b_dsref_type_instantiate(&hashmap_type); if (!hashmap) { return NULL; } @@ -444,7 +444,7 @@ bool b_hashmap_iterator_is_valid(const struct b_hashmap_iterator *it) return it->key != NULL; } -static void hashmap_release(struct b_object *obj) +static void hashmap_release(struct b_dsref *obj) { struct b_hashmap *map = B_HASHMAP(obj); @@ -455,7 +455,7 @@ static void hashmap_release(struct b_object *obj) } } -b_object_type_id b_hashmap_type_id(void) +b_dsref_type_id b_hashmap_type_id(void) { - return (b_object_type_id)&hashmap_type; + return (b_dsref_type_id)&hashmap_type; } diff --git a/object/hashmap.h b/ds/hashmap.h similarity index 89% rename from object/hashmap.h rename to ds/hashmap.h index f9ac29d..76de029 100644 --- a/object/hashmap.h +++ b/ds/hashmap.h @@ -3,7 +3,7 @@ #include #include -#include +#include struct b_hashmap_bucket_item { struct b_queue_entry bi_entry; @@ -18,7 +18,7 @@ struct b_hashmap_bucket { }; struct b_hashmap { - struct b_object h_base; + struct b_dsref h_base; struct b_btree h_buckets; b_hashmap_key_destructor h_key_dtor; b_hashmap_value_destructor h_value_dtor; diff --git a/object/include/blue/object.h b/ds/include/blue/ds.h similarity index 100% rename from object/include/blue/object.h rename to ds/include/blue/ds.h diff --git a/object/include/blue/object/array.h b/ds/include/blue/ds/array.h similarity index 92% rename from object/include/blue/object/array.h rename to ds/include/blue/ds/array.h index 0ef9886..67185ab 100644 --- a/object/include/blue/object/array.h +++ b/ds/include/blue/ds/array.h @@ -4,11 +4,11 @@ #include #include #include -#include -#include +#include +#include /** - * Cast a generic b_object pointer to an b_array pointer. + * Cast a generic b_dsref pointer to an b_array pointer. */ #define B_ARRAY(p) ((b_array *)(p)) @@ -43,7 +43,7 @@ typedef struct b_array b_array; /** * Iterator for traversing the contents of an b_array. * - * The iterator provides the current b_object `value`, as well + * The iterator provides the current b_dsref `value`, as well * as the index `i` of that value within the array. * * Any members whose names begin with _ (underscore) are reserved @@ -56,7 +56,7 @@ typedef struct b_array_iterator { /** The index of the current value */ size_t i; /** The current value */ - b_object *value; + b_dsref *value; } b_array_iterator; /** @@ -67,7 +67,7 @@ typedef struct b_array_iterator { BLUE_API b_array *b_array_create(void); /** - * Creates an b_array initialised with the contents of the provided b_object + * Creates an b_array initialised with the contents of the provided b_dsref * pointer array. The b_array will take a reference to each object specified in * `values`, and will increment the reference count. The order of objects in the * new b_array will be the same as the order of objects in `values`. Any NULL @@ -82,7 +82,7 @@ BLUE_API b_array *b_array_create(void); * @return A pointer to the new b_array, or NULL if an error occurred. */ BLUE_API b_array *b_array_create_with_values( - b_object *const *values, size_t nr_values); + b_dsref *const *values, size_t nr_values); /** * Increment the reference counter of an b_array. @@ -92,7 +92,7 @@ BLUE_API b_array *b_array_create_with_values( */ static inline b_array *b_array_retain(b_array *array) { - return B_ARRAY(b_retain(B_OBJECT(array))); + return B_ARRAY(b_retain(B_DSREF(array))); } /** @@ -101,7 +101,7 @@ static inline b_array *b_array_retain(b_array *array) */ static inline void b_array_release(b_array *array) { - b_release(B_OBJECT(array)); + b_release(B_DSREF(array)); } /** @@ -120,7 +120,7 @@ BLUE_API void b_array_clear(b_array *array); * @param value The object to append. * @return B_SUCCESS if the object was appended successfully, or an error code if an error occurred. */ -BLUE_API b_status b_array_append(b_array *array, b_object *value); +BLUE_API b_status b_array_append(b_array *array, b_dsref *value); /** * Inserts an object at the beginning of an b_array. The reference count of the object @@ -131,7 +131,7 @@ BLUE_API b_status b_array_append(b_array *array, b_object *value); * @param value The object to prepend. * @return B_SUCCESS if the object was prepended successfully, or an error code if an error occurred. */ -BLUE_API b_status b_array_prepend(b_array *array, b_object *value); +BLUE_API b_status b_array_prepend(b_array *array, b_dsref *value); /** * Inserts an object into an b_array at a given index. The reference count of the object @@ -145,7 +145,7 @@ BLUE_API b_status b_array_prepend(b_array *array, b_object *value); * be inserted at the end of the b_array. * @return B_SUCCESS if the object was inserted, or a status code describing any error that occurred. */ -BLUE_API b_status b_array_insert(b_array *array, b_object *value, size_t at); +BLUE_API b_status b_array_insert(b_array *array, b_dsref *value, size_t at); /** * Removes the object at the specified index from an b_array. The reference count @@ -191,7 +191,7 @@ BLUE_API b_status b_array_remove_back(b_array *array); * @return An pointer to the removed object. This pointer is owned by the * caller. Returns NULL if an error occurred. */ -BLUE_API b_object *b_array_pop(b_array *array, size_t at); +BLUE_API b_dsref *b_array_pop(b_array *array, size_t at); /** * Removes the object at the beginning of an b_array, and returns a pointer to @@ -204,7 +204,7 @@ BLUE_API b_object *b_array_pop(b_array *array, size_t at); * @return An pointer to the removed object. This pointer is owned by the * caller. Returns NULL if an error occurred. */ -BLUE_API b_object *b_array_pop_front(b_array *array); +BLUE_API b_dsref *b_array_pop_front(b_array *array); /** * Removes the object at the end of an b_array, and returns a pointer to it. The @@ -215,7 +215,7 @@ BLUE_API b_object *b_array_pop_front(b_array *array); * @return An pointer to the removed object. This pointer is owned by the * caller. Returns NULL if an error occurred. */ -BLUE_API b_object *b_array_pop_back(b_array *array); +BLUE_API b_dsref *b_array_pop_back(b_array *array); /** * Returns an unowned pointer to the object at the given index of an b_array. @@ -226,7 +226,7 @@ BLUE_API b_object *b_array_pop_back(b_array *array); * @return A pointer to the object at the given index. This pointer is NOT owned * by the caller. Returns NULL if an error occurred. */ -BLUE_API b_object *b_array_at(const b_array *array, size_t at); +BLUE_API b_dsref *b_array_at(const b_array *array, size_t at); /** * Returns an owned pointer to the object at the given index of an b_array. The caller owns @@ -237,7 +237,7 @@ BLUE_API b_object *b_array_at(const b_array *array, size_t at); * @return A pointer to the object at the given index. This pointer is owned by the caller. * Returns NULL if an error occurred. */ -BLUE_API b_object *b_array_get(b_array *array, size_t at); +BLUE_API b_dsref *b_array_get(b_array *array, size_t at); /** * Returns the number of objects contained in an b_array. diff --git a/object/include/blue/object/bitbuffer.h b/ds/include/blue/ds/bitbuffer.h similarity index 88% rename from object/include/blue/object/bitbuffer.h rename to ds/include/blue/ds/bitbuffer.h index cf40e45..b2bd451 100644 --- a/object/include/blue/object/bitbuffer.h +++ b/ds/include/blue/ds/bitbuffer.h @@ -1,7 +1,7 @@ #ifndef BLUE_OBJECT_BITBUFFER_H_ #define BLUE_OBJECT_BITBUFFER_H_ -#include +#include #define B_BITBUFFER(p) ((b_bitbuffer *)(p)) @@ -11,11 +11,11 @@ BLUE_API b_bitbuffer *b_bitbuffer_create(void); static inline b_bitbuffer *b_bitbuffer_retain(b_bitbuffer *buf) { - return B_BITBUFFER(b_retain(B_OBJECT(buf))); + return B_BITBUFFER(b_retain(B_DSREF(buf))); } static inline void b_bitbuffer_release(b_bitbuffer *buf) { - b_release(B_OBJECT(buf)); + b_release(B_DSREF(buf)); } BLUE_API b_status b_bitbuffer_put_bit(b_bitbuffer *buf, int bit); diff --git a/object/include/blue/object/bitmap.h b/ds/include/blue/ds/bitmap.h similarity index 100% rename from object/include/blue/object/bitmap.h rename to ds/include/blue/ds/bitmap.h diff --git a/object/include/blue/object/buffer.h b/ds/include/blue/ds/buffer.h similarity index 92% rename from object/include/blue/object/buffer.h rename to ds/include/blue/ds/buffer.h index 3548700..f424e95 100644 --- a/object/include/blue/object/buffer.h +++ b/ds/include/blue/ds/buffer.h @@ -1,8 +1,8 @@ #ifndef BLUELIB_BUFFER_H_ #define BLUELIB_BUFFER_H_ -#include -#include +#include +#include #include #define B_BUFFER(p) ((b_buffer *)(p)) @@ -16,11 +16,11 @@ BLUE_API b_buffer *b_buffer_create_from_array( static inline b_buffer *b_buffer_retain(b_buffer *buf) { - return B_BUFFER(b_retain(B_OBJECT(buf))); + return B_BUFFER(b_retain(B_DSREF(buf))); } static inline void b_buffer_release(b_buffer *buf) { - b_release(B_OBJECT(buf)); + b_release(B_DSREF(buf)); } BLUE_API void *b_buffer_steal(b_buffer *buf); BLUE_API b_status b_buffer_reserve(b_buffer *buf, size_t capacity); diff --git a/object/include/blue/object/dict.h b/ds/include/blue/ds/dict.h similarity index 82% rename from object/include/blue/object/dict.h rename to ds/include/blue/ds/dict.h index 531e069..bfd42f0 100644 --- a/object/include/blue/object/dict.h +++ b/ds/include/blue/ds/dict.h @@ -5,8 +5,8 @@ #include #include #include -#include -#include +#include +#include #define B_DICT(p) ((b_dict *)(p)) @@ -29,7 +29,7 @@ typedef struct b_dict_iterator { b_iterator _base; size_t i; const char *key; - b_object *value; + b_dsref *value; b_dict *_d; b_btree_node *_cbn; @@ -38,7 +38,7 @@ typedef struct b_dict_iterator { typedef struct b_dict_item { const char *key; - b_object *value; + b_dsref *value; } b_dict_item; BLUE_API b_dict *b_dict_create(void); @@ -46,16 +46,16 @@ BLUE_API b_dict *b_dict_create_with_items(const b_dict_item *items); static inline b_dict *b_dict_retain(b_dict *dict) { - return B_DICT(b_retain(B_OBJECT(dict))); + return B_DICT(b_retain(B_DSREF(dict))); } static inline void b_dict_release(b_dict *dict) { - b_release(B_OBJECT(dict)); + b_release(B_DSREF(dict)); } -BLUE_API b_status b_dict_put(b_dict *dict, const char *key, b_object *value); -BLUE_API b_object *b_dict_at(const b_dict *dict, const char *key); -BLUE_API b_object *b_dict_get(b_dict *dict, const char *key); +BLUE_API b_status b_dict_put(b_dict *dict, const char *key, b_dsref *value); +BLUE_API b_dsref *b_dict_at(const b_dict *dict, const char *key); +BLUE_API b_dsref *b_dict_get(b_dict *dict, const char *key); BLUE_API bool b_dict_has_key(const b_dict *dict, const char *key); BLUE_API size_t b_dict_get_size(const b_dict *dict); diff --git a/object/include/blue/object/hashmap.h b/ds/include/blue/ds/hashmap.h similarity index 95% rename from object/include/blue/object/hashmap.h rename to ds/include/blue/ds/hashmap.h index 225b2f2..8edda90 100644 --- a/object/include/blue/object/hashmap.h +++ b/ds/include/blue/ds/hashmap.h @@ -5,8 +5,8 @@ #include #include #include -#include -#include +#include +#include #define B_HASHMAP(p) ((b_hashmap *)(p)) @@ -70,11 +70,11 @@ BLUE_API b_hashmap *b_hashmap_create_with_items(const b_hashmap_item *items); static inline b_hashmap *b_hashmap_retain(b_hashmap *hashmap) { - return B_HASHMAP(b_retain(B_OBJECT(hashmap))); + return B_HASHMAP(b_retain(B_DSREF(hashmap))); } static inline void b_hashmap_release(b_hashmap *hashmap) { - b_release(B_OBJECT(hashmap)); + b_release(B_DSREF(hashmap)); } BLUE_API b_status b_hashmap_put( diff --git a/object/include/blue/object/list.h b/ds/include/blue/ds/list.h similarity index 95% rename from object/include/blue/object/list.h rename to ds/include/blue/ds/list.h index 4872849..3e81d7c 100644 --- a/object/include/blue/object/list.h +++ b/ds/include/blue/ds/list.h @@ -2,7 +2,7 @@ #define BLUE_OBJECT_LIST_H_ #include -#include +#include #define B_LIST(p) ((b_list *)(p)) @@ -25,11 +25,11 @@ BLUE_API b_list *b_list_create(void); static inline b_list *b_list_retain(b_list *str) { - return B_LIST(b_retain(B_OBJECT(str))); + return B_LIST(b_retain(B_DSREF(str))); } static inline void b_list_release(b_list *str) { - b_release(B_OBJECT(str)); + b_release(B_DSREF(str)); } BLUE_API bool b_list_empty(b_list *q); diff --git a/object/include/blue/object/number.h b/ds/include/blue/ds/number.h similarity index 97% rename from object/include/blue/object/number.h rename to ds/include/blue/ds/number.h index b8eaa0c..7333138 100644 --- a/object/include/blue/object/number.h +++ b/ds/include/blue/ds/number.h @@ -1,8 +1,8 @@ #ifndef BLUELIB_NUMBER_H #define BLUELIB_NUMBER_H -#include -#include +#include +#include #include #define B_NUMBER(p) ((b_number *)(p)) @@ -69,11 +69,11 @@ typedef enum b_number_type { BLUE_API b_number *b_number_create(b_number_type type, void *value_ptr); static inline b_number *b_number_retain(b_number *number) { - return B_NUMBER(b_retain(B_OBJECT(number))); + return B_NUMBER(b_retain(B_DSREF(number))); } static inline void b_number_release(b_number *number) { - b_release(B_OBJECT(number)); + b_release(B_DSREF(number)); } static inline b_number *b_number_create_int8(int8_t value) diff --git a/ds/include/blue/ds/object.h b/ds/include/blue/ds/object.h new file mode 100644 index 0000000..5c9f77f --- /dev/null +++ b/ds/include/blue/ds/object.h @@ -0,0 +1,40 @@ +#ifndef BLUELIB_DSREF_H_ +#define BLUELIB_DSREF_H_ + +#include + +#define B_DSREF(p) ((b_dsref *)(p)) + +#define B_TYPEOF(object) ((struct b_dsref *)(object)->ob_type) +#define B_TYPEID(object) (b_typeid(B_DSREF(object))) + +#define B_RV(p) (b_make_rvalue(B_DSREF(p))) +#define B_RVT(t, p) ((t *)(b_make_rvalue(B_DSREF(p)))) + +#define B_DSREF_IS(object, type) (B_TYPEID(object) == B_DSREF_TYPE_##type) + +struct b_string; +struct b_stream; + +typedef enum b_comparison_result { + B_LESS = -1, + B_EQUAL = 0, + B_GREATER = 1, +} b_comparison_result_t; + +typedef struct b_dsref { + unsigned int ob_ref; + const struct b_dsref_type *ob_type; +} b_dsref; + +BLUE_API b_dsref *b_make_rvalue(b_dsref *obj); + +BLUE_API b_dsref *b_retain(b_dsref *obj); +BLUE_API void b_release(b_dsref *obj); + +BLUE_API void b_to_string(b_dsref *obj, struct b_stream *out); +BLUE_API b_dsref_type_id b_typeid(const b_dsref *obj); + +BLUE_API b_comparison_result_t b_compare(const b_dsref *a, const b_dsref *b); + +#endif diff --git a/object/include/blue/object/string.h b/ds/include/blue/ds/string.h similarity index 95% rename from object/include/blue/object/string.h rename to ds/include/blue/ds/string.h index c8853e2..8ff6760 100644 --- a/object/include/blue/object/string.h +++ b/ds/include/blue/ds/string.h @@ -2,8 +2,8 @@ #define BLUELIB_STRING_H_ #include -#include -#include +#include +#include #include struct b_stream; @@ -28,11 +28,11 @@ BLUE_API b_string *b_string_duplicate(const b_string *str); static inline b_string *b_string_retain(b_string *str) { - return B_STRING(b_retain(B_OBJECT(str))); + return B_STRING(b_retain(B_DSREF(str))); } static inline void b_string_release(b_string *str) { - b_release(B_OBJECT(str)); + b_release(B_DSREF(str)); } BLUE_API char *b_string_steal(b_string *str); BLUE_API b_status b_string_reserve(b_string *str, size_t capacity); diff --git a/object/include/blue/object/tree.h b/ds/include/blue/ds/tree.h similarity index 95% rename from object/include/blue/object/tree.h rename to ds/include/blue/ds/tree.h index 0d4a3dc..f2cc0a8 100644 --- a/object/include/blue/object/tree.h +++ b/ds/include/blue/ds/tree.h @@ -3,7 +3,7 @@ #include #include -#include +#include #define B_TREE(p) ((b_tree *)(p)) #define B_TREE_NODE_INIT ((b_tree_node){0}) @@ -45,11 +45,11 @@ BLUE_API b_tree *b_tree_create(void); static inline b_tree *b_tree_retain(b_tree *tree) { - return B_TREE(b_retain(B_OBJECT(tree))); + return B_TREE(b_retain(B_DSREF(tree))); } static inline void b_tree_release(b_tree *tree) { - b_release(B_OBJECT(tree)); + b_release(B_DSREF(tree)); } BLUE_API void b_tree_set_root(b_tree *tree, struct b_tree_node *node); diff --git a/ds/include/blue/ds/type.h b/ds/include/blue/ds/type.h new file mode 100644 index 0000000..8bef990 --- /dev/null +++ b/ds/include/blue/ds/type.h @@ -0,0 +1,53 @@ +#ifndef BLUELIB_TYPE_H_ +#define BLUELIB_TYPE_H_ + +#include +#include +#include +#include +#include + +#define B_NPOS ((size_t)INTPTR_MAX) + +struct b_dsref; +struct b_stream; + +typedef uintptr_t b_dsref_type_id; + +typedef enum b_fundamental_type_id { + B_DSREF_TYPE_NONE = 0, + B_DSREF_TYPE_ANY, + B_DSREF_TYPE_LIST, + B_DSREF_TYPE_ARRAY, + B_DSREF_TYPE_BUFFER, + B_DSREF_TYPE_DICT, + B_DSREF_TYPE_ERROR, + B_DSREF_TYPE_HASHMAP, + B_DSREF_TYPE_NUMBER, + B_DSREF_TYPE_STRING, + B_DSREF_TYPE_TREE, + B_DSREF_TYPE_UUID, + B_DSREF_TYPE_PATH, + B_DSREF_TYPE_FILE, + B_DSREF_TYPE_DIRECTORY, +} b_fundamental_type_id; + +typedef enum b_dsref_type_flags { + B_DSREF_FUNDAMENTAL = 0x01u, +} b_dsref_type_flags; + +typedef struct b_dsref_type { + b_dsref_type_flags t_flags; + char t_name[64]; + size_t t_instance_size; + b_dsref_type_id t_id; + b_queue_entry t_entry; + void (*t_init)(struct b_dsref *); + void (*t_release)(struct b_dsref *); + void (*t_to_string)(struct b_dsref *, struct b_stream *); +} b_dsref_type; + +BLUE_API b_status b_dsref_type_register(b_dsref_type *type); +BLUE_API struct b_dsref *b_dsref_type_instantiate(const b_dsref_type *type); + +#endif diff --git a/object/include/blue/object/uuid.h b/ds/include/blue/ds/uuid.h similarity index 92% rename from object/include/blue/object/uuid.h rename to ds/include/blue/ds/uuid.h index 8a73af4..29cdb27 100644 --- a/object/include/blue/object/uuid.h +++ b/ds/include/blue/ds/uuid.h @@ -2,8 +2,8 @@ #define BLUELIB_UUID_H_ #include -#include -#include +#include +#include #define B_UUID(p) ((b_uuid *)(p)) @@ -33,11 +33,11 @@ BLUE_API b_uuid *b_uuid_create_from_cstr(const char *s); static inline b_uuid *b_uuid_retain(b_uuid *uuid) { - return B_UUID(b_retain(B_OBJECT(uuid))); + return B_UUID(b_retain(B_DSREF(uuid))); } static inline void b_uuid_release(b_uuid *uuid) { - b_release(B_OBJECT(uuid)); + b_release(B_DSREF(uuid)); } BLUE_API b_status b_uuid_to_string(const b_uuid *uuid, struct b_string *out); diff --git a/object/list.c b/ds/list.c similarity index 95% rename from object/list.c rename to ds/list.c index 5b7beba..deeb2fb 100644 --- a/object/list.c +++ b/ds/list.c @@ -1,15 +1,15 @@ #include "list.h" -#include +#include #include #include -static void list_release(struct b_object *obj); +static void list_release(struct b_dsref *obj); -static struct b_object_type list_type = { +static struct b_dsref_type list_type = { .t_name = "corelib::list", - .t_flags = B_OBJECT_FUNDAMENTAL, - .t_id = B_OBJECT_TYPE_LIST, + .t_flags = B_DSREF_FUNDAMENTAL, + .t_id = B_DSREF_TYPE_LIST, .t_instance_size = sizeof(struct b_list), .t_release = list_release, }; @@ -17,7 +17,7 @@ static struct b_object_type list_type = { struct b_list *b_list_create(void) { struct b_list *list - = (struct b_list *)b_object_type_instantiate(&list_type); + = (struct b_list *)b_dsref_type_instantiate(&list_type); if (!list) { return NULL; } @@ -335,7 +335,7 @@ void *b_list_entry_value(const struct b_list_entry *entry) return entry ? entry->e_data : NULL; } -static void list_release(struct b_object *obj) +static void list_release(struct b_dsref *obj) { struct b_list *list = B_LIST(obj); b_list_delete_all(list); diff --git a/object/list.h b/ds/list.h similarity index 90% rename from object/list.h rename to ds/list.h index 8a0f507..fbea02a 100644 --- a/object/list.h +++ b/ds/list.h @@ -6,7 +6,7 @@ #include struct b_list { - struct b_object l_base; + struct b_dsref l_base; struct b_queue l_queue; size_t l_len; }; diff --git a/object/number.c b/ds/number.c similarity index 99% rename from object/number.c rename to ds/number.c index ca18f6c..9fd27f9 100644 --- a/object/number.c +++ b/ds/number.c @@ -1,7 +1,7 @@ #include "number.h" #include -#include +#include #include #include #include @@ -10,12 +10,12 @@ typedef int (*number_converter_t)(const struct b_number *, void *); static number_converter_t converters[B_NUMBER_TYPE_COUNT][B_NUMBER_TYPE_COUNT]; -static void number_to_string(struct b_object *obj, struct b_stream *out); +static void number_to_string(struct b_dsref *obj, struct b_stream *out); -static struct b_object_type number_type = { +static struct b_dsref_type number_type = { .t_name = "corelib::number", - .t_flags = B_OBJECT_FUNDAMENTAL, - .t_id = B_OBJECT_TYPE_NUMBER, + .t_flags = B_DSREF_FUNDAMENTAL, + .t_id = B_DSREF_TYPE_NUMBER, .t_instance_size = sizeof(b_number), .t_to_string = number_to_string, }; @@ -23,7 +23,7 @@ static struct b_object_type number_type = { struct b_number *b_number_create(b_number_type type, void *value_ptr) { struct b_number *n - = (struct b_number *)b_object_type_instantiate(&number_type); + = (struct b_number *)b_dsref_type_instantiate(&number_type); if (!n) { return NULL; } @@ -175,7 +175,7 @@ size_t b_number_data_size(const struct b_number *number) } } -static void number_to_string(struct b_object *obj, struct b_stream *out) +static void number_to_string(struct b_dsref *obj, struct b_stream *out) { struct b_number *number = B_NUMBER(obj); switch (number->n_type) { @@ -1675,7 +1675,7 @@ static number_converter_t converters[B_NUMBER_TYPE_COUNT][B_NUMBER_TYPE_COUNT] = }, }; -b_object_type_id b_number_type_id(void) +b_dsref_type_id b_number_type_id(void) { - return (b_object_type_id)&number_type; + return (b_dsref_type_id)&number_type; } diff --git a/object/number.h b/ds/number.h similarity index 87% rename from object/number.h rename to ds/number.h index fe29158..161b4c3 100644 --- a/object/number.h +++ b/ds/number.h @@ -3,10 +3,10 @@ #include "object.h" -#include +#include struct b_number { - struct b_object n_base; + struct b_dsref n_base; b_number_type n_type; union { int8_t v_int8; diff --git a/object/object.c b/ds/object.c similarity index 56% rename from object/object.c rename to ds/object.c index 812e9c4..b087d0f 100644 --- a/object/object.c +++ b/ds/object.c @@ -1,31 +1,31 @@ #include "object.h" #include -#include -#include -#include +#include +#include +#include #include #include -void b_object_init(struct b_object *obj, struct b_object_type *type) +void b_dsref_init(struct b_dsref *obj, struct b_dsref_type *type) { obj->ob_ref = 1; obj->ob_type = type; } -struct b_object *b_make_rvalue(struct b_object *obj) +struct b_dsref *b_make_rvalue(struct b_dsref *obj) { obj->ob_ref = 0; return obj; } -struct b_object *b_retain(struct b_object *obj) +struct b_dsref *b_retain(struct b_dsref *obj) { obj->ob_ref++; return obj; } -void b_release(struct b_object *obj) +void b_release(struct b_dsref *obj) { if (obj->ob_ref > 1) { obj->ob_ref--; @@ -41,7 +41,7 @@ void b_release(struct b_object *obj) free(obj); } -void b_to_string(struct b_object *obj, struct b_stream *out) +void b_to_string(struct b_dsref *obj, struct b_stream *out) { if (obj->ob_type->t_to_string) { obj->ob_type->t_to_string(obj, out); @@ -56,11 +56,11 @@ void b_to_string(struct b_object *obj, struct b_stream *out) b_stream_write_fmt(out, NULL, "<%s@%p>", name, obj); } -b_object_type_id b_typeid(const struct b_object *obj) +b_dsref_type_id b_typeid(const struct b_dsref *obj) { - if (obj->ob_type->t_flags & B_OBJECT_FUNDAMENTAL) { + if (obj->ob_type->t_flags & B_DSREF_FUNDAMENTAL) { return obj->ob_type->t_id; } - return (b_object_type_id)obj->ob_type; + return (b_dsref_type_id)obj->ob_type; } diff --git a/ds/object.h b/ds/object.h new file mode 100644 index 0000000..8cedfcc --- /dev/null +++ b/ds/object.h @@ -0,0 +1,6 @@ +#ifndef _BLUELIB_DSREF_H_ +#define _BLUELIB_DSREF_H_ + +#include + +#endif diff --git a/object/string.c b/ds/string.c similarity index 95% rename from object/string.c rename to ds/string.c index d948a29..b644535 100644 --- a/object/string.c +++ b/ds/string.c @@ -2,8 +2,8 @@ #include #include -#include -#include +#include +#include #include #include #include @@ -11,13 +11,13 @@ #include #include -static void string_release(struct b_object *obj); -static void string_to_string(struct b_object *obj, struct b_stream *out); +static void string_release(struct b_dsref *obj); +static void string_to_string(struct b_dsref *obj, struct b_stream *out); -static struct b_object_type string_type = { +static struct b_dsref_type string_type = { .t_name = "corelib::string", - .t_flags = B_OBJECT_FUNDAMENTAL, - .t_id = B_OBJECT_TYPE_STRING, + .t_flags = B_DSREF_FUNDAMENTAL, + .t_id = B_DSREF_TYPE_STRING, .t_instance_size = sizeof(struct b_string), .t_release = string_release, .t_to_string = string_to_string, @@ -26,7 +26,7 @@ static struct b_object_type string_type = { struct b_string *b_string_create(void) { struct b_string *str - = (struct b_string *)b_object_type_instantiate(&string_type); + = (struct b_string *)b_dsref_type_instantiate(&string_type); if (!str) { return NULL; } @@ -613,7 +613,7 @@ struct b_string *b_string_substr(const struct b_string *str, size_t start, size_ return newstr; } -static void string_release(struct b_object *obj) +static void string_release(struct b_dsref *obj) { struct b_string *str = B_STRING(obj); if (!string_is_inline(str)) { @@ -621,7 +621,7 @@ static void string_release(struct b_object *obj) } } -static void string_to_string(struct b_object *obj, struct b_stream *out) +static void string_to_string(struct b_dsref *obj, struct b_stream *out) { b_string *str = B_STRING(obj); b_stream_write_fmt(out, NULL, "%s", b_string_ptr(str)); @@ -677,7 +677,7 @@ size_t b_strlen(const char *s, b_strlen_flags flags) return out; } -b_object_type_id b_string_type_id(void) +b_dsref_type_id b_string_type_id(void) { - return (b_object_type_id)&string_type; + return (b_dsref_type_id)&string_type; } diff --git a/object/string.h b/ds/string.h similarity index 95% rename from object/string.h rename to ds/string.h index fecf196..85d1428 100644 --- a/object/string.h +++ b/ds/string.h @@ -7,7 +7,7 @@ #define STRING_INLINE_CAPACITY 15 struct b_string { - struct b_object s_base; + struct b_dsref s_base; /* length of string, not including null-terminator */ unsigned int s_len; /* maximum length of string storable in the currently-allocated buffer, not including null terminator */ diff --git a/object/tree.c b/ds/tree.c similarity index 94% rename from object/tree.c rename to ds/tree.c index 90c47ce..24f2229 100644 --- a/object/tree.c +++ b/ds/tree.c @@ -1,8 +1,8 @@ #include "tree.h" -#include -#include -#include +#include +#include +#include #include #include @@ -16,17 +16,17 @@ #define NODE_FIRST_CHILD(n) ((n)->__p02) #define NODE_NEXT_SIBLING(n) ((n)->__p03) -static struct b_object_type tree_type = { +static struct b_dsref_type tree_type = { .t_name = "corelib::tree", - .t_flags = B_OBJECT_FUNDAMENTAL, - .t_id = B_OBJECT_TYPE_TREE, + .t_flags = B_DSREF_FUNDAMENTAL, + .t_id = B_DSREF_TYPE_TREE, .t_instance_size = sizeof(struct b_tree), }; struct b_tree *b_tree_create(void) { struct b_tree *tree - = (struct b_tree *)b_object_type_instantiate(&tree_type); + = (struct b_tree *)b_dsref_type_instantiate(&tree_type); if (!tree) { return NULL; } @@ -294,7 +294,7 @@ bool b_tree_iterator_is_valid(const struct b_tree_iterator *it) return it->node != NULL; } -b_object_type_id b_tree_type_id(void) +b_dsref_type_id b_tree_type_id(void) { - return (b_object_type_id)&tree_type; + return (b_dsref_type_id)&tree_type; } diff --git a/object/tree.h b/ds/tree.h similarity index 73% rename from object/tree.h rename to ds/tree.h index f9cc809..8db19b4 100644 --- a/object/tree.h +++ b/ds/tree.h @@ -4,10 +4,10 @@ #include "../object.h" #include -#include +#include struct b_tree { - struct b_object t_base; + struct b_dsref t_base; struct b_tree_node *t_root; }; diff --git a/object/type.c b/ds/type.c similarity index 56% rename from object/type.c rename to ds/type.c index 2532a49..7ffd3a9 100644 --- a/object/type.c +++ b/ds/type.c @@ -1,17 +1,17 @@ #include "object.h" #include -#include +#include #include #include -struct b_object *b_object_type_instantiate(const b_object_type *type) +struct b_dsref *b_dsref_type_instantiate(const b_dsref_type *type) { - if (!type || type->t_instance_size < sizeof(struct b_object)) { + if (!type || type->t_instance_size < sizeof(struct b_dsref)) { return NULL; } - struct b_object *out = malloc(type->t_instance_size); + struct b_dsref *out = malloc(type->t_instance_size); if (!out) { return NULL; } diff --git a/object/uuid.c b/ds/uuid.c similarity index 92% rename from object/uuid.c rename to ds/uuid.c index 60863f5..289e29a 100644 --- a/object/uuid.c +++ b/ds/uuid.c @@ -1,25 +1,25 @@ #include "uuid.h" #include -#include -#include -#include +#include +#include +#include #include #include #include #include -static struct b_object_type uuid_type = { +static struct b_dsref_type uuid_type = { .t_name = "corelib::uuid", - .t_flags = B_OBJECT_FUNDAMENTAL, - .t_id = B_OBJECT_TYPE_UUID, + .t_flags = B_DSREF_FUNDAMENTAL, + .t_id = B_DSREF_TYPE_UUID, .t_instance_size = sizeof(struct b_uuid), }; struct b_uuid *b_uuid_create(void) { struct b_uuid *out - = (struct b_uuid *)b_object_type_instantiate(&uuid_type); + = (struct b_uuid *)b_dsref_type_instantiate(&uuid_type); if (!out) { return NULL; } @@ -192,7 +192,7 @@ struct b_uuid_bytes *b_uuid_ptr(struct b_uuid *uuid) return &uuid->uuid_bytes; } -b_object_type_id b_uuid_type_id(void) +b_dsref_type_id b_uuid_type_id(void) { - return (b_object_type_id)&uuid_type; + return (b_dsref_type_id)&uuid_type; } diff --git a/object/uuid.h b/ds/uuid.h similarity index 67% rename from object/uuid.h rename to ds/uuid.h index 6a1bde6..74ca5ca 100644 --- a/object/uuid.h +++ b/ds/uuid.h @@ -1,10 +1,10 @@ #ifndef _BLUELIB_UUID_H_ #define _BLUELIB_UUID_H_ -#include +#include struct b_uuid { - struct b_object u_base; + struct b_dsref u_base; struct b_uuid_bytes uuid_bytes; }; diff --git a/io-test/io-units.c b/io-test/io-units.c index b264ab5..0fa8fb1 100644 --- a/io-test/io-units.c +++ b/io-test/io-units.c @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include void test_path_1(CuTest *tc) @@ -11,7 +11,7 @@ void test_path_1(CuTest *tc) b_stringstream str; b_stringstream_begin(&str, buf, sizeof buf); - b_to_string(B_OBJECT(path), (b_stream *)&str); + b_to_string(B_DSREF(path), (b_stream *)&str); printf("%s\n", buf); @@ -23,7 +23,7 @@ void test_path_1(CuTest *tc) b_path *path4 = b_path_join(paths, sizeof paths / sizeof paths[0]); b_stringstream_begin(&str, buf, sizeof buf); - b_to_string(B_OBJECT(path4), (b_stream *)&str); + b_to_string(B_DSREF(path4), (b_stream *)&str); printf("%s\n", buf); } diff --git a/io/CMakeLists.txt b/io/CMakeLists.txt index 7887d12..c79fe14 100644 --- a/io/CMakeLists.txt +++ b/io/CMakeLists.txt @@ -1,3 +1,3 @@ include(../cmake/Templates.cmake) -add_bluelib_module(NAME io DEPENDENCIES core object) +add_bluelib_module(NAME io DEPENDENCIES core ds) diff --git a/io/include/blue/io/directory.h b/io/include/blue/io/directory.h index cd5c508..db7a081 100644 --- a/io/include/blue/io/directory.h +++ b/io/include/blue/io/directory.h @@ -69,12 +69,12 @@ BLUE_API bool b_directory_iterator_is_valid(const b_directory_iterator *it); static inline b_directory *b_directory_retain(b_directory *dir) { - return B_DIRECTORY(b_retain(B_OBJECT(dir))); + return B_DIRECTORY(b_retain(B_DSREF(dir))); } static inline void b_directory_release(b_directory *dir) { - b_release(B_OBJECT(dir)); + b_release(B_DSREF(dir)); } #endif diff --git a/io/include/blue/io/file.h b/io/include/blue/io/file.h index bcf801d..d11cc74 100644 --- a/io/include/blue/io/file.h +++ b/io/include/blue/io/file.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include #define B_FILE(p) ((b_file *)(p)) @@ -73,11 +73,11 @@ BLUE_API b_status b_file_write( static inline b_file *b_file_retain(b_file *file) { - return B_FILE(b_retain(B_OBJECT(file))); + return B_FILE(b_retain(B_DSREF(file))); } static inline void b_file_release(b_file *file) { - b_release(B_OBJECT(file)); + b_release(B_DSREF(file)); } #endif diff --git a/io/include/blue/io/path.h b/io/include/blue/io/path.h index d33a03c..2d70fb5 100644 --- a/io/include/blue/io/path.h +++ b/io/include/blue/io/path.h @@ -3,7 +3,7 @@ #include #include -#include +#include #include #define B_PATH(p) ((b_path *)p) @@ -43,12 +43,12 @@ BLUE_API size_t b_path_length(const b_path *path); static inline b_path *b_path_retain(b_path *path) { - return B_PATH(b_retain(B_OBJECT(path))); + return B_PATH(b_retain(B_DSREF(path))); } static inline void b_path_release(b_path *path) { - b_release(B_OBJECT(path)); + b_release(B_DSREF(path)); } #endif diff --git a/io/sys/darwin/directory.c b/io/sys/darwin/directory.c index b8d4b08..1928060 100644 --- a/io/sys/darwin/directory.c +++ b/io/sys/darwin/directory.c @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include #include @@ -17,7 +17,7 @@ enum directory_flags { }; struct b_directory { - struct b_object base; + struct b_dsref base; enum directory_flags flags; int fd; struct b_path *rel_path; @@ -29,12 +29,12 @@ struct z__b_directory_iterator { FTSENT *ent; }; -static void directory_release(struct b_object *obj); +static void directory_release(struct b_dsref *obj); -static struct b_object_type directory_type = { +static struct b_dsref_type directory_type = { .t_name = "corelib::directory", - .t_flags = B_OBJECT_FUNDAMENTAL, - .t_id = B_OBJECT_TYPE_PATH, + .t_flags = B_DSREF_FUNDAMENTAL, + .t_id = B_DSREF_TYPE_PATH, .t_instance_size = sizeof(struct b_directory), .t_release = directory_release, }; @@ -133,7 +133,7 @@ b_result b_directory_open( } struct b_directory *dir - = (struct b_directory *)b_object_type_instantiate(&directory_type); + = (struct b_directory *)b_dsref_type_instantiate(&directory_type); struct b_path *cwd = NULL; @@ -579,7 +579,7 @@ bool b_directory_iterator_is_valid(const struct b_directory_iterator *it) return true; } -static void directory_release(struct b_object *obj) +static void directory_release(struct b_dsref *obj) { struct b_directory *dir = B_DIRECTORY(obj); diff --git a/io/sys/darwin/file.c b/io/sys/darwin/file.c index 7d8a7d8..5a21c14 100644 --- a/io/sys/darwin/file.c +++ b/io/sys/darwin/file.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include #include @@ -15,18 +15,18 @@ #include struct b_file { - struct b_object base; + struct b_dsref base; enum b_file_mode mode; int fd; struct b_path *path; }; -static void file_release(struct b_object *obj); +static void file_release(struct b_dsref *obj); -static struct b_object_type file_type = { +static struct b_dsref_type file_type = { .t_name = "corelib::file", - .t_flags = B_OBJECT_FUNDAMENTAL, - .t_id = B_OBJECT_TYPE_FILE, + .t_flags = B_DSREF_FUNDAMENTAL, + .t_id = B_DSREF_TYPE_FILE, .t_instance_size = sizeof(struct b_file), .t_release = file_release, }; @@ -104,7 +104,7 @@ b_result b_file_open( } struct b_file *file - = (struct b_file *)b_object_type_instantiate(&file_type); + = (struct b_file *)b_dsref_type_instantiate(&file_type); if (!file) { close(fd); b_path_release(abs_path); @@ -482,7 +482,7 @@ enum b_status b_file_write( return status; } -static void file_release(struct b_object *obj) +static void file_release(struct b_dsref *obj) { struct b_file *file = (struct b_file *)obj; close(file->fd); diff --git a/io/sys/darwin/path.c b/io/sys/darwin/path.c index ff098d1..24e95b0 100644 --- a/io/sys/darwin/path.c +++ b/io/sys/darwin/path.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include @@ -13,17 +13,17 @@ #include struct b_path { - struct b_object base; + struct b_dsref base; struct b_string *pathstr; }; -static void path_release(struct b_object *obj); -static void path_to_string(struct b_object *obj, struct b_stream *out); +static void path_release(struct b_dsref *obj); +static void path_to_string(struct b_dsref *obj, struct b_stream *out); -static struct b_object_type path_type = { +static struct b_dsref_type path_type = { .t_name = "corelib::path", - .t_flags = B_OBJECT_FUNDAMENTAL, - .t_id = B_OBJECT_TYPE_PATH, + .t_flags = B_DSREF_FUNDAMENTAL, + .t_id = B_DSREF_TYPE_PATH, .t_instance_size = sizeof(struct b_path), .t_release = path_release, .t_to_string = path_to_string, @@ -32,7 +32,7 @@ static struct b_object_type path_type = { struct b_path *b_path_create() { struct b_path *path - = (struct b_path *)b_object_type_instantiate(&path_type); + = (struct b_path *)b_dsref_type_instantiate(&path_type); if (!path) { return NULL; } @@ -305,14 +305,14 @@ size_t b_path_length(const struct b_path *path) return b_string_get_size(path->pathstr, B_STRLEN_NORMAL); } -void path_release(struct b_object *obj) +void path_release(struct b_dsref *obj) { struct b_path *path = (struct b_path *)obj; b_string_release(path->pathstr); } -void path_to_string(struct b_object *obj, struct b_stream *out) +void path_to_string(struct b_dsref *obj, struct b_stream *out) { struct b_path *path = (struct b_path *)obj; diff --git a/io/sys/windows/directory.c b/io/sys/windows/directory.c index 5245a6e..047bb34 100644 --- a/io/sys/windows/directory.c +++ b/io/sys/windows/directory.c @@ -6,7 +6,7 @@ #include struct b_directory { - struct b_object base; + struct b_dsref base; HANDLE handle; struct b_path *abs_path; }; @@ -23,12 +23,12 @@ struct iteration_state { bool child_search_complete; }; -static void directory_release(struct b_object *obj); +static void directory_release(struct b_dsref *obj); -static struct b_object_type directory_type = { +static struct b_dsref_type directory_type = { .t_name = "corelib::directory", - .t_flags = B_OBJECT_FUNDAMENTAL, - .t_id = B_OBJECT_TYPE_PATH, + .t_flags = B_DSREF_FUNDAMENTAL, + .t_id = B_DSREF_TYPE_PATH, .t_instance_size = sizeof(struct b_directory), .t_release = directory_release, }; @@ -89,7 +89,7 @@ enum b_status b_directory_open( } struct b_directory *dir - = (struct b_directory *)b_object_type_instantiate(&directory_type); + = (struct b_directory *)b_dsref_type_instantiate(&directory_type); if (!path) { CloseHandle(dir_handle); b_path_release(new_path); @@ -361,6 +361,6 @@ bool b_directory_iterator_is_valid(const struct b_directory_iterator *it) return true; } -static void directory_release(struct b_object *obj) +static void directory_release(struct b_dsref *obj) { } diff --git a/io/sys/windows/path.c b/io/sys/windows/path.c index ee5822a..33473c9 100644 --- a/io/sys/windows/path.c +++ b/io/sys/windows/path.c @@ -2,24 +2,24 @@ #include #include -#include +#include #include #include #include #include struct b_path { - struct b_object base; + struct b_dsref base; struct b_string *pathstr; }; -static void path_release(struct b_object *obj); -static void path_to_string(struct b_object *obj, struct b_stringstream *out); +static void path_release(struct b_dsref *obj); +static void path_to_string(struct b_dsref *obj, struct b_stringstream *out); -static struct b_object_type path_type = { +static struct b_dsref_type path_type = { .t_name = "corelib::path", - .t_flags = B_OBJECT_FUNDAMENTAL, - .t_id = B_OBJECT_TYPE_PATH, + .t_flags = B_DSREF_FUNDAMENTAL, + .t_id = B_DSREF_TYPE_PATH, .t_instance_size = sizeof(struct b_path), .t_release = path_release, .t_to_string = path_to_string, @@ -28,7 +28,7 @@ static struct b_object_type path_type = { struct b_path *b_path_create() { struct b_path *path - = (struct b_path *)b_object_type_instantiate(&path_type); + = (struct b_path *)b_dsref_type_instantiate(&path_type); if (!path) { return NULL; } @@ -234,13 +234,13 @@ const char *b_path_ptr(const struct b_path *path) return b_string_ptr(path->pathstr); } -void path_release(struct b_object* obj) +void path_release(struct b_dsref* obj) { struct b_path *path = B_PATH(obj); b_string_release(path->pathstr); } -void path_to_string(struct b_object* obj, struct b_stringstream* out) +void path_to_string(struct b_dsref* obj, struct b_stringstream* out) { struct b_path *path = (struct b_path *)obj; diff --git a/object/CMakeLists.txt b/object/CMakeLists.txt deleted file mode 100644 index 905e9c0..0000000 --- a/object/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -include(../cmake/Templates.cmake) - -add_bluelib_module(NAME object DEPENDENCIES core) diff --git a/object/include/blue/object/object.h b/object/include/blue/object/object.h deleted file mode 100644 index 185d6ff..0000000 --- a/object/include/blue/object/object.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef BLUELIB_OBJECT_H_ -#define BLUELIB_OBJECT_H_ - -#include - -#define B_OBJECT(p) ((b_object *)(p)) - -#define B_TYPEOF(object) ((struct b_object *)(object)->ob_type) -#define B_TYPEID(object) (b_typeid(B_OBJECT(object))) - -#define B_RV(p) (b_make_rvalue(B_OBJECT(p))) -#define B_RVT(t, p) ((t *)(b_make_rvalue(B_OBJECT(p)))) - -#define B_OBJECT_IS(object, type) (B_TYPEID(object) == B_OBJECT_TYPE_##type) - -struct b_string; -struct b_stream; - -typedef enum b_comparison_result { - B_LESS = -1, - B_EQUAL = 0, - B_GREATER = 1, -} b_comparison_result_t; - -typedef struct b_object { - unsigned int ob_ref; - const struct b_object_type *ob_type; -} b_object; - -BLUE_API b_object *b_make_rvalue(b_object *obj); - -BLUE_API b_object *b_retain(b_object *obj); -BLUE_API void b_release(b_object *obj); - -BLUE_API void b_to_string(b_object *obj, struct b_stream *out); -BLUE_API b_object_type_id b_typeid(const b_object *obj); - -BLUE_API b_comparison_result_t b_compare(const b_object *a, const b_object *b); - -#endif diff --git a/object/include/blue/object/type.h b/object/include/blue/object/type.h deleted file mode 100644 index b45c200..0000000 --- a/object/include/blue/object/type.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef BLUELIB_TYPE_H_ -#define BLUELIB_TYPE_H_ - -#include -#include -#include -#include -#include - -#define B_NPOS ((size_t)INTPTR_MAX) - -struct b_object; -struct b_stream; - -typedef uintptr_t b_object_type_id; - -typedef enum b_fundamental_type_id { - B_OBJECT_TYPE_NONE = 0, - B_OBJECT_TYPE_ANY, - B_OBJECT_TYPE_LIST, - B_OBJECT_TYPE_ARRAY, - B_OBJECT_TYPE_BUFFER, - B_OBJECT_TYPE_DICT, - B_OBJECT_TYPE_ERROR, - B_OBJECT_TYPE_HASHMAP, - B_OBJECT_TYPE_NUMBER, - B_OBJECT_TYPE_STRING, - B_OBJECT_TYPE_TREE, - B_OBJECT_TYPE_UUID, - B_OBJECT_TYPE_PATH, - B_OBJECT_TYPE_FILE, - B_OBJECT_TYPE_DIRECTORY, -} b_fundamental_type_id; - -typedef enum b_object_type_flags { - B_OBJECT_FUNDAMENTAL = 0x01u, -} b_object_type_flags; - -typedef struct b_object_type { - b_object_type_flags t_flags; - char t_name[64]; - size_t t_instance_size; - b_object_type_id t_id; - b_queue_entry t_entry; - void (*t_init)(struct b_object *); - void (*t_release)(struct b_object *); - void (*t_to_string)(struct b_object *, struct b_stream *); -} b_object_type; - -BLUE_API b_status b_object_type_register(b_object_type *type); -BLUE_API struct b_object *b_object_type_instantiate(const b_object_type *type); - -#endif diff --git a/object/object.h b/object/object.h deleted file mode 100644 index 251efc5..0000000 --- a/object/object.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _BLUELIB_OBJECT_H_ -#define _BLUELIB_OBJECT_H_ - -#include - -#endif diff --git a/serial-test/streams.c b/serial-test/streams.c index ac7b6b7..e5844da 100644 --- a/serial-test/streams.c +++ b/serial-test/streams.c @@ -1,8 +1,8 @@ #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include @@ -26,11 +26,11 @@ int main(void) b_dict_put(dict, "strings", B_RV(array)); - b_to_string(B_OBJECT(dict), b_stdout); + b_to_string(B_DSREF(dict), b_stdout); b_stream_write_char(b_stdout, '\n'); b_serial_ctx_serialise( - ctx, B_SERIAL_FORMAT_JSON, B_OBJECT(dict), b_stdout, 0); + ctx, B_SERIAL_FORMAT_JSON, B_DSREF(dict), b_stdout, 0); b_dict_release(dict); b_serial_ctx_destroy(ctx); diff --git a/serial/CMakeLists.txt b/serial/CMakeLists.txt index 25fdef4..6fbd8a5 100644 --- a/serial/CMakeLists.txt +++ b/serial/CMakeLists.txt @@ -1,3 +1,3 @@ include(../cmake/Templates.cmake) -add_bluelib_module(NAME serial DEPENDENCIES core object) +add_bluelib_module(NAME serial DEPENDENCIES core ds) diff --git a/serial/include/blue/serial.h b/serial/include/blue/serial.h index 8db05db..300cd7f 100644 --- a/serial/include/blue/serial.h +++ b/serial/include/blue/serial.h @@ -5,7 +5,7 @@ #include #include -struct b_object; +struct b_dsref; typedef enum b_serial_format { B_SERIAL_FORMAT_NONE = 0, @@ -24,11 +24,11 @@ BLUE_API b_status b_serial_ctx_create(b_serial_ctx **out); BLUE_API b_status b_serial_ctx_destroy(b_serial_ctx *ctx); BLUE_API b_status b_serial_ctx_serialise( - b_serial_ctx *ctx, b_serial_format fmt, struct b_object *src, + b_serial_ctx *ctx, b_serial_format fmt, struct b_dsref *src, b_stream *dest, b_serial_flags flags); BLUE_API b_status b_serial_ctx_deserialise( b_serial_ctx *ctx, b_serial_format fmt, b_stream *src, - struct b_object **dest, b_serial_flags flags); + struct b_dsref **dest, b_serial_flags flags); #endif diff --git a/serial/json.c b/serial/json.c index c73e15e..9fe23d1 100644 --- a/serial/json.c +++ b/serial/json.c @@ -37,12 +37,12 @@ #pragma warning(disable : 4001) #endif -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -2933,9 +2933,9 @@ CJSON_PUBLIC(void) cJSON_free(void *object) object = NULL; } -static enum b_status b_object_to_cJSON(const struct b_object *object, cJSON **out); +static enum b_status b_dsref_to_cJSON(const struct b_dsref *object, cJSON **out); -static enum b_status serialise_array(const struct b_object *object, cJSON **out) +static enum b_status serialise_array(const struct b_dsref *object, cJSON **out) { cJSON *json_array = cJSON_CreateArray(); if (!json_array) { @@ -2947,7 +2947,7 @@ static enum b_status serialise_array(const struct b_object *object, cJSON **out) b_array_foreach(&it, array) { cJSON *child = NULL; - enum b_status status = b_object_to_cJSON(it.value, &child); + enum b_status status = b_dsref_to_cJSON(it.value, &child); if (!B_OK(status)) { cJSON_Delete(json_array); return status; @@ -2960,7 +2960,7 @@ static enum b_status serialise_array(const struct b_object *object, cJSON **out) return B_SUCCESS; } -static enum b_status serialise_dict(const struct b_object *object, cJSON **out) +static enum b_status serialise_dict(const struct b_dsref *object, cJSON **out) { cJSON *json_dict = cJSON_CreateObject(); if (!json_dict) { @@ -2972,7 +2972,7 @@ static enum b_status serialise_dict(const struct b_object *object, cJSON **out) b_dict_foreach(&it, dict) { cJSON *child = NULL; - enum b_status status = b_object_to_cJSON(it.value, &child); + enum b_status status = b_dsref_to_cJSON(it.value, &child); if (!B_OK(status)) { cJSON_Delete(json_dict); return status; @@ -2985,7 +2985,7 @@ static enum b_status serialise_dict(const struct b_object *object, cJSON **out) return B_SUCCESS; } -static enum b_status serialise_number(const struct b_object *object, cJSON **out) +static enum b_status serialise_number(const struct b_dsref *object, cJSON **out) { cJSON *json_number = cJSON_CreateNumber(0); if (!json_number) { @@ -3049,7 +3049,7 @@ static enum b_status serialise_number(const struct b_object *object, cJSON **out return B_SUCCESS; } -static enum b_status serialise_string(const struct b_object *object, cJSON **out) +static enum b_status serialise_string(const struct b_dsref *object, cJSON **out) { struct b_string *string = B_STRING(object); cJSON *json_string = cJSON_CreateStringReference(b_string_ptr(string)); @@ -3061,7 +3061,7 @@ static enum b_status serialise_string(const struct b_object *object, cJSON **out return B_SUCCESS; } -static enum b_status serialise_uuid(const struct b_object *object, cJSON **out) +static enum b_status serialise_uuid(const struct b_dsref *object, cJSON **out) { struct b_uuid *uuid = B_UUID(object); char s[B_UUID_STRING_MAX]; @@ -3077,21 +3077,21 @@ static enum b_status serialise_uuid(const struct b_object *object, cJSON **out) } typedef enum b_status (*object_serialise_callback)( - const struct b_object *, cJSON **); + const struct b_dsref *, cJSON **); static const object_serialise_callback object_serialise[] = { - [B_OBJECT_TYPE_ARRAY] = serialise_array, - [B_OBJECT_TYPE_DICT] = serialise_dict, - [B_OBJECT_TYPE_NUMBER] = serialise_number, - [B_OBJECT_TYPE_STRING] = serialise_string, - [B_OBJECT_TYPE_UUID] = serialise_uuid, + [B_DSREF_TYPE_ARRAY] = serialise_array, + [B_DSREF_TYPE_DICT] = serialise_dict, + [B_DSREF_TYPE_NUMBER] = serialise_number, + [B_DSREF_TYPE_STRING] = serialise_string, + [B_DSREF_TYPE_UUID] = serialise_uuid, }; static const size_t nr_object_serialise = sizeof object_serialise / sizeof object_serialise[0]; -static enum b_status b_object_to_cJSON(const struct b_object *object, cJSON **out) +static enum b_status b_dsref_to_cJSON(const struct b_dsref *object, cJSON **out) { - b_object_type_id type = b_typeid(object); + b_dsref_type_id type = b_typeid(object); if (type >= nr_object_serialise) { return B_ERR_NOT_SUPPORTED; } @@ -3104,9 +3104,9 @@ static enum b_status b_object_to_cJSON(const struct b_object *object, cJSON **ou return callback(object, out); } -static enum b_status cJSON_to_b_object(cJSON *json, struct b_object **out); +static enum b_status cJSON_to_b_dsref(cJSON *json, struct b_dsref **out); -static enum b_status deserialise_dict(cJSON *json, struct b_object **out) +static enum b_status deserialise_dict(cJSON *json, struct b_dsref **out) { struct b_dict *dict = b_dict_create(); if (!dict) { @@ -3117,8 +3117,8 @@ static enum b_status deserialise_dict(cJSON *json, struct b_object **out) enum b_status status = B_SUCCESS; while (item) { - struct b_object *child = NULL; - status = cJSON_to_b_object(item, &child); + struct b_dsref *child = NULL; + status = cJSON_to_b_dsref(item, &child); if (!B_OK(status)) { b_dict_release(dict); dict = NULL; @@ -3133,11 +3133,11 @@ static enum b_status deserialise_dict(cJSON *json, struct b_object **out) item = item->next; } - *out = B_OBJECT(dict); + *out = B_DSREF(dict); return B_SUCCESS; } -static enum b_status deserialise_array(cJSON *json, struct b_object **out) +static enum b_status deserialise_array(cJSON *json, struct b_dsref **out) { struct b_array *array = b_array_create(); if (!array) { @@ -3148,8 +3148,8 @@ static enum b_status deserialise_array(cJSON *json, struct b_object **out) enum b_status status = B_SUCCESS; while (item) { - struct b_object *child = NULL; - status = cJSON_to_b_object(item, &child); + struct b_dsref *child = NULL; + status = cJSON_to_b_dsref(item, &child); if (!B_OK(status)) { b_array_release(array); array = NULL; @@ -3164,22 +3164,22 @@ static enum b_status deserialise_array(cJSON *json, struct b_object **out) item = item->next; } - *out = B_OBJECT(array); + *out = B_DSREF(array); return B_SUCCESS; } -static enum b_status deserialise_string(cJSON *json, struct b_object **out) +static enum b_status deserialise_string(cJSON *json, struct b_dsref **out) { struct b_string *string = b_string_create_from_cstr(json->valuestring); if (!string) { return B_ERR_NO_MEMORY; } - *out = B_OBJECT(string); + *out = B_DSREF(string); return B_SUCCESS; } -static enum b_status deserialise_number(cJSON *json, struct b_object **out) +static enum b_status deserialise_number(cJSON *json, struct b_dsref **out) { struct b_number *number = NULL; @@ -3193,11 +3193,11 @@ static enum b_status deserialise_number(cJSON *json, struct b_object **out) return B_ERR_NO_MEMORY; } - *out = B_OBJECT(number); + *out = B_DSREF(number); return B_SUCCESS; } -static enum b_status deserialise_bool(cJSON *json, struct b_object **out) +static enum b_status deserialise_bool(cJSON *json, struct b_dsref **out) { struct b_number *number = NULL; @@ -3211,11 +3211,11 @@ static enum b_status deserialise_bool(cJSON *json, struct b_object **out) return B_ERR_NO_MEMORY; } - *out = B_OBJECT(number); + *out = B_DSREF(number); return B_SUCCESS; } -static enum b_status cJSON_to_b_object(cJSON *json, struct b_object **out) +static enum b_status cJSON_to_b_dsref(cJSON *json, struct b_dsref **out) { switch (json->type) { case cJSON_True: @@ -3238,11 +3238,11 @@ static enum b_status cJSON_to_b_object(cJSON *json, struct b_object **out) } static enum b_status json_serialise( - struct b_serial_ctx *ctx, struct b_object *src, struct b_stream *dest, + struct b_serial_ctx *ctx, struct b_dsref *src, struct b_stream *dest, enum b_serial_flags flags) { cJSON *json; - enum b_status status = b_object_to_cJSON(src, &json); + enum b_status status = b_dsref_to_cJSON(src, &json); if (!B_OK(status)) { return status; @@ -3269,7 +3269,7 @@ static enum b_status json_serialise( } static enum b_status json_deserialise( - struct b_serial_ctx *ctx, struct b_stream *src, struct b_object **dest, + struct b_serial_ctx *ctx, struct b_stream *src, struct b_dsref **dest, enum b_serial_flags flags) { struct b_string *json_string = b_string_create(); @@ -3294,7 +3294,7 @@ static enum b_status json_deserialise( return B_ERR_BAD_FORMAT; } - status = cJSON_to_b_object(json, dest); + status = cJSON_to_b_dsref(json, dest); cJSON_Delete(json); diff --git a/serial/serial.c b/serial/serial.c index 07df3b0..cf77d6d 100644 --- a/serial/serial.c +++ b/serial/serial.c @@ -51,7 +51,7 @@ static const struct b_serial_format_ops *get_formatter(enum b_serial_format fmt) enum b_status b_serial_ctx_serialise( struct b_serial_ctx *ctx, enum b_serial_format fmt, - struct b_object *src, struct b_stream *dest, enum b_serial_flags flags) + struct b_dsref *src, struct b_stream *dest, enum b_serial_flags flags) { const struct b_serial_format_ops *ops = get_formatter(fmt); if (!ops) { @@ -67,7 +67,7 @@ enum b_status b_serial_ctx_serialise( enum b_status b_serial_ctx_deserialise( struct b_serial_ctx *ctx, enum b_serial_format fmt, - struct b_stream *src, struct b_object **dest, enum b_serial_flags flags) + struct b_stream *src, struct b_dsref **dest, enum b_serial_flags flags) { const struct b_serial_format_ops *ops = get_formatter(fmt); if (!ops) { diff --git a/serial/serial.h b/serial/serial.h index 69d39d1..309bc39 100644 --- a/serial/serial.h +++ b/serial/serial.h @@ -10,10 +10,10 @@ struct b_serial_ctx { struct b_serial_format_ops { enum b_status (*fmt_serialise)( - struct b_serial_ctx *, struct b_object *, struct b_stream *, + struct b_serial_ctx *, struct b_dsref *, struct b_stream *, enum b_serial_flags); enum b_status (*fmt_deserialise)( - struct b_serial_ctx *, struct b_stream *, struct b_object **, + struct b_serial_ctx *, struct b_stream *, struct b_dsref **, enum b_serial_flags); }; diff --git a/term-test/printing.c b/term-test/printing.c index bdc4e37..95cf086 100644 --- a/term-test/printing.c +++ b/term-test/printing.c @@ -1,6 +1,6 @@ #include #include -#include +#include #include #define F_GREEN "[green]" diff --git a/term/CMakeLists.txt b/term/CMakeLists.txt index fb097cd..1581e77 100644 --- a/term/CMakeLists.txt +++ b/term/CMakeLists.txt @@ -1,3 +1,3 @@ include(../cmake/Templates.cmake) -add_bluelib_module(NAME term DEPENDENCIES core object) +add_bluelib_module(NAME term DEPENDENCIES core ds) diff --git a/term/paragraph.c b/term/paragraph.c index c0c7cc7..e37f5b1 100644 --- a/term/paragraph.c +++ b/term/paragraph.c @@ -1,6 +1,6 @@ #include "print.h" -#include +#include #include #include #include diff --git a/test/cat.c b/test/cat.c index 6c8ffd4..40ec02f 100644 --- a/test/cat.c +++ b/test/cat.c @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include int main(int argc, const char **argv) diff --git a/test/json-read.c b/test/json-read.c index 6c84c91..407b5e1 100644 --- a/test/json-read.c +++ b/test/json-read.c @@ -26,7 +26,7 @@ int main(int argc, const char **argv) b_serial_ctx *ctx; b_serial_ctx_create(&ctx); - b_object *data; + b_dsref *data; b_status status = b_serial_ctx_deserialise( ctx, B_SERIAL_FORMAT_JSON, src_stream, &data, 0); if (!B_OK(status)) { @@ -34,7 +34,7 @@ int main(int argc, const char **argv) return -1; } - b_to_string(B_OBJECT(data), b_stdout); + b_to_string(B_DSREF(data), b_stdout); b_stream_write_char(b_stdout, '\n'); b_release(data);