1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# 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;
```
|