summaryrefslogtreecommitdiff
path: root/docs/application
diff options
context:
space:
mode:
Diffstat (limited to 'docs/application')
-rw-r--r--docs/application/buffer.md14
-rw-r--r--docs/application/error.md3
-rw-r--r--docs/application/group.md2
-rw-r--r--docs/application/index.md12
-rw-r--r--docs/application/interface.md16
-rw-r--r--docs/application/io.md38
-rw-r--r--docs/application/map.md6
-rw-r--r--docs/application/memory.md152
-rw-r--r--docs/application/namespace.md94
-rw-r--r--docs/application/native.md1
-rw-r--r--docs/application/queue.md5
-rw-r--r--docs/application/shared.md3
-rw-r--r--docs/application/thread.md21
-rw-r--r--docs/application/union.md3
14 files changed, 183 insertions, 187 deletions
diff --git a/docs/application/buffer.md b/docs/application/buffer.md
index 92de6ae..40c58e4 100644
--- a/docs/application/buffer.md
+++ b/docs/application/buffer.md
@@ -6,16 +6,20 @@
```c
typedef struct _kpl_buffer {
- KPL_ALLOC_HEADER(struct _kpl_buffer);
- size_t byte_length : KPL_ALLOC_POOL_SIZE;
- int32_t io_register_index : KPL_ALLOC_WEIGHT;
+ KPL_DYNAMIC_OBJ_HEADER();
+ int32_t byte_length;
kpl_interface *interface;
+ int16_t io_register_index;
uint8_t bytes[];
} kpl_buffer;
+
+typedef struct {
+ // TODO RING BUFFERS BY POWERS OF TWO
+} kpl_buffer_registered_pool;
```
-## Io uring buffer register
+## Io uring buffer sparse register
-### Set `io_register_index` to -1 of not used
+### Set `io_register_index` to -1 if not used
## Unicode Methods
diff --git a/docs/application/error.md b/docs/application/error.md
index e6fae17..f0d844a 100644
--- a/docs/application/error.md
+++ b/docs/application/error.md
@@ -6,9 +6,8 @@
```c
typedef struct _kpl_error {
- KPL_SLAB_HEADER(struct _kpl_error);
+ int32_t line;
char *file, *function;
kpl_class class;
- int32_t line;
} kpl_error;
```
diff --git a/docs/application/group.md b/docs/application/group.md
index 65566b7..1294afe 100644
--- a/docs/application/group.md
+++ b/docs/application/group.md
@@ -6,7 +6,7 @@
```c
typedef struct _kpl_group {
- KPL_ALLOC_HEADER(struct _kpl_group);
+ KPL_DYNAMIC_OBJ_HEADER();
kpl_class items[];
} kpl_group;
```
diff --git a/docs/application/index.md b/docs/application/index.md
index 40a03b8..e315baf 100644
--- a/docs/application/index.md
+++ b/docs/application/index.md
@@ -33,10 +33,14 @@
## Startup
1. Configuration
+ * `thread_count` - defaults to number of available processors
2. Initialize tasks
2. Initialize allocators
+ * Slab sizes
4. Initialize types
+ * Built In Alias
5. Initialize IO
+ * Size of registered sparse buffers
## Main
@@ -52,10 +56,10 @@
4. ##### [Import](../lifecycle/import.md)
5. ##### [Check](../lifecycle/check.md)
6. ##### [Eval](../lifecycle/eval.md)
-7. ##### Ir
-8. ##### Jit
-9. ##### Exec
-10. ##### Notify
+7. ##### [Ir](../lifecycle/ir.md)
+8. ##### [Jit](../lifecycle/jit.md)
+9. ##### [Exec](../lifecycle/exec.md)
+10. ##### [Notify](../lifecycle/notify.md)
## Shutdown
diff --git a/docs/application/interface.md b/docs/application/interface.md
index 790c155..9a7fa22 100644
--- a/docs/application/interface.md
+++ b/docs/application/interface.md
@@ -22,15 +22,7 @@ typedef union {
void *ptr;
} kpl_any;
-typedef size_t kpl_any_hash_fn(const kpl_any a);
-
-typedef ssize_t kpl_any_cmp_fn(const kpl_any a, const kpl_any b);
-
-typedef int32_t kpl_write(const kpl_ant a, FILE *file, int32_t idnt, uint32_t opts);
-
-// TODO GC FUNCTION
-
-typedef void kpl_any_free_fn(kpl_any a);
+typedef void kpl_interface_free(kpl_any a);
typedef struct {
// TODO
@@ -38,7 +30,7 @@ typedef struct {
typedef struct {
kpl_any *any;
- kpl_interface *interflace;
+ kpl_interface *interface;
} kpl_class;
typedef enum : uint8_t {
@@ -64,3 +56,7 @@ typdef struct {
#define KPL_PTR_NULL (kpl_ptr) { .slab_index = UINT16_MAX, .array_index = UINT16_MAX }
```
+
+## `kpl_interface`
+
+See [Operators](../language/operators.md)
diff --git a/docs/application/io.md b/docs/application/io.md
index 9ab786c..a292718 100644
--- a/docs/application/io.md
+++ b/docs/application/io.md
@@ -1,5 +1,39 @@
-# Io
+# Io (io_uring)
---
-All Io is done through linux io uring
+# Design
+
+## Io Ring
+
+## Fixed Buffers
+
+## Fixed Files
+
+## Buffer Rings
+
+# Io Tasks
+
+Tasks for each IO operation are stored in the `user_data` field
+
+## Ring Submission `struct io_uring_sqe`
+
+## Ring Completion `struct io_uring_cqe`
+
+# Usage
+
+## File
+
+### Open
+
+### Statx
+
+### Read
+
+### Write
+
+## Directory
+
+## Timers
+
+## Network
diff --git a/docs/application/map.md b/docs/application/map.md
index 01ba57f..18fa7a8 100644
--- a/docs/application/map.md
+++ b/docs/application/map.md
@@ -6,13 +6,13 @@
```c
typedef struct _kpl_map_bucket {
- KPL_SLAB_LIST_HEADER(struct _kpl_map_bucket);
+ struct _kpl_map_bucket *prev, *next;
kpl_any key, value;
} kpl_map_bucket;
typedef struct _kpl_map {
- KPL_ALLOC_HEADER(struct _kpl_map);
- uint32_t used_buckets, available_buckets;
+ KPL_DYNAMIC_OBJ_HEADER();
+ int32_t available_buckets;
kpl_interface *key_interface, *value_interface;
kpl_map_bucket *head, *tail;
kpl_map_bucket *buckets[];
diff --git a/docs/application/memory.md b/docs/application/memory.md
index e7f05ba..44a3786 100644
--- a/docs/application/memory.md
+++ b/docs/application/memory.md
@@ -1,151 +1,39 @@
-# Memory Pool
+# Memory
---
-## Object Definitions
-
-```c
-#define KPL_ALLOC_POOL_SIZE 40
-
-#define KPL_ALLOC_WEIGHT 24
-
-#define KPL_ALLOC_HEADER(STRCUT) size_t obj_size : KPL_ALLOC_POOL_SIZE; uint32_t tree_weight : KPL_ALLOC_WEIGHT; STRCUT *prev
-
-typedef struct _kpl_alloc_obj {
- KPL_ALLOC_HEADER(_kpl_alloc_obj);
-} kpl_alloc_obj;
-
-#define KPL_ALLOC_TREE_HEADER(STRCUT) KPL_ALLOC_HEADER(STRUCT); STRUCT *next;
-
-typdef struct _kpl_alloc_tree_obj {
- KPL_ALLOC_TREE_HEADER(struct _kpl_alloc_tree_obj);
-} kpl_alloc_tree_obj;
+An allocator per Object definition with ring buffer pooling based
-typedef struct kpl_alloc {
- _Atomic size_t bytes_allocated;
- kpl_mutex mutex;
- kpl_alloc_obj *pool[KPL_ALLOC_POOL_SIZE]
-} kpl_alloc;
+# Single Allocation
-#define KPL_SLAB_HEADER(STRUCT) STRCUT *prev
+Once created never freed until shutdown
-typdef strcut _kpl_slab_obj {
- KPL_SLAB_HEADER(strcut _kpl_slab_obj);
-} kpl_slab_obj;
+# Pooling Allocations
-#define KPL_SLAB_LIST_HEADER(STRCUT) STRCUT *prev, *next
+## Ring Buffer
-typdef strcut _kpl_slab_list_obj {
- KPL_SLAB_LIST_HEADER(strcut _kpl_slab_list_obj);
-} kpl_slab_list_obj;
+## Fixed Sized Objects
-#define KPL_SLAB_TREE_HEADER(STRUCT) STRUCT *prev, *next; uint32_t tree_weight : KPL_ALLOC_WEIGHT
+## Dynamic Sized Objects
-typdef strcut _kpl_slab_tree_obj {
- KPL_SLAB_TREE_HEADER(struct _kpl_slab_tree_obj);
-} kpl_slab_tree_obj;
+Dynamically sized objects must be aligned to a power of two
-typdef struct _kpl_slab_bucket {
- struct _kpl_slab_bucket *next;
- uint8_t byte_obj_array[];
-} kpl_slab_bucket;
+Requires a ring buffer for each power of two
-typedef struct _kpl_slab {
- uint16_t obj_count, obj_index;
- uint32_t obj_size;
- kpl_slab_obj *pool;
- kpl_slab_bucket *bucket;
- kpl_mutex mutex;
-} kpl_slab;
-```
-
-# Alloc
-
-All allocated objects size must be aligned to the power of two
-
-## Pooling
-
-Each bucket in the `kpl_alloc.pool` represents two to the power of the bucket index
+## Object Definitions
-# Slab
+```c
+#define KPL_DYANMIC_OBJ_MIN_BITS 7
-## Pooling
+#define KPL_DYNAMIC_OBJ_MAX_BITS 27
-Objects for reuse are stored as a list by the `kpl_slab_obj.prev` on `kpl_slab.pool`
+#define KPL_DYNAMIC_OBJ_MIN_SIZE (1 << KPL_DYANMIC_OBJ_MIN_BITS)
-# AVL Tree For Slab And Alloc
+#define KPL_DYNAMIC_OBJ_MAX_SIZE (1 << KPL_DYNAMIC_OBJ_MAX_BITS)
-## AVL Tree Example
+#define KPL_DYNAMIC_OBJ_HEADER() int32_t obj_size;
-```c
-typedef struct _avl {
- int val, count;
- struct _avl *left, *right;
-} avl;
-
-
-int get_count(const avl *node) {
- return node ? node->count : 0;
-}
-
-int get_balance(const avl *node) {
- if (!node)
- return 0;
- return get_count(node->left) - get_count(node->right);
-}
-
-void right_rotate(avl **right) {
- avl *left = (*right)->left, *left_right = left->right;
- left->right = *right;
- (*right)->left = left_right;
- (*right)->count = MAX(get_count((*right)->left), get_count((*right)->right)) + 1;
- left->count = MAX(get_count(left->left), get_count(left->right)) + 1;
- *right = left;
-}
-
-void left_rotate(avl **left) {
- avl *right = (*left)->right, *right_left = right->left;
- right->left = *left;
- (*left)->right = right_left;
- (*left)->count = MAX(get_count((*left)->left), get_count((*left)->right)) + 1;
- right->count = MAX(get_count(right->left), get_count(right->right)) + 1;
- *left = right;
-}
-
-void insert(avl **parent, avl *node) {
- if (!*parent) {
- *parent = node;
- return;
- }
- if (node->val < (*parent)->val)
- insert(&(*parent)->left, node);
- else
- insert(&(*parent)->right, node);
- (*parent)->count = MAX(get_count((*parent)->left), get_count((*parent)->right)) + 1;
- int balance = get_balance(*parent);
- if (balance > 1 && get_balance((*parent)->left) >= 0)
- right_rotate(parent);
- if (balance > 1 && get_balance((*parent)->left) > 0) {
- left_rotate(&(*parent)->left);
- right_rotate(parent);
- }
- if (balance < -1 && get_balance((*parent)->right) <= 0)
- left_rotate(parent);
- if (balance < -1 && get_balance((*parent)->right) > 0) {
- right_rotate(&(*parent)->right);
- left_rotate(parent);
- }
-}
-
-struct TreeNode* sortedListToBST(struct ListNode* head) {
- avl *root = NULL;
- while (head) {
- avl *node = calloc(1, sizeof(avl));
- node->val = head->val;
- node->count = 1;
- head = head->next;
- insert(&root, node);
- }
- return (struct TreeNode*) root;
-}
+typedef struct {
+ KPL_DYNAMIC_OBJ_HEADER();
+} kpl_dynamic_obj;
```
diff --git a/docs/application/namespace.md b/docs/application/namespace.md
index c6b8cea..ac382de 100644
--- a/docs/application/namespace.md
+++ b/docs/application/namespace.md
@@ -6,28 +6,27 @@
```c
typedef struct _kpl_export {
- KPL_SLAB_TREE_HEADER(struct _kpl_export);
+ size_t tree_weight;
+ struct _kpl_export *tree_left, *tree_right;
kpl_type_ptr type;
} kpl_export;
typedef struct _kpl_namespace_native {
- KPL_SLAB_TREE_HEADER(struct _kpl_namespace_native);
+ size_t tree_weight;
+ struct _kpl_namespace_native *tree_left, *tree_right;
const char *name;
kpl_export *export_tree;
} kpl_namespace_native;
-static kpl_namespace_native namespace_native_tree;
-
-typedef enum : uint8_t {
- // ...
-} namespace_lifecycle;
+static kpl_namespace_native *namespace_native_tree;
typedef struct _kpl_namespace_module {
- KPL_SLAB_TREE_HEADER(struct _kpl_namespace_module);
- kpl_type_ptr ast;
+ size_t tree_weight;
+ struct _kpl_namespace_module *tree_left, *tree_right;
kpl_buffer *module_string, *module_name;
kpl_export *export_tree;
kpl_mutex export_mutex;
+ kpl_type_ptr ast;
} kpl_namespace_module;
static kpl_namespace_module *namespace_module_tree;
@@ -93,3 +92,80 @@ Since the native modules are loaded statically the `native_module_tree` becomes
2. Add a get export task to the namespaces `export_mutex`
3. The `export_mutex` will not start processing it's queue until the namespace notifies that it's and unlocks its `export_mutex`
4. The importer will get a copy of the read only `export_tree`
+
+# AVL Tree Storage and Lookup
+
+## AVL Tree Example
+
+```c
+typedef struct _avl {
+ int val, count;
+ struct _avl *left, *right;
+} avl;
+
+
+int get_count(const avl *node) {
+ return node ? node->count : 0;
+}
+
+int get_balance(const avl *node) {
+ if (!node)
+ return 0;
+ return get_count(node->left) - get_count(node->right);
+}
+
+void right_rotate(avl **right) {
+ avl *left = (*right)->left, *left_right = left->right;
+ left->right = *right;
+ (*right)->left = left_right;
+ (*right)->count = MAX(get_count((*right)->left), get_count((*right)->right)) + 1;
+ left->count = MAX(get_count(left->left), get_count(left->right)) + 1;
+ *right = left;
+}
+
+void left_rotate(avl **left) {
+ avl *right = (*left)->right, *right_left = right->left;
+ right->left = *left;
+ (*left)->right = right_left;
+ (*left)->count = MAX(get_count((*left)->left), get_count((*left)->right)) + 1;
+ right->count = MAX(get_count(right->left), get_count(right->right)) + 1;
+ *left = right;
+}
+
+void insert(avl **parent, avl *node) {
+ if (!*parent) {
+ *parent = node;
+ return;
+ }
+ if (node->val < (*parent)->val)
+ insert(&(*parent)->left, node);
+ else
+ insert(&(*parent)->right, node);
+ (*parent)->count = MAX(get_count((*parent)->left), get_count((*parent)->right)) + 1;
+ int balance = get_balance(*parent);
+ if (balance > 1 && get_balance((*parent)->left) >= 0)
+ right_rotate(parent);
+ if (balance > 1 && get_balance((*parent)->left) > 0) {
+ left_rotate(&(*parent)->left);
+ right_rotate(parent);
+ }
+ if (balance < -1 && get_balance((*parent)->right) <= 0)
+ left_rotate(parent);
+ if (balance < -1 && get_balance((*parent)->right) > 0) {
+ right_rotate(&(*parent)->right);
+ left_rotate(parent);
+ }
+}
+
+struct TreeNode* sortedListToBST(struct ListNode* head) {
+ avl *root = NULL;
+ while (head) {
+ avl *node = calloc(1, sizeof(avl));
+ node->val = head->val;
+ node->count = 1;
+ head = head->next;
+ insert(&root, node);
+ }
+ return (struct TreeNode*) root;
+}
+```
diff --git a/docs/application/native.md b/docs/application/native.md
index 705c4ed..c5108aa 100644
--- a/docs/application/native.md
+++ b/docs/application/native.md
@@ -6,7 +6,6 @@
```c
typedef struct _kpl_native {
- KPL_SLAB_HEADER(struct _kpl_native);
kpl_class class;
} kpl_native;
```
diff --git a/docs/application/queue.md b/docs/application/queue.md
index cd9f363..a770ac7 100644
--- a/docs/application/queue.md
+++ b/docs/application/queue.md
@@ -6,13 +6,12 @@
```c
typedef struct _kpl_queue_item {
- KPL_SLAB_LIST_HEADER(struct _kpl_queue_item);
+ struct _kpl_queue_item *prev, *next;
kpl_any any;
} kpl_queue_item;
typedef struct _kpl_queue {
- KPL_SLAB_HEADER(struct _kpl_queue);
- size_t item_length;
+ int32_t item_length;
kpl_interface *interface;
kpl_pool_any *head, *tail;
} kpl_queue;
diff --git a/docs/application/shared.md b/docs/application/shared.md
index 89ba292..0528645 100644
--- a/docs/application/shared.md
+++ b/docs/application/shared.md
@@ -6,10 +6,9 @@
```c
typedef struct _kpl_shared {
- KPL_SLAB_HEADER(struct _kpl_shared);
+ bool mark;
kpl_class data;
kpl_mutex mutex;
- bool mark;
} kpl_shared;
_Atomic uint32_t shared_threads_makred;
diff --git a/docs/application/thread.md b/docs/application/thread.md
index 770358f..6d3f76f 100644
--- a/docs/application/thread.md
+++ b/docs/application/thread.md
@@ -22,13 +22,6 @@ typedef struct _task {
_Atomic bool join_ready;
} task;
-#define KPL_TASK_SLAB_SIZE 50
-
-typedef struct _kpl_task_slab {
- struct _kpl_task_slab *next;
- kpl_task array[KPL_TASK_SLAB_SIZE];
-} kpl_task_slab;
-
#define KPL_QUEUE_ASYNC -1
#define KPL_MAIN_THREAD 0
@@ -40,13 +33,11 @@ typedef struct {
} dummy;
} kpl_task_queue;
+// TODO RING BUFFER ALLOCATOR
+
typedef struct {
kpl_task_queue queue;
_Atomic ssize_t priority;
- uint32_t slab_array_index;
- _Atomic uint32_t pool_size;
- kpl_task_slab *slab;
- kpl_task *pool;
sem_t counter;
pthread_t thread;
} kpl_thread;
@@ -75,12 +66,20 @@ regex : captures, function state, regex function
## Sync
+Queue task on selected thread
+
## Async
+Queue task on thread with lowest `priority`
+
# Running
## Joining
+# Thread Pool Management
+
+Run task to check thread pool sizes and create tasks to spread out a large pool across other threads
+
# Example
```c
diff --git a/docs/application/union.md b/docs/application/union.md
index 3626f1c..984253c 100644
--- a/docs/application/union.md
+++ b/docs/application/union.md
@@ -6,8 +6,7 @@
```c
typedef struct _kpl_union {
- KPL_SLAB_HEADER(strcut _kpl_union);
- kpl_class class;
uint32_t tag;
+ kpl_class class;
} kpl_union;
```