forked from vysheng/tgl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.h
173 lines (142 loc) · 4.13 KB
/
generate.h
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
This file is part of tgl-libary/generate
Tgl-library/generate is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
Tgl-library/generate is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this tgl-library/generate. If not, see <http://www.gnu.org/licenses/>.
Copyright Vitaly Valtman 2014-2015
It is derivative work of VK/KittenPHP-DB-Engine (https://github.com/vk-com/kphp-kdb/)
Copyright 2012-2013 Vkontakte Ltd
2012-2013 Vitaliy Valtman
*/
#ifndef __GENERATE_H__
#define __GENERATE_H__
struct tl_combinator;
struct tl_type {
// struct tl_type_methods *methods;
char *id;
char *print_id;
unsigned name;
int arity;
int flags;
int constructors_num;
struct tl_combinator **constructors;
long long params_types;
int extra;
};
#define NODE_TYPE_TYPE 1
#define NODE_TYPE_NAT_CONST 2
#define NODE_TYPE_VAR_TYPE 3
#define NODE_TYPE_VAR_NUM 4
#define NODE_TYPE_ARRAY 5
#define MAX_COMBINATOR_VARS 64
#define NAME_VAR_NUM 0x70659eff
#define NAME_VAR_TYPE 0x2cecf817
#define NAME_INT 0xa8509bda
#define NAME_LONG 0x22076cba
#define NAME_DOUBLE 0x2210c154
#define NAME_STRING 0xb5286e24
#define NAME_VECTOR 0x1cb5c415
#define NAME_MAYBE_TRUE 0x3f9c8ef8
#define NAME_MAYBE_FALSE 0x27930a7b
#define NAME_BOOL_FALSE 0xbc799737
#define NAME_BOOL_TRUE 0x997275b5
#define NAME_BYTES 0x0ee1379f
#define FLAG_OPT_VAR (1 << 17)
#define FLAG_EXCL (1 << 18)
#define FLAG_OPT_FIELD (1 << 20)
#define FLAG_NOVAR (1 << 21)
#define FLAG_BARE 1
#define FLAGS_MASK ((1 << 16) - 1)
#define FLAG_DEFAULT_CONSTRUCTOR (1 << 25)
#define FLAG_NOCONS (1 << 1)
extern struct tl_tree_methods tl_nat_const_methods;
extern struct tl_tree_methods tl_nat_const_full_methods;
extern struct tl_tree_methods tl_pnat_const_full_methods;
extern struct tl_tree_methods tl_array_methods;
extern struct tl_tree_methods tl_type_methods;
extern struct tl_tree_methods tl_parray_methods;
extern struct tl_tree_methods tl_ptype_methods;
extern struct tl_tree_methods tl_var_num_methods;
extern struct tl_tree_methods tl_var_type_methods;
extern struct tl_tree_methods tl_pvar_num_methods;
extern struct tl_tree_methods tl_pvar_type_methods;
#define TL_IS_NAT_VAR(x) (((long)x) & 1)
#define TL_TREE_METHODS(x) (TL_IS_NAT_VAR (x) ? &tl_nat_const_methods : ((struct tl_tree *)(x))->methods)
#define DEC_REF(x) (TL_TREE_METHODS(x)->dec_ref ((void *)x))
#define INC_REF(x) (TL_TREE_METHODS(x)->inc_ref ((void *)x))
#define TYPE(x) (TL_TREE_METHODS(x)->type ((void *)x))
typedef unsigned long long tl_tree_hash_t;
struct tl_tree;
struct tl_tree_methods {
int (*type)(struct tl_tree *T);
int (*eq)(struct tl_tree *T, struct tl_tree *U);
void (*inc_ref)(struct tl_tree *T);
void (*dec_ref)(struct tl_tree *T);
};
struct tl_tree {
int ref_cnt;
int flags;
//tl_tree_hash_t hash;
struct tl_tree_methods *methods;
};
/*
struct tl_tree_nat_const {
struct tl_tree self;
int value;
};*/
struct tl_tree_type {
struct tl_tree self;
struct tl_type *type;
int children_num;
struct tl_tree **children;
};
struct tl_tree_array {
struct tl_tree self;
struct tl_tree *multiplicity;
int args_num;
struct arg **args;
};
struct tl_tree_var_type {
struct tl_tree self;
int var_num;
};
struct tl_tree_var_num {
struct tl_tree self;
int var_num;
int dif;
};
struct tl_tree_nat_const {
struct tl_tree self;
long long value;
};
struct arg {
char *id;
int var_num;
int flags;
int exist_var_num;
int exist_var_bit;
struct tl_tree *type;
};
struct tl_combinator {
//struct tl_combinator_methods *methods;
char *id;
char *print_id;
unsigned name;
int is_fun;
int var_num;
int args_num;
struct arg **args;
struct tl_tree *result;
void **IP;
void **fIP;
int IP_len;
int fIP_len;
};
#endif