/* * KPL Types * A Type is a declaration of code and data */ #pragma once typedef enum : uint8_t { KPL_TYPE_NAME_INVALID, // VALUES KPL_TYPE_NAME_BOOLEAN, KPL_TYPE_NAME_INTEGER, KPL_TYPE_NAME_U8, KPL_TYPE_NAME_U16, KPL_TYPE_NAME_U32, KPL_TYPE_NAME_U64, KPL_TYPE_NAME_I8, KPL_TYPE_NAME_I16, KPL_TYPE_NAME_I32, KPL_TYPE_NAME_I64, KPL_TYPE_NAME_FLOAT, KPL_TYPE_NAME_F32, KPL_TYPE_NAME_F64, KPL_TYPE_NAME_CHAR, // CONTAINERS KPL_TYPE_NAME_STRING, KPL_TYPE_NAME_ARRAY, KPL_TYPE_NAME_TUPLE, KPL_TYPE_NAME_TABLE, KPL_TYPE_NAME_MAP, KPL_TYPE_NAME_SET, KPL_TYPE_NAME_UNION, KPL_TYPE_NAME_ANY, KPL_TYPE_NAME_NATIVE, KPL_TYPE_NAME_ERROR, // COROUTINES KPL_TYPE_NAME_LAMBDA, KPL_TYPE_NAME_GENERATOR, KPL_TYPE_NAME_REGEXP, // STORAGE KPL_TYPE_NAME_MODULE, KPL_TYPE_NAME_NAMESPACE, // DEFINITIONS KPL_TYPE_NAME_ALIAS, 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_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_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_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 #define KPL_TYPE_HEADER(STRUCT_NAME) \ KPL_OBJECT_HEADER(STRUCT_NAME); \ kpl_type_name type_name; \ kpl_type_kind type_kind; \ uint16_t type_flags /* * Type has no additional information */ typedef struct _kpl_type_base { KPL_TYPE_HEADER(_kpl_type_base); } kpl_type_base; /* * Keeps interface pointer for its type comparison */ 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; kpl_type_base *array[]; } kpl_type_array; /* * 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;