From 899951244d75254b870e0c7f4d1e9419e7964052 Mon Sep 17 00:00:00 2001 From: nodist Date: Wed, 24 Jun 2026 17:58:11 -0400 Subject: use trees without parent nodes --- docs/application/namespace.md | 63 ++++++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 18 deletions(-) (limited to 'docs/application/namespace.md') diff --git a/docs/application/namespace.md b/docs/application/namespace.md index e6809d5..b8caea7 100644 --- a/docs/application/namespace.md +++ b/docs/application/namespace.md @@ -6,43 +6,50 @@ ```c typedef struct _kpl_export { - KPL_SLAB_TREE_HEADER(struct _kpl_export); + KPL_ALLOC_TREE_HEADER(struct _kpl_export); kpl_type_ptr type; } kpl_export; typedef struct _kpl_namespace_native { KPL_SLAB_TREE_HEADER(struct _kpl_namespace_native); - kpl_buffer *name; - kpl_export *exports; + const char *name; + kpl_export *export_tree; } kpl_namespace_native; -static kpl_namespace_native *namespace_native_head; +static kpl_namespace_native namespace_native_tree; + +typedef enum : uint8_t { + // ... +} namespace_lifecycle; typedef struct _kpl_namespace_module { KPL_SLAB_TREE_HEADER(struct _kpl_namespace_module); kpl_type_ptr ast; - kpl_queue *parents; + kpl_name *name_tree; kpl_buffer *module_name, *module_string; - kpl_export *exports; - kpl_task *task; - _Atomic int32_t children; + kpl_export *export_tree; + kpl_mutex mutex; } kpl_namespace_module; -static kpl_namespace_module *namespace_module_head; +static kpl_namespace_module *namespace_module_tree; + +kpl_mutex namespace_module_mutex; typedef struct _kpl_namespace_string { - kpl_buffer *string; - kpl_task *task; kpl_type_ptr ast; - _Atomic int32_t children; + kpl_name *name_tree; + kpl_buffer *string; + kpl_mutex mutex; } kpl_namespace_string; + +static kpl_namespace_string namespace_string ``` Each `NAMESPACE_IDENTIFIER` maps to `kpl_namespace_native*` or `kpl_namespace_module*` depending on flags ## Lookup and Storage -The native and namespace objects are stored as a tree under `namespace_native_head` and `namespace_module_head` +The native and namespace objects are stored as a tree The exports are stored under a tree for both the native and namespace objects @@ -50,26 +57,46 @@ The exports are stored under a tree for both the native and namespace objects ## Native -## Module +TODO C code for exposing native code + +## Module/String/REPL ### Main -### ``import` +Begin life cycle and [Register](../lifecycle/register.md) -## String/REPL +### Scan ``import` + +Add a [Register](../lifecycle/regiser.md) task to `namespace_module_mutex` # Updating +## Native + +### Native code should not be updated at runtime, doing so is undefined behavior + ## Module ### ``export` +Add exports directly to the namespaces `export_tree`, thread safe + +## String/REPL + +### Cannot export for String/REPL + # Using ## Native ### ``use` -## Module +Since the native modules are loaded statically the `native_module_tree` becomes read only at runtime, access is thread safe + +## Module/String/REPL + +### Import ``import` -### ``import` +1. Add find namespace task to the `namespace_module_mutex`, the namespace not existing is an error +2. Add task to the namespaces `mutex` +3. The task will resume the importer -- cgit v1.2.3