aboutsummaryrefslogtreecommitdiff
path: root/include/kpl/object.h
diff options
context:
space:
mode:
authornodist <kevin.comas.git@gmail.com>2026-11-05 15:22:02 -0500
committernodist <kevin.comas.git@gmail.com>2026-11-05 15:22:02 -0500
commit7b9204a8680539bc4795a14f3d9a34e47981d0c3 (patch)
tree7aa69bba0c9cbee0cafb638fd49af64958dbb228 /include/kpl/object.h
parentfaa937cb09cd01f4ea94f5d7722a20e9c1246df0 (diff)
more objects and special slab for gc
Diffstat (limited to 'include/kpl/object.h')
-rw-r--r--include/kpl/object.h88
1 files changed, 82 insertions, 6 deletions
diff --git a/include/kpl/object.h b/include/kpl/object.h
index cdea84e..933b459 100644
--- a/include/kpl/object.h
+++ b/include/kpl/object.h
@@ -23,9 +23,13 @@ typedef enum : uint16_t {
KPL_OBJECT_GC_HEADER(STRUCT_NAME); \
kpl_object_gc *object_gc_parent;
+/*
+ * All kpl objects allocated by the kpl memory allocator extend this header
+ * The kpl_object_gc extends is partially, so it can still be used with the memory allocator
+ */
typedef struct _kpl_object {
KPL_OBJECT_HEADER(_kpl_object);
-} kpl_object; // all kpl objects allocated by the kpl memory allocator extend this header
+} kpl_object;
/*
* Atomic linked list queue any thread can add, only owner thread can remove
@@ -74,20 +78,92 @@ typedef struct _kpl_object_gc {
} kpl_object_gc;
/*
+ * UTF-8 Strings
+ * Strings must be null termed
+ */
+typedef struct _kpl_object_string {
+ KPL_OBJECT_HEADER(_kpl_object_string);
+ int32_t bytes_length, bytes_size; // length does not include null term, size includes null term
+ uint8_t bytes[];
+} kpl_object_string;
+
+#define KPL_ARRAY_MAX_VALUE_SIZE ((1 << 30) - 1)
+
+// for array polymorphism
+// values_length and values_size refers to the number of values, to get in bytes multiply by VALUE_BIT_WIDTH
+#define KPL_OBJECT_ARRAY_HEADER(STRUCT_NAME) \
+ KPL_OBJECT_HEADER(STRUCT_NAME); \
+ kpl_value_bit_width value_bit_width : 3; \
+ uint32_t values_length : 29, values_size : 29
+
+/*
+ * KPL arrays
+ * Use this object as the base for all arrays
+ * Array methods will cast to different value sizes
+ */
+typedef struct _kpl_object_array {
+ KPL_OBJECT_ARRAY_HEADER(_kpl_object_array);
+} kpl_object_array;
+
+// One container for each internal value bit width
+#define _KPL_OBJECT_ARRAY_DEFINE(VALUE_BIT_WIDTH) \
+typedef struct _kpl_object_array ## VALUE_BIT_WIDTH { \
+ KPL_OBJECT_ARRAY_HEADER(_kpl_object_array ## VALUE_BIT_WIDTH); \
+ kpl_value ## VALUE_BIT_WIDTH values[]; \
+} kpl_object_array ## VALUE_BIT_WIDTH;
+
+/*
+ * kpl_object_array8
+ */
+_KPL_OBJECT_ARRAY_DEFINE(8);
+/*
+ * kpl_object_array16
+ */
+_KPL_OBJECT_ARRAY_DEFINE(16);
+/*
+ * kpl_object_array32
+ */
+_KPL_OBJECT_ARRAY_DEFINE(32);
+/*
+ * kpl_object_array64
+ */
+_KPL_OBJECT_ARRAY_DEFINE(64);
+
+#define KPL_TUPLE_ITEMS_MAX 64
+
+/*
+ * Tuple, array of different types
+ * Can hold up TO KPL_TUPLE_ITEMS_MAX items, if (items_gc_mask & 1UL << index) then items[index] is a kpl_object_gc
+ */
+typedef struct _kpl_object_tuple {
+ KPL_OBJECT_HEADER(_kpl_object_tuple);
+ uint64_t items_gc_mask;
+ kpl_value64 items[];
+} kpl_object_tuple;
+
+/*
+ * Wraps C objects
+ * The c object is freed with the kpl_interface_native_free_fn
+ */
+typedef struct _kpl_object_native {
+ KPL_OBJECT_HEADER(_kpl_object_native);
+ void *c_object;
+} kpl_object_native;
+
+/*
* Class data is read only, cannot modify or race conditions can occur
- * The error stack can be modified across threads
+ * queue_next from the object header is used to create an error stack
*/
typedef struct _kpl_object_error {
KPL_OBJECT_HEADER(_kpl_object_error);
- kpl_object_queue error_stack;
kpl_class error_file, error_data; // Can be a reference to C code or KPL code
int32_t error_line;
} kpl_object_error;
-typedef kpl_object_error *kpl_task_fn(kpl_object_task *task, kpl_thread *thread);
+typedef kpl_object_error *kpl_task_fn(kpl_thread *thread, kpl_object_task *task);
/*
- * Max variables per task, used a bit field to check if the variable can be garbage collected
+ * Max variables per task, a bit mask used to check if the variable can be garbage collected
*/
#define KPL_TASK_VARIABLES_MAX 56
@@ -102,7 +178,7 @@ typedef struct _kpl_object_task {
uint64_t variables_gc_mask : KPL_TASK_VARIABLES_MAX; // set once then only read
int32_t io_res; // io_res and io_flags are set by io_uring complete
uint32_t io_flags;
- kpl_object_task *join;
+ kpl_object_task *join_task;
kpl_task_fn *task_fn;
kpl_result result;
kpl_value64 variables[]; // a task has no distinction between an argument or a local, both live here