DEADSOFTWARE

Добавлен модуль SYSTEM и тип SYSTEM.TYPE
[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 };
54 typedef oberon_expr_t * (*GenerateFuncCallback)(oberon_context_t *, int, oberon_expr_t *);
55 typedef void (*GenerateProcCallback)(oberon_context_t *, int, oberon_expr_t *);
57 struct oberon_type_t
58 {
59 enum oberon_type_kind class;
60 int size;
61 oberon_type_t * shorter;
62 oberon_type_t * longer;
64 int num_decl;
65 oberon_type_t * base;
66 oberon_object_t * decl;
67 oberon_scope_t * scope;
69 bool sysproc;
70 GenerateFuncCallback genfunc;
71 GenerateProcCallback genproc;
73 oberon_module_t * module;
75 int recursive;
76 int initialized;
77 gen_type_t * gen_type;
78 };
80 enum oberon_object_kind
81 {
82 OBERON_CLASS_VAR,
83 OBERON_CLASS_TYPE,
84 OBERON_CLASS_PROC,
85 OBERON_CLASS_PARAM,
86 OBERON_CLASS_VAR_PARAM,
87 OBERON_CLASS_CONST,
88 OBERON_CLASS_FIELD,
89 OBERON_CLASS_MODULE
90 };
92 struct oberon_object_t
93 {
94 char * name;
95 enum oberon_object_kind class;
96 int export;
97 int read_only;
99 int local;
100 int linked;
101 int initialized;
103 oberon_object_t * parent;
104 oberon_type_t * parent_type;
106 oberon_scope_t * scope; // for proc
107 int has_return; // for proc
109 oberon_type_t * type;
110 oberon_item_t * value;
111 oberon_object_t * next;
113 oberon_module_t * module;
115 gen_var_t * gen_var;
116 gen_proc_t * gen_proc;
117 };
119 struct oberon_module_t
121 char * name;
122 bool ready;
123 bool intrinsic;
125 oberon_scope_t * decl;
127 oberon_module_t * next;
129 gen_module_t * gen_mod;
130 };
132 typedef const char * (*ModuleImportCallback)(const char * name);
134 struct oberon_context_t
136 /*** SCANER DATA ***/
137 const char * code;
138 int code_index;
140 char c;
141 int token;
142 char * string;
143 int64_t integer;
144 double real;
145 bool longmode;
146 /*** END SCANER DATA ***/
148 /*** PARSER DATA ***/
149 oberon_scope_t * decl;
150 oberon_module_t * mod;
151 /*** END PARSER DATA ***/
153 oberon_scope_t * world_scope;
154 oberon_type_t * notype_type;
155 oberon_type_t * nil_type;
156 oberon_type_t * bool_type;
157 oberon_type_t * byte_type;
158 oberon_type_t * shortint_type;
159 oberon_type_t * int_type;
160 oberon_type_t * longint_type;
161 oberon_type_t * real_type;
162 oberon_type_t * longreal_type;
163 oberon_type_t * char_type;
164 oberon_type_t * string_type;
165 oberon_type_t * set_type;
167 oberon_module_t * system_module;
168 oberon_type_t * system_byte_type;
170 oberon_module_t * module_list;
171 ModuleImportCallback import_module;
172 gen_context_t * gen_context;
173 };
175 enum oberon_mode_kind
177 MODE_VAR,
178 MODE_INTEGER,
179 MODE_BOOLEAN,
180 MODE_CALL,
181 MODE_INDEX,
182 MODE_FIELD,
183 MODE_DEREF,
184 MODE_NIL,
185 MODE_NEW,
186 MODE_REAL,
187 MODE_CHAR,
188 MODE_STRING,
189 MODE_TYPE,
190 MODE_SET,
191 MODE_LEN
192 };
194 enum oberon_operator_kind
196 OP_UNARY_MINUS,
197 OP_LOGIC_NOT,
198 OP_ABS,
199 OP_CAP,
200 OP_ENTIER,
202 OP_ADD,
203 OP_SUB,
204 OP_MUL,
205 OP_DIV,
206 OP_MOD,
207 OP_LOGIC_AND,
208 OP_LOGIC_OR,
210 OP_EQ,
211 OP_NEQ,
212 OP_LSS,
213 OP_LEQ,
214 OP_GRT,
215 OP_GEQ,
217 OP_CAST,
218 OP_IS,
220 OP_RANGE,
221 OP_UNION,
222 OP_INTERSECTION,
223 OP_DIFFERENCE,
224 OP_SYM_DIFFERENCE,
225 OP_COMPLEMENTATION,
226 OP_IN,
228 OP_ASH
229 };
231 struct oberon_item_t
233 bool is_item; // == 1
234 oberon_type_t * result;
235 oberon_expr_t * next;
236 bool read_only;
238 enum oberon_mode_kind mode;
239 long integer;
240 double real;
241 char * string;
242 oberon_object_t * var;
244 oberon_item_t * parent;
246 int num_args;
247 oberon_expr_t * args;
248 };
250 struct oberon_oper_t
252 bool is_item; // == 0
253 oberon_type_t * result;
254 oberon_expr_t * next;
255 bool read_only;
257 enum oberon_operator_kind op;
258 oberon_expr_t * left;
259 oberon_expr_t * right;
260 };
262 union oberon_expr_t
264 struct {
265 bool is_item;
266 oberon_type_t * result;
267 oberon_expr_t * next;
268 bool read_only;
269 };
271 oberon_item_t item;
272 oberon_oper_t oper;
273 };
275 #endif // OBERON_INTERNALS_H