aboutsummaryrefslogtreecommitdiff
path: root/include/kpl/type.h
diff options
context:
space:
mode:
authornodist <kevin.comas.git@gmail.com>2026-11-11 14:05:59 -0500
committernodist <kevin.comas.git@gmail.com>2026-11-11 14:05:59 -0500
commit75c8828d804f45cf8f44af73bfe87e0f3eaf9a9e (patch)
tree2fdf51906d2517bbe8c928fc52f95bb2e0dda4f9 /include/kpl/type.h
parent7b9204a8680539bc4795a14f3d9a34e47981d0c3 (diff)
run a task test
Diffstat (limited to 'include/kpl/type.h')
-rw-r--r--include/kpl/type.h40
1 files changed, 37 insertions, 3 deletions
diff --git a/include/kpl/type.h b/include/kpl/type.h
index 7b93e6f..91c3bd4 100644
--- a/include/kpl/type.h
+++ b/include/kpl/type.h
@@ -1,6 +1,7 @@
/*
* KPL Types
* A Type is a declaration of code and data
+ * Types can be shared across threads
*/
#pragma once
@@ -58,6 +59,7 @@ typedef enum : uint8_t {
KPL_TYPE_KIND_NATIVE, // keeps interface pointer
KPL_TYPE_KIND_ARRAY, // type wraps an unknown number of types
KPL_TYPE_KIND_TREE, // tree of type/type or identifier/type
+ KPL_TYPE_KIND_RESULT, // union of array and tree for tags
KPL_TYPE_KIND_COROUTINE // coroutine type, tree + array
} kpl_type_kind;
@@ -71,6 +73,7 @@ typedef enum : uint16_t {
} kpl_type_flags;
// type_kind is for struct polymorphism
+// types are in the gc cannot use object_flags for meta
#define KPL_TYPE_HEADER(STRUCT_NAME) \
KPL_OBJECT_HEADER(STRUCT_NAME); \
kpl_type_name type_name; \
@@ -129,17 +132,48 @@ typedef struct _kpl_type_tree_item_identifier {
typedef struct _kpl_type_tree {
KPL_TYPE_HEADER(_kpl_type_tree);
uint16_t tag_counter;
- kpl_tree tree;
+ kpl_tree tag_tree;
} kpl_type_tree;
/*
+ * Reserved ids for result types
+ * For result_types tag_counter has to be initialized to 3
+ * New tags cannot use these ids
+ */
+typedef enum : uint8_t {
+ KPL_TYPE_RESULT_ID_DEFAULT = 0, // .default can be any type
+ KPL_TYPE_RESULT_ID_ERROR = 1, // .error must be error type
+ KPL_TYPE_RESULT_ID_DONE = 2 // .done must be void
+} kpL_type_result_ids;
+
+/*
+ * Most of the time we can use default_error and map all .default and .error tags to this array
+ * .done does not need a type it is always void
+ * If more tags are added move .default, .error (.done if applicable) to the tree and add additional tags to tree
+ */
+typedef union {
+ kpl_type_base *default_error[2]; // used if tag counter == 3
+ kpl_tree tree; // tag counter > 3
+} kpl_type_result_union;
+
+/*
+ * KPL result type
+ */
+typedef struct _kpl_type_result {
+ KPL_TYPE_HEADER(_kpl_type_result);
+ uint16_t tag_counter;
+ kpl_type_result_union result;
+} kpl_type_result;
+
+/*
* Coroutine Type
* Arguments size is known at creation and does not grow
* Arguments size can be zero
+ * Can be cased to kpl_type_result when working with results
*/
typedef struct _kpl_type_coroutine {
KPL_TYPE_HEADER(_kpl_type_coroutine);
- uint16_t arguments_size, tag_counter; // unique id generator
- kpl_tree result_tree;
+ uint16_t tag_counter, arguments_size; // unique id generator
+ kpl_type_result_union result;
kpl_type_base *arguments[];
} kpl_type_coroutine;