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 };
53 typedef oberon_expr_t * (*GenerateFuncCallback)(oberon_context_t *, int, oberon_expr_t *);
54 typedef void (*GenerateProcCallback)(oberon_context_t *, int, oberon_expr_t *);
56 struct oberon_type_t
57 {
58 enum oberon_type_kind class;
59 int size;
60 oberon_type_t * shorter;
61 oberon_type_t * longer;
63 int num_decl;
64 oberon_type_t * base;
65 oberon_object_t * decl;
66 oberon_scope_t * scope;
68 bool sysproc;
69 GenerateFuncCallback genfunc;
70 GenerateProcCallback genproc;
72 oberon_module_t * module;
74 int recursive;
75 int initialized;
76 gen_type_t * gen_type;
77 };
79 enum oberon_object_kind
80 {
81 OBERON_CLASS_VAR,
82 OBERON_CLASS_TYPE,
83 OBERON_CLASS_PROC,
84 OBERON_CLASS_PARAM,
85 OBERON_CLASS_VAR_PARAM,
86 OBERON_CLASS_CONST,
87 OBERON_CLASS_FIELD,
88 OBERON_CLASS_MODULE
89 };
91 struct oberon_object_t
92 {
93 char * name;
94 enum oberon_object_kind class;
95 int export;
96 int read_only;
98 int local;
99 int linked;
100 int initialized;
102 oberon_object_t * parent;
103 oberon_type_t * parent_type;
105 oberon_scope_t * scope; // for proc
106 int has_return; // for proc
108 oberon_type_t * type;
109 oberon_item_t * value;
110 oberon_object_t * next;
112 oberon_module_t * module;
114 gen_var_t * gen_var;
115 gen_proc_t * gen_proc;
116 };
118 struct oberon_module_t
120 char * name;
121 int ready;
123 oberon_scope_t * decl;
125 oberon_module_t * next;
127 gen_module_t * gen_mod;
128 };
130 typedef const char * (*ModuleImportCallback)(const char * name);
132 struct oberon_context_t
134 /*** SCANER DATA ***/
135 const char * code;
136 int code_index;
138 char c;
139 int token;
140 char * string;
141 int64_t integer;
142 double real;
143 bool longmode;
144 /*** END SCANER DATA ***/
146 /*** PARSER DATA ***/
147 oberon_scope_t * decl;
148 oberon_module_t * mod;
149 /*** END PARSER DATA ***/
151 oberon_type_t * notype_type;
152 oberon_type_t * nil_type;
153 oberon_type_t * bool_type;
154 oberon_type_t * byte_type;
155 oberon_type_t * shortint_type;
156 oberon_type_t * int_type;
157 oberon_type_t * longint_type;
158 oberon_type_t * real_type;
159 oberon_type_t * longreal_type;
160 oberon_type_t * char_type;
161 oberon_type_t * string_type;
162 oberon_type_t * set_type;
164 oberon_scope_t * world_scope;
165 oberon_module_t * module_list;
166 ModuleImportCallback import_module;
167 gen_context_t * gen_context;
168 };
170 enum oberon_mode_kind
172 MODE_VAR,
173 MODE_INTEGER,
174 MODE_BOOLEAN,
175 MODE_CALL,
176 MODE_INDEX,
177 MODE_FIELD,
178 MODE_DEREF,
179 MODE_NIL,
180 MODE_NEW,
181 MODE_REAL,
182 MODE_CHAR,
183 MODE_STRING,
184 MODE_TYPE,
185 MODE_SET,
186 MODE_LEN
187 };
189 enum oberon_operator_kind
191 OP_UNARY_MINUS,
192 OP_LOGIC_NOT,
193 OP_ABS,
194 OP_CAP,
195 OP_ENTIER,
197 OP_ADD,
198 OP_SUB,
199 OP_MUL,
200 OP_DIV,
201 OP_MOD,
202 OP_LOGIC_AND,
203 OP_LOGIC_OR,
205 OP_EQ,
206 OP_NEQ,
207 OP_LSS,
208 OP_LEQ,
209 OP_GRT,
210 OP_GEQ,
212 OP_CAST,
213 OP_IS,
215 OP_RANGE,
216 OP_UNION,
217 OP_INTERSECTION,
218 OP_DIFFERENCE,
219 OP_SYM_DIFFERENCE,
220 OP_COMPLEMENTATION,
221 OP_IN,
223 OP_ASH
224 };
226 struct oberon_item_t
228 bool is_item; // == 1
229 oberon_type_t * result;
230 oberon_expr_t * next;
231 bool read_only;
233 enum oberon_mode_kind mode;
234 long integer;
235 double real;
236 char * string;
237 oberon_object_t * var;
239 oberon_item_t * parent;
241 int num_args;
242 oberon_expr_t * args;
243 };
245 struct oberon_oper_t
247 bool is_item; // == 0
248 oberon_type_t * result;
249 oberon_expr_t * next;
250 bool read_only;
252 enum oberon_operator_kind op;
253 oberon_expr_t * left;
254 oberon_expr_t * right;
255 };
257 union oberon_expr_t
259 struct {
260 bool is_item;
261 oberon_type_t * result;
262 oberon_expr_t * next;
263 bool read_only;
264 };
266 oberon_item_t item;
267 oberon_oper_t oper;
268 };
270 #endif // OBERON_INTERNALS_H