diff options
Diffstat (limited to 'include/kpl/type.h')
| -rw-r--r-- | include/kpl/type.h | 79 |
1 files changed, 64 insertions, 15 deletions
diff --git a/include/kpl/type.h b/include/kpl/type.h index 76c64c1..7b93e6f 100644 --- a/include/kpl/type.h +++ b/include/kpl/type.h @@ -6,7 +6,7 @@ #pragma once typedef enum : uint8_t { - KPL_TYPE_NAME_UNKOWN, + KPL_TYPE_NAME_INVALID, // VALUES KPL_TYPE_NAME_BOOLEAN, KPL_TYPE_NAME_INTEGER, @@ -42,24 +42,32 @@ typedef enum : uint8_t { KPL_TYPE_NAME_NAMESPACE, // DEFINITIONS KPL_TYPE_NAME_ALIAS, - KPL_TYPE_NAME_UNIQUE + KPL_TYPE_NAME_UNIQUE, + // ENUM COUNT + KPL_TYPE_NAME_ENUM_COUNT } kpl_type_name; +const char *kpl_type_name_c_string(kpl_type_name type_name); + /* * The c struct for this type */ typedef enum : uint8_t { + KPL_TYPE_KIND_INVALID, KPL_TYPE_KIND_BASE, // has no additional type information - KPL_TYPE_KIND_INNER, // type wraps one or two types + KPL_TYPE_KIND_NATIVE, // keeps interface pointer KPL_TYPE_KIND_ARRAY, // type wraps an unknown number of types - KPL_TYPE_KIND_TREE_ITEM_TYPE, - KPL_TYPE_KIND_TREE_ITEM_IDENTIFIER, - KPL_TYPE_KIND_TREE // tree of type/type or identifier/type + KPL_TYPE_KIND_TREE, // tree of type/type or identifier/type + KPL_TYPE_KIND_COROUTINE // coroutine type, tree + array } kpl_type_kind; +kpl_type_kind kpl_type_name_get_kind(kpl_type_name type_name); + typedef enum : uint16_t { - KPL_TYPE_FLAG_EMPTY = 0, - KPL_TYPE_FLAG_REF = 1 << 0 + KPL_TYPE_FLAG_EMPTY = 0, + KPL_TYPE_FLAG_NULLABLE = 1 << 0, + KPL_TYPE_FLAG_TREE_TYPE = 1 << 1, + KPL_TYPE_FLAG_TREE_IDENTIFIER = 1 << 2 } kpl_type_flags; // type_kind is for struct polymorphism @@ -77,20 +85,61 @@ typedef struct _kpl_type_base { } kpl_type_base; /* - * Type wraps one or two types + * Keeps interface pointer for its type comparison */ -typedef struct _kpl_type_inner { - KPL_TYPE_HEADER(_kpl_type_inner); - kpl_type_base *inner[2]; -} kpl_type_inner; +typedef struct _kpl_type_native { + KPL_TYPE_HEADER(_kpl_type_native); + kpl_interface *interface; +} kpl_type_native; /* * Type wraps an unknown number of types + * Array does not grow or shrink + * Minimum array size is 1 */ typedef struct _kpl_type_array { KPL_TYPE_HEADER(_kpl_type_array); - uint16_t array_size, array_length; + uint16_t array_size; kpl_type_base *array[]; } kpl_type_array; -// TODO TREE +/* + * Tree based on matching types + */ +typedef struct _kpl_type_tree_item_type { + KPL_TREE_HEADER(_kpl_type_tree_item_type); + uint16_t tag; // unique id + kpl_type_base *type; +} kpl_type_tree_item_type; + +/* + * Tree based on matching identifiers + */ +typedef struct _kpl_type_tree_item_identifier { + KPL_TREE_HEADER(_kpl_type_tree_item_identifier); + uint16_t tag; // unique id for the item + kpl_type_base *type; + kpl_identifier identifier; +} kpl_type_tree_item_identifier; + +/* + * Tree of types + * Tag counter provides a unique tag to each new inserted item + */ +typedef struct _kpl_type_tree { + KPL_TYPE_HEADER(_kpl_type_tree); + uint16_t tag_counter; + kpl_tree tree; +} kpl_type_tree; + +/* + * Coroutine Type + * Arguments size is known at creation and does not grow + * Arguments size can be zero + */ +typedef struct _kpl_type_coroutine { + KPL_TYPE_HEADER(_kpl_type_coroutine); + uint16_t arguments_size, tag_counter; // unique id generator + kpl_tree result_tree; + kpl_type_base *arguments[]; +} kpl_type_coroutine; |
