From de65adbc1b2d1b3efdbe6a023bb7435f84b2f3a7 Mon Sep 17 00:00:00 2001 From: nodist Date: Sat, 3 Oct 2026 08:50:07 -0400 Subject: redesign --- include/kpl/code.h | 25 ----------- include/kpl/color.h | 119 -------------------------------------------------- include/kpl/io.h | 25 ----------- include/kpl/macro.h | 15 ------- include/kpl/process.h | 39 ----------------- include/kpl/queue.h | 53 ---------------------- include/kpl/system.h | 21 --------- include/kpl/type.h | 53 ---------------------- 8 files changed, 350 deletions(-) delete mode 100644 include/kpl/code.h delete mode 100644 include/kpl/color.h delete mode 100644 include/kpl/io.h delete mode 100644 include/kpl/macro.h delete mode 100644 include/kpl/process.h delete mode 100644 include/kpl/queue.h delete mode 100644 include/kpl/system.h delete mode 100644 include/kpl/type.h (limited to 'include/kpl') diff --git a/include/kpl/code.h b/include/kpl/code.h deleted file mode 100644 index 1902c42..0000000 --- a/include/kpl/code.h +++ /dev/null @@ -1,25 +0,0 @@ - -#pragma once - -// Queues and trees for code life cycle - -#include "kpl/queue.h" - -typedef enum : int8_t { - KPL_CONFIG_CODE_QUEUE_POW2_MIN = 4, - KPL_CONFIG_CODE_QUEUE_POW2_DEFAULT = 7, - KPL_CONFIG_CODE_QUEUE_POW2_MAX = 10, -} kpl_config_code_queue_pow; - -typedef struct { - int8_t queue_pow2; -} kpl_config_code; - -// TODO namespace tree - -// TODO module tree - -typedef struct { - kpl_config_code *config_code; - kpl_ring_queue code_queue; -} kpl_code; diff --git a/include/kpl/color.h b/include/kpl/color.h deleted file mode 100644 index 1f77dcb..0000000 --- a/include/kpl/color.h +++ /dev/null @@ -1,119 +0,0 @@ - -#pragma once - -// C string pretty printing macros - -#define KPL_COLOR_CONCAT(COLOR) KPL_COLOR_ ## COLOR - -#ifndef KPL_COLOR_OFF - -#define KPL_COLOR(A) "\e[" KPL_COLOR_CONCAT(A) "m" -#define KPL_COLOR2(A, B) "\e[" KPL_COLOR_CONCAT(A) ";" KPL_COLOR_CONCAT(B) "m" -#define KPL_COLOR3(A, B, C) "\e[" KPL_COLOR_CONCAT(A) ";" KPL_COLOR_CONCAT(B) ";" KPL_COLOR_CONCAT(C) "m" - -#define KPL_COLOR_RESET "0" -#define KPL_COLOR_BOLD "1" -#define KPL_COLOR_FAINT "2" -#define KPL_COLOR_ITALIC "3" -#define KPL_COLOR_UNDERLINE "4" -#define KPL_COLOR_BLINK "5" -#define KPL_COLOR_REVERSE "7" -#define KPL_COLOR_HIDDEN "8" -#define KPL_COLOR_RESET_BOLD "21" -#define KPL_COLOR_RESET_FAINT "22" -#define KPL_COLOR_RESET_ITALIC "23" -#define KPL_COLOR_RESET_UNDERLINE "24" -#define KPL_COLOR_RESET_BLINK "25" -#define KPL_COLOR_RESET_REVERSE "27" -#define KPL_COLOR_RESET_HIDDEN "28" -#define KPL_COLOR_BLACK "30" -#define KPL_COLOR_RED "31" -#define KPL_COLOR_GREEN "32" -#define KPL_COLOR_YELLOW "33" -#define KPL_COLOR_BLUE "34" -#define KPL_COLOR_MAGENTA "35" -#define KPL_COLOR_CYAN "36" -#define KPL_COLOR_GREY "37" -#define KPL_COLOR_DEFAULT "39" -#define KPL_COLOR_BG_BLACK "30" -#define KPL_COLOR_BG_RED "41" -#define KPL_COLOR_BG_GREEN "42" -#define KPL_COLOR_BG_YELLOW "43" -#define KPL_COLOR_BG_BLUE "44" -#define KPL_COLOR_BG_MAGENTA "45" -#define KPL_COLOR_BG_CYAN "46" -#define KPL_COLOR_BG_GREY "47" -#define KPL_COLOR_DARK_GREY "90" -#define KPL_COLOR_LIGHT_RED "91" -#define KPL_COLOR_LIGHT_GREEN "92" -#define KPL_COLOR_LIGHT_YELLOW "93" -#define KPL_COLOR_LIGHT_BLUE "94" -#define KPL_COLOR_LIGHT_MAGENTA "95" -#define KPL_COLOR_LIGHT_CYAN "96" -#define KPL_COLOR_WHITE "97" -#define KPL_COLOR_BG_DARK_GREY "100" -#define KPL_COLOR_BG_LIGHT_RED "101" -#define KPL_COLOR_BG_LIGHT_GREEN "102" -#define KPL_COLOR_BG_LIGHT_YELLOW "103" -#define KPL_COLOR_BG_LIGHT_BLUE "104" -#define KPL_COLOR_BG_LIGHT_MAGENTA "105" -#define KPL_COLOR_BG_LIGHT_CYAN "106" -#define KPL_COLOR_BG_WHITE "107" - -#else - -#define KPL_COLOR(A) KPL_COLOR_CONCAT(A) -#define KPL_COLOR2(A, B) KPL_COLOR_CONCAT(A) KPL_COLOR_CONCAT(B) -#define KPL_COLOR3(A, B, C) KPL_COLOR_CONCAT(A) KPL_COLOR_CONCAT(B) KPL_COLOR_CONCAT(C) - - -#define KPL_COLOR_RESET "" -#define KPL_COLOR_BOLD "" -#define KPL_COLOR_FAINT "" -#define KPL_COLOR_ITALIC "" -#define KPL_COLOR_UNDERLINE "" -#define KPL_COLOR_BLINK "" -#define KPL_COLOR_REVERSE "" -#define KPL_COLOR_HIDDEN "" -#define KPL_COLOR_RESET_BOLD "" -#define KPL_COLOR_RESET_FAINT "" -#define KPL_COLOR_RESET_ITALIC "" -#define KPL_COLOR_RESET_UNDERLINE "" -#define KPL_COLOR_RESET_BLINK "" -#define KPL_COLOR_RESET_REVERSE "" -#define KPL_COLOR_RESET_HIDDEN "" -#define KPL_COLOR_BLACK "" -#define KPL_COLOR_RED "" -#define KPL_COLOR_GREEN "" -#define KPL_COLOR_YELLOW "" -#define KPL_COLOR_BLUE "" -#define KPL_COLOR_MAGENTA "" -#define KPL_COLOR_CYAN "" -#define KPL_COLOR_GREY "" -#define KPL_COLOR_DEFAULT "" -#define KPL_COLOR_BG_BLACK "" -#define KPL_COLOR_BG_RED "" -#define KPL_COLOR_BG_GREEN "" -#define KPL_COLOR_BG_YELLOW "" -#define KPL_COLOR_BG_BLUE "" -#define KPL_COLOR_BG_MAGENTA "" -#define KPL_COLOR_BG_CYAN "" -#define KPL_COLOR_BG_GREY "" -#define KPL_COLOR_DARK_GREY "" -#define KPL_COLOR_LIGHT_RED "" -#define KPL_COLOR_LIGHT_GREEN "" -#define KPL_COLOR_LIGHT_YELLOW "" -#define KPL_COLOR_LIGHT_BLUE "" -#define KPL_COLOR_LIGHT_MAGENTA "" -#define KPL_COLOR_LIGHT_CYAN "" -#define KPL_COLOR_WHITE "" -#define KPL_COLOR_BG_DARK_GREY "" -#define KPL_COLOR_BG_LIGHT_RED "" -#define KPL_COLOR_BG_LIGHT_GREEN "" -#define KPL_COLOR_BG_LIGHT_YELLOW "" -#define KPL_COLOR_BG_LIGHT_BLUE "" -#define KPL_COLOR_BG_LIGHT_MAGENTA "" -#define KPL_COLOR_BG_LIGHT_CYAN "" -#define KPL_COLOR_BG_WHITE "" - -#endif diff --git a/include/kpl/io.h b/include/kpl/io.h deleted file mode 100644 index a1b4b3f..0000000 --- a/include/kpl/io.h +++ /dev/null @@ -1,25 +0,0 @@ - -#pragma once - -// Io through io_uring - -#include "kpl/macro.h" - -typedef enum : int8_t { - KPL_CONFIG_IO_QUEUE_POW2_MIN = 4, - KPL_CONFIG_IO_QUEUE_POW2_DEFAULT = 10, - KPL_CONFIG_IO_QUEUE_POW2_MAX = 16 -} kpl_io_queue_pow_options; - -typedef struct { - int8_t queue_pow2; -} kpl_config_io; - -typedef struct { - kpl_config_io *config_io; - // TODO -} kpl_io; - -bool kpl_io_init(kpl_io *io); - -void kpl_io_free(kpl_io *io); diff --git a/include/kpl/macro.h b/include/kpl/macro.h deleted file mode 100644 index e0b59e5..0000000 --- a/include/kpl/macro.h +++ /dev/null @@ -1,15 +0,0 @@ - -#pragma once - -// KPL specific macros - -#include "color.h" -#include "type.h" - -#define _KPL_PRINT_(MESSAGE_COLOR, MESSAGE) printf(KPL_COLOR2(BOLD, MESSAGE_COLOR) "TODO " KPL_COLOR(RESET) KPL_COLOR(BOLD) "%s" KPL_COLOR(RESET) ":" KPL_COLOR(LIGHT_BLUE) "%s" KPL_COLOR(RESET) ":" KPL_COLOR(LIGHT_MAGENTA) "%d" KPL_COLOR(RESET) "::" KPL_COLOR(MESSAGE_COLOR) "%s\n" KPL_COLOR(RESET), __FILE__, __FUNCTION__, __LINE__, MESSAGE) - -#define KPL_PRINT_TODO(MESSAGE) _KPL_PRINT_(LIGHT_YELLOW, MESSAGE) - -#define KPL_PRINT_ERROR(MESSAGE) _KPL_PRINT_(LIGHT_RED, MESSAGE) - -#define KPL_PAGE_SIZE_ROUND(SIZE) ((SIZE + (getpagesize() - 1)) & ~(getpagesize() - 1)) diff --git a/include/kpl/process.h b/include/kpl/process.h deleted file mode 100644 index 528365a..0000000 --- a/include/kpl/process.h +++ /dev/null @@ -1,39 +0,0 @@ - -#pragma once - -// Kpl threads, allocators, atomic queues and garbage collection - -#include "kpl/queue.h" - -typedef enum : int8_t { - KPL_CONFIG_THREAD_COUNT_AFFINITY = -1, - KPL_CONFIG_THREAD_COUNT_MAX = 127 -} kpl_config_thread_count; - -typedef enum : uint8_t { - KPL_CONFIG_THREAD_RING_POOL_COUNT = 28, - KPL_CONFIG_THREAD_RING_POOL_MIN_OBJECT_SIZE_POW2 = 5, - KPL_CONFIG_THREAD_RING_POOL_MAX_OBJECT_SIZE_POW2 = 27, - KPL_CONFIG_THREAD_RING_POOL_MIN_RING_SIZE_POW2 = 6, - KPL_CONFIG_THREAD_RING_POOL_MAX_RING_SIZE_POW2 = 20 -} kpl_config_thread_ring_pool; - -typedef struct { - int8_t count, ring_pool_entries_pow2[KPL_CONFIG_THREAD_RING_POOL_COUNT]; -} kpl_config_thread; - -typedef struct { - int32_t thread_id; - _Atomic ssize_t priority; - kpl_env *env; - kpl_task_queue task_queue; - // TODO - sem_t sem; - pthread_t pthread; -} kpl_thread; - -typedef struct { - kpl_config_thread *config_thread; - kpl_thread *threads; - kpl_ring_queue memory_pool[KPL_CONFIG_THREAD_RING_POOL_COUNT]; -} kpl_process; diff --git a/include/kpl/queue.h b/include/kpl/queue.h deleted file mode 100644 index 0107434..0000000 --- a/include/kpl/queue.h +++ /dev/null @@ -1,53 +0,0 @@ - -#pragma once - -// KPL atomic queues - -#include "kpl/macro.h" - -typedef struct { - kpl_task *_Atomic head, *tail; - struct { - kpl_task *_Atomic next; - } dummy; -} kpl_task_queue; - -inline void kpl_task_queue_init(kpl_task_queue *task_queue) { - __atomic_store_n(&task_queue->dummy.next, NULL, __ATOMIC_RELAXED); - __atomic_store_n(&task_queue->head, &task_queue->dummy, __ATOMIC_RELAXED); - task_queue->tail = (kpl_task*) &task_queue->dummy; -} - -inline void kpl_task_queue_add(kpl_task_queue *task_queue, kpl_task *task) { - __atomic_store_n(&task->next, NULL, __ATOMIC_RELAXED); - kpl_task *head = __atomic_exchange_n(&task_queue->head, task, __ATOMIC_SEQ_CST); - __atomic_store_n(&head->next, task, __ATOMIC_RELEASE); -} - -kpl_task *kpl_task_queue_next(kpl_task_queue *task_queue); - -typedef enum : int8_t { - KPL_RING_QUEUE_MIN_POW2 = 4, - KPL_RING_QUEUE_MAX_POW2 = 30 -} kpl_ring_queue_pow2_sizes; - -typedef struct { - _Atomic ssize_t index; - void *data; -} kpl_ring_queue_item; - -typedef struct { - size_t mmap_size, items_mask; - _Atomic ssize_t head_index, tail_index; - kpl_ring_queue_item *items; -} kpl_ring_queue; - -bool kpl_ring_queue_init(kpl_ring_queue *ring_queue, int8_t size_pow2); - -inline void kpl_ring_queue_free(kpl_ring_queue *ring_queue) { - munmap(ring_queue->items, ring_queue->mmap_size); -} - -bool kpl_ring_queue_add(kpl_ring_queue *ring_queue, void *data); - -void *kpl_ring_queue_next(kpl_ring_queue *ring_queue); diff --git a/include/kpl/system.h b/include/kpl/system.h deleted file mode 100644 index 2d1ec48..0000000 --- a/include/kpl/system.h +++ /dev/null @@ -1,21 +0,0 @@ - -#pragma once - -// System headers - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include diff --git a/include/kpl/type.h b/include/kpl/type.h deleted file mode 100644 index 5003cf0..0000000 --- a/include/kpl/type.h +++ /dev/null @@ -1,53 +0,0 @@ - -#pragma once - -// KPL specific types - -#include "system.h" - -typedef enum : int32_t { - KPL_EXIT_CODE_SUCCESS = 0, - KPL_EXIT_CODE_ERROR = 1, - KPL_EXIT_CODE_HELP = 2 -} kpl_exit_code; - -typedef uint8_t kpl_utf8[4]; - -typedef union { - uint8_t u8; - int8_t i8; - uint16_t u16; - int16_t i16; - uint32_t u32; - int32_t i32; - uint64_t u64; - int64_t i64; - kpl_utf8 utf8; - float f32; - double f64; - void *ptr; -} kpl_value; - -typedef struct { - kpl_value value; - int64_t tag; -} kpl_result; - -typedef struct _kpl_task kpl_task; - -typedef struct _kpl_env kpl_env; - -typedef void kpl_task_fn(kpl_task *task, kpl_env *env); - -typedef struct _kpl_task { - struct _kpl_task *_Atomic next, *join; - kpl_task_fn *task_fn; - int32_t io_res; - uint32_t io_flags; - int32_t thread_id; - _Atomic bool canceled __attribute__((aligned(4))), join_ready __attribute__((aligned(8))); - kpl_result result; - // TODO TASK ARGUMENTS -} kpl_task; - - -- cgit v1.2.3