DEADSOFTWARE

Исправлена конверсия строки единичного размера в символ в сравнениях
[dsw-obn.git] / src / oberon-internals.h
1 #ifndef OBERON_INTERNALS_H
2 #define OBERON_INTERNALS_H
4 #include <stdint.h>
5 #include <stdbool.h>
7 typedef struct gen_module_t gen_module_t;
8 typedef struct gen_proc_t gen_proc_t;
9 typedef struct gen_type_t gen_type_t;
10 typedef struct gen_var_t gen_var_t;
11 typedef struct gen_label_t gen_label_t;
12 typedef struct gen_context_t gen_context_t;
14 typedef struct oberon_type_t oberon_type_t;
15 typedef struct oberon_object_t oberon_object_t;
16 typedef struct oberon_module_t oberon_module_t;
17 typedef struct oberon_context_t oberon_context_t;
18 typedef struct oberon_scope_t oberon_scope_t;
20 typedef struct oberon_item_t oberon_item_t;
21 typedef struct oberon_oper_t oberon_oper_t;
22 typedef union oberon_expr_t oberon_expr_t;
24 struct oberon_scope_t
25 {
26 oberon_context_t * ctx;
27 oberon_object_t * list;
28 oberon_scope_t * up;
30 int local;
31 oberon_object_t * parent;
32 oberon_type_t * parent_type;
34 gen_label_t * exit_label;
35 };
37 enum oberon_type_kind
38 {
39 OBERON_TYPE_NOTYPE,
40 OBERON_TYPE_INTEGER,
41 OBERON_TYPE_BOOLEAN,
42 OBERON_TYPE_PROCEDURE,
43 OBERON_TYPE_ARRAY,
44 OBERON_TYPE_RECORD,
45 OBERON_TYPE_POINTER,
46 OBERON_TYPE_REAL,
47 OBERON_TYPE_CHAR,
48 OBERON_TYPE_STRING,
49 OBERON_TYPE_SET,
50 OBERON_TYPE_NIL,
51 OBERON_TYPE_SYSTEM_BYTE,
52 OBERON_TYPE_SYSTEM_PTR
53 };
55 typedef oberon_expr_t * (*GenerateFuncCallback)(oberon_context_t *, int, oberon_expr_t *);
56 typedef void (*GenerateProcCallback)(oberon_context_t *, int, oberon_expr_t *);
58 struct oberon_type_t
59 {
60 enum oberon_type_kind class;
61 int size;
62 oberon_type_t * shorter;
63 oberon_type_t * longer;
65 int num_decl;
66 oberon_type_t * base;
67 oberon_object_t * decl;
68 oberon_scope_t * scope;
70 bool sysproc;
71 GenerateFuncCallback genfunc;
72 GenerateProcCallback genproc;
74 oberon_module_t * module;
76 int recursive;
77 int initialized;
78 gen_type_t * gen_type;
79 };
81 enum oberon_object_kind
82 {
83 OBERON_CLASS_VAR,
84 OBERON_CLASS_TYPE,
85 OBERON_CLASS_PROC,
86 OBERON_CLASS_PARAM,
87 OBERON_CLASS_VAR_PARAM,
88 OBERON_CLASS_CONST,
89 OBERON_CLASS_FIELD,
90 OBERON_CLASS_MODULE
91 };
93 struct oberon_object_t
94 {
95 char * name;
96 enum oberon_object_kind class;
97 int export;
98 int read_only;
100 int local;
101 int linked;
102 int initialized;
104 oberon_object_t * parent;
105 oberon_type_t * parent_type;
107 oberon_scope_t * scope; // for proc
108 int has_return; // for proc
110 oberon_type_t * type;
111 oberon_item_t * value;
112 oberon_object_t * next;
114 oberon_module_t * module;
116 gen_var_t * gen_var;
117 gen_proc_t * gen_proc;
118 };
120 struct oberon_module_t
122 char * name;
123 bool ready;
124 bool intrinsic;
126 oberon_scope_t * decl;
128 oberon_module_t * next;
130 gen_module_t * gen_mod;
131 };
133 typedef const char * (*ModuleImportCallback)(const char * name);
135 struct oberon_context_t
137 /*** SCANER DATA ***/
138 const char * code;
139 int code_index;
141 char c;
142 int token;
143 char * string;
144 int64_t integer;
145 double real;
146 bool longmode;
147 /*** END SCANER DATA ***/
149 /*** PARSER DATA ***/
150 oberon_scope_t * decl;
151 oberon_module_t * mod;
152 /*** END PARSER DATA ***/
154 oberon_scope_t * world_scope;
155 oberon_type_t * notype_type;
156 oberon_type_t * nil_type;
157 oberon_type_t * bool_type;
158 oberon_type_t * byte_type;
159 oberon_type_t * shortint_type;
160 oberon_type_t * int_type;
161 oberon_type_t * longint_type;
162 oberon_type_t * real_type;
163 oberon_type_t * longreal_type;
164 oberon_type_t * char_type;
165 oberon_type_t * string_type;
166 oberon_type_t * set_type;
168 oberon_module_t * system_module;
169 oberon_type_t * system_byte_type;
170 oberon_type_t * system_ptr_type;
172 oberon_module_t * module_list;
173 ModuleImportCallback import_module;
174 gen_context_t * gen_context;
175 };
177 enum oberon_mode_kind
179 MODE_VAR,
180 MODE_INTEGER,
181 MODE_BOOLEAN,
182 MODE_CALL,
183 MODE_INDEX,
184 MODE_FIELD,
185 MODE_DEREF,
186 MODE_NIL,
187 MODE_NEW,
188 MODE_REAL,
189 MODE_CHAR,
190 MODE_STRING,
191 MODE_TYPE,
192 MODE_SET,
193 MODE_LEN,
194 MODE_SYSBYTE
195 };
197 enum oberon_operator_kind
199 OP_UNARY_MINUS,
200 OP_LOGIC_NOT,
201 OP_ABS,
202 OP_CAP,
203 OP_ENTIER,
205 OP_ADD,
206 OP_SUB,
207 OP_MUL,
208 OP_DIV,
209 OP_MOD,
210 OP_LOGIC_AND,
211 OP_LOGIC_OR,
213 OP_EQ,
214 OP_NEQ,
215 OP_LSS,
216 OP_LEQ,
217 OP_GRT,
218 OP_GEQ,
220 OP_CAST,
221 OP_HARDCAST,
222 OP_IS,
224 OP_RANGE,
225 OP_UNION,
226 OP_INTERSECTION,
227 OP_DIFFERENCE,
228 OP_SYM_DIFFERENCE,
229 OP_COMPLEMENTATION,
230 OP_IN,
232 OP_ASH,
233 OP_LSH,
234 OP_ROT
235 };
237 struct oberon_item_t
239 bool is_item; // == 1
240 oberon_type_t * result;
241 oberon_expr_t * next;
242 bool read_only;
244 enum oberon_mode_kind mode;
245 long integer;
246 double real;
247 char * string;
248 oberon_object_t * var;
250 oberon_item_t * parent;
252 int num_args;
253 oberon_expr_t * args;
254 };
256 struct oberon_oper_t
258 bool is_item; // == 0
259 oberon_type_t * result;
260 oberon_expr_t * next;
261 bool read_only;
263 enum oberon_operator_kind op;
264 oberon_expr_t * left;
265 oberon_expr_t * right;
266 };
268 union oberon_expr_t
270 struct {
271 bool is_item;
272 oberon_type_t * result;
273 oberon_expr_t * next;
274 bool read_only;
275 };
277 oberon_item_t item;
278 oberon_oper_t oper;
279 };
281 #endif // OBERON_INTERNALS_H