From 003119b9f285e5610f56186bce845441409265ae Mon Sep 17 00:00:00 2001 From: nodist Date: Sat, 18 Jul 2026 14:01:26 -0400 Subject: op and ir matching definitions --- docs/application/index.md | 2 ++ docs/application/namespace.md | 10 +++--- docs/application/type.md | 72 +++++++++++++++++++++++++++++++++---------- 3 files changed, 63 insertions(+), 21 deletions(-) (limited to 'docs/application') diff --git a/docs/application/index.md b/docs/application/index.md index 0dd4b7e..804e952 100644 --- a/docs/application/index.md +++ b/docs/application/index.md @@ -41,6 +41,8 @@ 5. Initialize IO * Size of registered sparse buffers 6. Initialize Jit +7. Initialize Op Matching +8. Initialize Ir Matching ## Main diff --git a/docs/application/namespace.md b/docs/application/namespace.md index cd1f89e..d276fd0 100644 --- a/docs/application/namespace.md +++ b/docs/application/namespace.md @@ -5,21 +5,21 @@ ## Object Definitions ```c -#define KPL_TREE_HEADER() uint32_t tree_weight, module_id; struct _kpl_namespace_tree *tree_left, *tree_right; kpl_buffer *name +#define KPL_TREE_HEADER(STRUCT) uint32_t tree_weight, module_id; STRUCT *tree_left, *tree_right; kpl_buffer *name -typedef struct _kpl_namespace_tree { - KPL_TREE_HEADER(); +typedef struct _kpl_namespace_tree_obj { + KPL_TREE_HEADER(struct _kpl_namespace_tree_obj); } kpl_namespace_tree_obj; typedef struct _kpl_namespace_native { - KPL_TREE_HEADER(); + KPL_TREE_HEADER(struct _kpl_namespace_native); kpl_type *export_var_tree; } kpl_namespace_native; static kpl_namespace_native *namespace_native_tree; typedef struct _kpl_namespace_module { - KPL_TREE_HEADER(); + KPL_TREE_HEADER(struct _kpl_namespace_module); kpl_buffer *body; kpl_type *ast, *export_var_tree; kpl_mutex export_mutex; diff --git a/docs/application/type.md b/docs/application/type.md index 796d848..b16b70f 100644 --- a/docs/application/type.md +++ b/docs/application/type.md @@ -10,16 +10,18 @@ typedef enum : uint8_t { } kpl_type_template; typedef enum : uint8_t { - CONST = 1 << 0, - EMPTY = 1 << 1, - REF = 1 << 2, - SHARED = 1 << 3, - RETURN = 1 << 4 + 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 union { - // 64 Bytes Max -} kpl_type_body; +typedef struct { + kpl_type_template template; + uint8_t qualifiers; + uint16_t modifiers; +} kpl_type_header; typedef struct { uint16_t length, line; @@ -27,20 +29,22 @@ typedef struct { } kpl_token; typedef enum { - NONE, - GENERAL_REGISTER, - XMM_REGISTER, - STACK + 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_template template; - uint8_t qualifiers; - uint16_t modifiers; + kpl_type_header header; union { kpl_token token; struct { @@ -58,4 +62,40 @@ typedef struct _kpl_type { # Type Matching -For type checking and evaluation +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; +``` -- cgit v1.2.3