# Type --- ## Object Definitions ```c typedef enum : uint8_t { // ... } kpl_type_template; typedef enum : uint8_t { KPL_TYPE_QUALIFIER_CONST = 1 << 0, KPL_TYPE_QUALIFIER_EMPTY = 1 << 1, KPL_TYPE_QUALIFIER_REF = 1 << 2, KPL_TYPE_QUALIFIER_SHARED = 1 << 3, KPL_TYPE_QUALIFIER_RETURN = 1 << 4 } kpl_type_qualifiers; typedef struct { kpl_type_template template; uint8_t qualifiers; uint16_t modifiers; } kpl_type_header; typedef struct { uint16_t length, line; int32_t position, module_id; } kpl_token; typedef enum { KPL_NATIVE_STORAGE_NONE, KPL_NATIVE_STORAGE_GENERAL_REGISTER, KPL_NATIVE_STORAGE_XMM_REGISTER, KPL_NATIVE_STORAGE_STACK } kpl_native_storage; typedef struct { uint8_t storage : 2, id : 6; } kpl_native_id; typedef union { // 64 Bytes Max } kpl_type_body; typedef struct _kpl_type { kpl_type_header header; union { kpl_token token; struct { kpl_native_id native_id; int8_t process_state_id; // -1 not used uint16_t tree_weight; struct _kpl_type *list; } var; } meta; _Atomic ssize_t ref_count; struct _kpl_type *prev, *next; kpl_type_body body; } kpl_type; ``` # Type Matching For type checking, evaluation and Ir generation Match based on the templates, from end of each statement to its start ## Op Matching Each Step is represented as a tree with sequential steps as sub trees 1. Op Name 2. Op Return Type 3. Op Left 4. Op Right 5. Match Mode (Check, Eval, Ir) ```c typedef enum : uint8_t { KPL_OP_MATCH_CHECK, KPL_OP_MATCH_EVAL, KPL_OP_MATCH_IR } kpl_op_match_mode; typedef struct _kpl_op_match { int32_t tree_weight; union { kpl_op_match_mode mode; kpl_op_name op_name; kpl_type_header header; } value; union { struct _kpl_op_match *children; union { // TODO FUNCTION POINTERS FOR EACH MODE } fn; } next; struct _kpl_op_match *tree_left, *tree_right; } kpl_op_match; ```