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_location_t oberon_location_t;
21 typedef struct oberon_scanner_t oberon_scanner_t;
22 typedef struct oberon_item_t oberon_item_t;
23 typedef struct oberon_oper_t oberon_oper_t;
24 typedef union oberon_expr_t oberon_expr_t;
26 struct oberon_scope_t
27 {
28 oberon_context_t * ctx;
29 oberon_object_t * list;
30 oberon_scope_t * up;
32 int local;
33 oberon_object_t * parent;
34 oberon_type_t * parent_type;
36 gen_label_t * exit_label;
37 };
39 enum oberon_type_kind
40 {
41 OBERON_TYPE_NOTYPE,
42 OBERON_TYPE_INTEGER,
43 OBERON_TYPE_BOOLEAN,
44 OBERON_TYPE_PROCEDURE,
45 OBERON_TYPE_ARRAY,
46 OBERON_TYPE_RECORD,
47 OBERON_TYPE_POINTER,
48 OBERON_TYPE_REAL,
49 OBERON_TYPE_CHAR,
50 OBERON_TYPE_STRING,
51 OBERON_TYPE_SET,
52 OBERON_TYPE_NIL,
53 OBERON_TYPE_SYSTEM_BYTE,
54 OBERON_TYPE_SYSTEM_PTR
55 };
57 typedef oberon_expr_t * (*GenerateFuncCallback)(oberon_context_t *, int, oberon_expr_t *);
58 typedef void (*GenerateProcCallback)(oberon_context_t *, int, oberon_expr_t *);
60 struct oberon_type_t
61 {
62 enum oberon_type_kind class;
63 int size;
64 oberon_type_t * shorter;
65 oberon_type_t * longer;
67 int num_decl;
68 oberon_type_t * base;
69 oberon_object_t * decl;
70 oberon_scope_t * scope;
72 bool sysproc;
73 GenerateFuncCallback genfunc;
74 GenerateProcCallback genproc;
76 oberon_module_t * module;
78 int recursive;
79 int initialized;
80 gen_type_t * gen_type;
81 };
83 enum oberon_object_kind
84 {
85 OBERON_CLASS_VAR,
86 OBERON_CLASS_TYPE,
87 OBERON_CLASS_PROC,
88 OBERON_CLASS_PARAM,
89 OBERON_CLASS_VAR_PARAM,
90 OBERON_CLASS_CONST,
91 OBERON_CLASS_FIELD,
92 OBERON_CLASS_MODULE
93 };
95 struct oberon_object_t
96 {
97 char * name;
98 enum oberon_object_kind class;
99 int export;
100 int read_only;
102 int local;
103 int linked;
104 int initialized;
106 oberon_object_t * parent;
107 oberon_type_t * parent_type;
109 oberon_scope_t * scope; // for proc
110 int has_return; // for proc
112 oberon_type_t * type;
113 oberon_item_t * value;
114 oberon_object_t * next;
116 oberon_module_t * module;
118 gen_var_t * gen_var;
119 gen_proc_t * gen_proc;
120 };
122 struct oberon_module_t
124 char * name;
125 bool ready;
126 bool intrinsic;
128 oberon_scope_t * decl;
130 oberon_module_t * next;
132 gen_module_t * gen_mod;
133 };
135 struct oberon_location_t
137 const char * source;
138 int line;
139 int col;
140 };
142 struct oberon_scanner_t
144 char * source;
145 char * code;
146 };
148 typedef oberon_scanner_t * (*ModuleImportCallback)(const char * name);
150 struct oberon_context_t
152 /*** SCANER DATA ***/
153 const char * code;
154 int code_index;
155 oberon_location_t loc;
156 oberon_location_t xloc;
158 char c;
159 int token;
160 char * string;
161 int64_t integer;
162 double real;
163 bool longmode;
164 /*** END SCANER DATA ***/
166 /*** PARSER DATA ***/
167 oberon_scope_t * decl;
168 oberon_module_t * mod;
169 /*** END PARSER DATA ***/
171 oberon_scope_t * world_scope;
172 oberon_type_t * notype_type;
173 oberon_type_t * nil_type;
174 oberon_type_t * bool_type;
175 oberon_type_t * byte_type;
176 oberon_type_t * shortint_type;
177 oberon_type_t * int_type;
178 oberon_type_t * longint_type;
179 oberon_type_t * real_type;
180 oberon_type_t * longreal_type;
181 oberon_type_t * char_type;
182 oberon_type_t * string_type;
183 oberon_type_t * set_type;
185 oberon_module_t * system_module;
186 oberon_type_t * system_byte_type;
187 oberon_type_t * system_ptr_type;
189 oberon_module_t * module_list;
190 ModuleImportCallback import_module;
191 gen_context_t * gen_context;
192 };
194 enum oberon_mode_kind
196 MODE_VAR,
197 MODE_INTEGER,
198 MODE_BOOLEAN,
199 MODE_CALL,
200 MODE_INDEX,
201 MODE_FIELD,
202 MODE_DEREF,
203 MODE_NIL,
204 MODE_NEW,
205 MODE_REAL,
206 MODE_CHAR,
207 MODE_STRING,
208 MODE_TYPE,
209 MODE_SET,
210 MODE_LEN,
211 MODE_SYSBYTE,
212 MODE_AS
213 };
215 enum oberon_operator_kind
217 OP_UNARY_MINUS,
218 OP_LOGIC_NOT,
219 OP_ABS,
220 OP_CAP,
221 OP_ENTIER,
223 OP_ADD,
224 OP_SUB,
225 OP_MUL,
226 OP_DIV,
227 OP_MOD,
228 OP_LOGIC_AND,
229 OP_LOGIC_OR,
231 OP_EQ,
232 OP_NEQ,
233 OP_LSS,
234 OP_LEQ,
235 OP_GRT,
236 OP_GEQ,
238 OP_CAST,
239 OP_HARDCAST,
240 OP_IS,
242 OP_RANGE,
243 OP_UNION,
244 OP_INTERSECTION,
245 OP_DIFFERENCE,
246 OP_SYM_DIFFERENCE,
247 OP_COMPLEMENTATION,
248 OP_IN,
250 OP_ASH,
251 OP_LSH,
252 OP_ROT
253 };
255 struct oberon_item_t
257 bool is_item; // == 1
258 oberon_type_t * result;
259 oberon_expr_t * next;
260 bool read_only;
262 enum oberon_mode_kind mode;
263 long integer;
264 double real;
265 char * string;
266 oberon_object_t * var;
268 oberon_item_t * parent;
270 int num_args;
271 oberon_expr_t * args;
272 };
274 struct oberon_oper_t
276 bool is_item; // == 0
277 oberon_type_t * result;
278 oberon_expr_t * next;
279 bool read_only;
281 enum oberon_operator_kind op;
282 oberon_expr_t * left;
283 oberon_expr_t * right;
284 };
286 union oberon_expr_t
288 struct {
289 bool is_item;
290 oberon_type_t * result;
291 oberon_expr_t * next;
292 bool read_only;
293 };
295 oberon_item_t item;
296 oberon_oper_t oper;
297 };
299 extern oberon_context_t *
300 oberon_create_context(ModuleImportCallback import_module);
302 extern void
303 oberon_destroy_context(oberon_context_t * ctx);
305 extern oberon_module_t *
306 oberon_compile_module(oberon_context_t * ctx, oberon_scanner_t * s);
308 #endif // OBERON_INTERNALS_H