diff options
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/application/buffer.md | 2 | ||||
| -rw-r--r-- | docs/application/error.md | 14 | ||||
| -rw-r--r-- | docs/application/group.md | 2 | ||||
| -rw-r--r-- | docs/application/index.md | 5 | ||||
| -rw-r--r-- | docs/application/map.md | 7 | ||||
| -rw-r--r-- | docs/application/name.md | 2 | ||||
| -rw-r--r-- | docs/application/namespace.md | 4 | ||||
| -rw-r--r-- | docs/application/native.md | 3 | ||||
| -rw-r--r-- | docs/application/pool.md | 9 | ||||
| -rw-r--r-- | docs/application/queue.md | 4 | ||||
| -rw-r--r-- | docs/application/shared.md | 26 | ||||
| -rw-r--r-- | docs/application/testing.md | 28 | ||||
| -rw-r--r-- | docs/application/thread.md | 12 | ||||
| -rw-r--r-- | docs/application/type.md | 4 | ||||
| -rw-r--r-- | docs/application/union.md | 13 | ||||
| -rw-r--r-- | docs/language/index.md | 6 | ||||
| -rw-r--r-- | docs/language/ownership.md | 10 | ||||
| -rw-r--r-- | docs/type_system/function.md | 2 | ||||
| -rw-r--r-- | docs/type_system/lock.md | 6 | ||||
| -rw-r--r-- | docs/type_system/shared.md | 20 |
20 files changed, 131 insertions, 48 deletions
diff --git a/docs/application/buffer.md b/docs/application/buffer.md index f8dff41..4580fec 100644 --- a/docs/application/buffer.md +++ b/docs/application/buffer.md @@ -6,7 +6,7 @@ ```c typedef struct _kpl_buffer { - POOL_HEADER(_kpl_buffer); + KPL_POOL_HEADER(_kpl_buffer); uint32_t byte_length; kpl_interface *interface; uint8_t bytes[]; diff --git a/docs/application/error.md b/docs/application/error.md new file mode 100644 index 0000000..dcf0a34 --- /dev/null +++ b/docs/application/error.md @@ -0,0 +1,14 @@ +# Error + +--- + +## Object Definitions + +```c +typedef struct _kpl_error { + KPL_POOL_HEADER(_kpl_error); + int32_t line; + char *file, *function; + kpl_class class; +} kpl_error; +``` diff --git a/docs/application/group.md b/docs/application/group.md index 2d5ed4b..c96c901 100644 --- a/docs/application/group.md +++ b/docs/application/group.md @@ -6,7 +6,7 @@ ```c typedef struct _kpl_group { - POOL_HEADER(_kpl_group); + KPL_POOL_HEADER(_kpl_group); uint32_t item_length; kpl_class items[]; } kpl_group; diff --git a/docs/application/index.md b/docs/application/index.md index ccde773..115d8b2 100644 --- a/docs/application/index.md +++ b/docs/application/index.md @@ -6,7 +6,7 @@ * Linux X64 with io_uring (6+) * GNU Make -* GCC with -std=gnu99 -fhardened (14+) +* GCC with -std=gnu23 -fhardened (14+) # Sections @@ -21,6 +21,9 @@ * ##### [Buffer](./buffer.md) * ##### [Map](./map.md) * ##### [Queue](./queue.md) +* ##### [Union](./union.md) +* ##### [Native](./native.md) +* ##### [Error](./error.md) * ##### [Namespace](./namespace.md) * ##### [Testing](./testing.md) diff --git a/docs/application/map.md b/docs/application/map.md index fd238e9..f2400a6 100644 --- a/docs/application/map.md +++ b/docs/application/map.md @@ -6,14 +6,15 @@ ```c typedef struct _kpl_map_bucket { - POOL_HEADER(_kpl_map_bucket); + KPL_POOL_HEADER(_kpl_map_bucket); kpl_any key, value; } kpl_map_bucket; typedef struct _kpl_map { - POOL_HEADER(_kpl_map); - int32_t used; + KPL_POOL_HEADER(_kpl_map); + int32_t length; kpl_interface *key_interface, *value_interface; kpl_map_bucket *buckets[]; + kpl_map_bucket *head, *tail; } kpl_map; ``` diff --git a/docs/application/name.md b/docs/application/name.md index fe3f0eb..a94789c 100644 --- a/docs/application/name.md +++ b/docs/application/name.md @@ -8,7 +8,7 @@ Each word representing a var, symbol or type gets an `NAME_IDENTIFIER` -> `kpl_n ```c typedef struct _kpl_name { - POOL_HEADER(_kpl_name); + KPL_POOL_HEADER(_kpl_name); uint32_t length; char *c_str[]; } kpl_name; diff --git a/docs/application/namespace.md b/docs/application/namespace.md index 3dd6bfa..07af049 100644 --- a/docs/application/namespace.md +++ b/docs/application/namespace.md @@ -25,7 +25,7 @@ typedef struct _kpl_namespace_module { kpl_buffer *module_name, *module_string; kpl_export *exports; kpl_task *task; - _Atomic int32_t children; + atomic_int_least32_t children; } kpl_namespace_module; static kpl_namespace_module *namespace_module_head; @@ -34,7 +34,7 @@ typedef struct _kpl_namespace_string { kpl_buffer *string; kpl_task *task; kpl_type_ptr ast; - _Atomic int32_t children; + atomic_int_least32_t children; } kpl_namespace_string; ``` diff --git a/docs/application/native.md b/docs/application/native.md new file mode 100644 index 0000000..71f1ffb --- /dev/null +++ b/docs/application/native.md @@ -0,0 +1,3 @@ +# Native + +--- diff --git a/docs/application/pool.md b/docs/application/pool.md index 8b57ee7..3795be0 100644 --- a/docs/application/pool.md +++ b/docs/application/pool.md @@ -5,19 +5,20 @@ ## Object Definitions ```c -#define POOL_HEADER(STRUCT) struct STRUCT *prev, *next; uint32_t obj_size +#define KPL_POOL_HEADER(STRUCT) struct STRUCT *prev, *next; uint32_t obj_byte_size typedef struct _kpl_pool_obj { - POOL_HEADER(_kpl_pool_obj); + KPL_POOL_HEADER(_kpl_pool_obj); } kpl_pool_obj; typedef void kpl_pool_on_fn(void *obj); typedef strut { - _Atomic int32_t allocs; + uint32_t min_obj_size; + atomic_size_t alloc_byte_size; kpl_pool_obj *root; kpl_pool_on_fn *on_init, *on_free; - pthread_spinlock_t lock; + pthread_mutex_t root_mutex; } kpl_pool; static kpl_pool_obj *kpl_pool_head; diff --git a/docs/application/queue.md b/docs/application/queue.md index bff1dd7..cab2e0b 100644 --- a/docs/application/queue.md +++ b/docs/application/queue.md @@ -6,12 +6,12 @@ ```c typedef struct _kpl_queue_item { - POOL_HEADER(_kpl_queue_item); + KPL_POOL_HEADER(_kpl_queue_item); kpl_any any; } kpl_queue_item; typedef struct _kpl_queue { - POOL_HEADER(_kpl_queue); + KPL_POOL_HEADER(_kpl_queue); uint32_t length; kpl_interface *interface; kpl_pool_any *head, *tail; diff --git a/docs/application/shared.md b/docs/application/shared.md index 753bd82..cbb773e 100644 --- a/docs/application/shared.md +++ b/docs/application/shared.md @@ -6,36 +6,36 @@ ```c typedef struct _kpl_shared { - POOL_HEADER(_kpl_shared); - _Atomic bool mutating; + KPL_POOL_HEADER(_kpl_shared); + atomic_flag mutating; bool mark; kpl_class class; kpl_task *queue_head, queue_tail; - pthread_spinlock_t lock; + pthread_mutex_t queue_mutex; } kpl_shared; -static _Atomic int32_t shared_threads; +static atomic_int_fast32_t shared_threads_marked; -static pthread_mutex_t shared_head_mutex; +static kpl_shared *shared_pool_sweep, *shared_pool; -static kpl_shared *shared_head_sweep, *shared_head; +static pthread_mutex_t shared_pool_mutex; ``` ## Tracing 1. Once triggered add a init task to the async queue -2. This task moves the `shared_head` to the `shared_head_sweep` and sets the `shared_wait` to off for each thread +2. This task moves the `shared_pool` to the `shared_pool_sweep` and sets the `shared_wait` to off for each thread 3. Each thread will run down its queue queue marking found shared objects -3. Once all have run and `shared_threads == available_threads` add a mark and sweep task to the async queue +3. Once all have run and `shared_threads_marked == available_threads` add a mark and sweep task to the async queue 4. The async queue is moved to a temp queue and as each item on the tmep queue is marked it is moved back to the async queue -5. A sweep on the `shared_head_sweep` is done -6. What remains on the `shared_head_sweep` is added to `shared_head` +5. A sweep on the `shared_pool_sweep` is done +6. What remains on the `shared_pool_sweep` is added to `shared_pool` ## Mutating 1. Check if state of `mutating` - 1. If false, set to true and add the task to the `async_queue_head` - 2. Once complete lock `lock` and check the `queue_head` + 1. If false, set to true and add the task to the `async_queue_pool` + 2. Once complete lock `queue_mutex` and check the `queue_pool` 3. If empty set the state of `mutating` to false 4. Else queue the next task -2. If the state of `mutating` is true add the task to `queue_tail` +2. If the state of `mutating` is true add, lock `queue_mutex` the task to `queue_tail` diff --git a/docs/application/testing.md b/docs/application/testing.md index 8657bf0..bbc7028 100644 --- a/docs/application/testing.md +++ b/docs/application/testing.md @@ -9,9 +9,33 @@ TEST(NAME) { // TEST BODY } -ASSERT(CONDITION) +ASSERT(CONDITION, FAIL_STRING) -FAIL() +FAIL(FAIL_STRING) ``` ## Object Definitions + +```c +typedef struct { + const char *name; + // TODO ERROR +} kpl_test; + +// TODO STORE ERRORS FOR PRINT AT END + +#define _TEST_FN(NAME) static void kpl_test_fn_##NAME([[gnu::constructor]] kpl_test *_test) + +#define TEST(NAME) \ + [[gnu::constructor]] _TEST_FN(NAME); + static void _kpl_test_constructor_##NAME(void) { \ + kpl_test _test = { .name = #NAME; /* TODO ERROR */ }; \ + kpl_test_fn_##NAME(&test); \ + / * TODO CHECK FOR ERROR */ \ + } \ + _TEST_FN(NAME) + +// TODO ASSERT + +// TODO FAIL +``` diff --git a/docs/application/thread.md b/docs/application/thread.md index 95bd450..a6b77e6 100644 --- a/docs/application/thread.md +++ b/docs/application/thread.md @@ -10,8 +10,8 @@ typedef struct _kpl_task kpl_task; typedef void kpl_task_fn(kpl_task *t); typedef struct _kpl_task { - POOL_HEADER(_kpl_task); - _Atomic bool next_ready; + KPL_POOL_HEADER(_kpl_task); + atomic_flag next_ready; uint16_t thread_id; kpl_task_fn *fn; kpl_group *state; @@ -20,7 +20,7 @@ typedef struct _kpl_task { } kpl_task; typedef struct { - _Atomic bool gc_wait; + atomic_flag gc_wait; kpl_task *queue_head, *queue_tail; pthread_t thread; } kpl_thread; @@ -29,13 +29,13 @@ typedef struct { static int32_t available_threads; // find with sched_getaffinity -static _Atomic int32_t running_threads; // init to available_threads +static atomic_int_fast32_t running_threads; // init to available_threads static kpl_task *async_queue_head, *async_queue_tail; -static pthread_mutex_t async_mutex; +static pthread_mutex_t async_queue_mutex; -static pthread_cond_t async_cond; +static pthread_cond_t async_queue_cond; static kpl_thread threads[KPL_MAX_THREADS]; ``` diff --git a/docs/application/type.md b/docs/application/type.md index e462e6d..5a856bd 100644 --- a/docs/application/type.md +++ b/docs/application/type.md @@ -34,8 +34,8 @@ typedef struct { kpl_type_template template; uint8_t qualifiers; uint16_t modifiers; - _Atomic int32_t ref_count; - kpl_type_ptr self, prev, next, parent; + atomic_int_least32_t ref_count; + kpl_ptr self; kpl_type_body body; } kpl_type; diff --git a/docs/application/union.md b/docs/application/union.md new file mode 100644 index 0000000..0032c0d --- /dev/null +++ b/docs/application/union.md @@ -0,0 +1,13 @@ +# Union + +--- + +## Object Definitions + +```c +typedef struct _kpl_union { + KPL_POOL_HEADER(_kpl_union); + uint32_t tag; + kpl_class class; +} kpl_union; +``` diff --git a/docs/language/index.md b/docs/language/index.md index 8ef01fd..ee2ea70 100644 --- a/docs/language/index.md +++ b/docs/language/index.md @@ -184,7 +184,7 @@ Move loop to next iteration { default statements } } -? condition {[args] statements } +? condition {[arg] statements } ``` ### Match `#` @@ -192,7 +192,7 @@ Move loop to next iteration ```text # match { target { statements } - target {[args] statements } + target {[arg] statements } { default statements } } ``` @@ -200,5 +200,5 @@ Move loop to next iteration ### Mutation `^` ```test -^ mutation {[args] statements } +^ mutation {[arg] statements } ``` diff --git a/docs/language/ownership.md b/docs/language/ownership.md index 9f29d8d..490363f 100644 --- a/docs/language/ownership.md +++ b/docs/language/ownership.md @@ -10,8 +10,6 @@ ## Assignment is not allowed for movable types that are not shared -## Shared Types - ## To And From Functions # Passing @@ -34,8 +32,14 @@ float_array : Array[F64] $ () `log float_array // Array[F64] $ (1.0; 2.0; 3.0) ``` +# Shared Types + # Locking -Prevent access to a container it's contents are modified +Prevent modification until a mutation occurs ## References + +# Mutating + +Unlock a lock or shared target and prevents modification to everything except the lock target diff --git a/docs/type_system/function.md b/docs/type_system/function.md index d8244a9..814e3c3 100644 --- a/docs/type_system/function.md +++ b/docs/type_system/function.md @@ -9,7 +9,7 @@ CLASS : INCOMPLETE | NATIVE | TASK | PROCESS | GENERATOR | ITERATOR | CLOSURE | FLAGS : INVOCATION | CLASS -Function[[FLAGS] STATE; List; RETURN_TYPE; Collection[TYPE.SYMBOL]] +Function[[FLAGS]; STATE; List; RETURN_TYPE; Collection[TYPE.SYMBOL]] ``` # Alias diff --git a/docs/type_system/lock.md b/docs/type_system/lock.md index 913a532..3b7d90a 100644 --- a/docs/type_system/lock.md +++ b/docs/type_system/lock.md @@ -2,8 +2,8 @@ --- -Prevent access to a parent while children are modifiable - ```text -Lock[[] Name[...]; TYPE] +Lock[[] TARGET] ``` + +Prevent access to `TARGET` until a mutation occurs diff --git a/docs/type_system/shared.md b/docs/type_system/shared.md index 2af408d..d1d3f07 100644 --- a/docs/type_system/shared.md +++ b/docs/type_system/shared.md @@ -21,3 +21,23 @@ x : Shared[Array] $ (1; 2; 3) } `log x // Shared[Array[I64]] $ (1; 2; 3; 4) ``` + +# Operators + +## ``get` + +## ``set` + +### Example sharing data between two shared objects + +```text +x : Shared $ 1 +y : Shared $ 0 + +z : ^ x {[x] x } +^ y {[y] y : z } +// same as above +y `set `get x +``` + + |
