diff options
Diffstat (limited to 'include/kpl')
| -rw-r--r-- | include/kpl/identifier.h | 10 | ||||
| -rw-r--r-- | include/kpl/type.h | 45 |
2 files changed, 44 insertions, 11 deletions
diff --git a/include/kpl/identifier.h b/include/kpl/identifier.h index 092b0c4..a30b4a7 100644 --- a/include/kpl/identifier.h +++ b/include/kpl/identifier.h @@ -13,8 +13,6 @@ #define KPL_IDENTIFIER_VALUES_PER_PART (KPL_IDENTIFIER_BITS_PER_PART / KPL_IDENTIFIER_BITS_PER_VALUE) -#define KPL_IDENTIFIER_VALUES_TOTAL_BITS (KPL_IDENTIFIER_BITS_PER_VALUE * KPL_IDENTIFIER_VALUES_PER_PART) - #define KPL_IDENTIFIER_MAX_LENGTH (KPL_IDENTIFIER_VALUES_PER_PART * KPL_IDENTIFIER_PARTS) #define KPL_IDENTIFIER_C_STRING_SIZE (KPL_IDENTIFIER_MAX_LENGTH + sizeof(char)) @@ -36,6 +34,12 @@ bool kpl_identifier_encode(kpl_identifier *identifier, const char *c_string, siz /* * Converts an identifier into a c string * Does not clear the c_string buffer - * Does not check the c_string buffer assumes the buffer is at least KPL_IDENTIFIER_C_STRING_SIZE + * Does not check the c_string buffer size assumes the buffer is at least KPL_IDENTIFIER_C_STRING_SIZE */ void kpl_identifier_decode(kpl_identifier *identifier, char c_string[KPL_IDENTIFIER_C_STRING_SIZE]); + +/* + * Compares identifiers like strings + * 0 - equal, negative - left < right, positive - left > right + */ +int32_t kpl_identifier_compare(const kpl_identifier *identifier_left, const kpl_identifier *identifier_right); diff --git a/include/kpl/type.h b/include/kpl/type.h index 546a1ed..76c64c1 100644 --- a/include/kpl/type.h +++ b/include/kpl/type.h @@ -25,7 +25,7 @@ typedef enum : uint8_t { // CONTAINERS KPL_TYPE_NAME_STRING, KPL_TYPE_NAME_ARRAY, - KPL_TYPE_NAME_TYPLE, + KPL_TYPE_NAME_TUPLE, KPL_TYPE_NAME_TABLE, KPL_TYPE_NAME_MAP, KPL_TYPE_NAME_SET, @@ -39,25 +39,35 @@ typedef enum : uint8_t { KPL_TYPE_NAME_REGEXP, // STORAGE KPL_TYPE_NAME_MODULE, - KPL_TYPE_NAME_NAMESPACE + KPL_TYPE_NAME_NAMESPACE, + // DEFINITIONS + KPL_TYPE_NAME_ALIAS, + KPL_TYPE_NAME_UNIQUE } kpl_type_name; +/* + * The c struct for this type + */ typedef enum : uint8_t { - KPL_TYPE_KIND_BASE + KPL_TYPE_KIND_BASE, // has no additional type information + KPL_TYPE_KIND_INNER, // type wraps one or two types + 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; -typedef enum : uint32_t { - KPL_TYPE_FLAG_EMPTY = 0 +typedef enum : uint16_t { + KPL_TYPE_FLAG_EMPTY = 0, + KPL_TYPE_FLAG_REF = 1 << 0 } kpl_type_flags; // type_kind is for struct polymorphism -// type_specific meaning changes depending on type_name #define KPL_TYPE_HEADER(STRUCT_NAME) \ KPL_OBJECT_HEADER(STRUCT_NAME); \ kpl_type_name type_name; \ kpl_type_kind type_kind; \ - uint16_t type_specific; \ - uint32_t type_flags + uint16_t type_flags /* * Type has no additional information @@ -65,3 +75,22 @@ typedef enum : uint32_t { typedef struct _kpl_type_base { KPL_TYPE_HEADER(_kpl_type_base); } kpl_type_base; + +/* + * Type wraps one or two types + */ +typedef struct _kpl_type_inner { + KPL_TYPE_HEADER(_kpl_type_inner); + kpl_type_base *inner[2]; +} kpl_type_inner; + +/* + * Type wraps an unknown number of types + */ +typedef struct _kpl_type_array { + KPL_TYPE_HEADER(_kpl_type_array); + uint16_t array_size, array_length; + kpl_type_base *array[]; +} kpl_type_array; + +// TODO TREE |
