DEADSOFTWARE

Добавлены функции ASH и ODD, к другим добавлена свёртка констант
[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;
61 int num_decl;
62 oberon_type_t * base;
63 oberon_object_t * decl;
64 oberon_scope_t * scope;
66 bool sysproc;
67 GenerateFuncCallback genfunc;
68 GenerateProcCallback genproc;
70 oberon_module_t * module;
72 int recursive;
73 int initialized;
74 gen_type_t * gen_type;
75 };
77 enum oberon_object_kind
78 {
79 OBERON_CLASS_VAR,
80 OBERON_CLASS_TYPE,
81 OBERON_CLASS_PROC,
82 OBERON_CLASS_PARAM,
83 OBERON_CLASS_VAR_PARAM,
84 OBERON_CLASS_CONST,
85 OBERON_CLASS_FIELD,
86 OBERON_CLASS_MODULE
87 };
89 struct oberon_object_t
90 {
91 char * name;
92 enum oberon_object_kind class;
93 int export;
94 int read_only;
96 int local;
97 int linked;
98 int initialized;
100 oberon_object_t * parent;
101 oberon_type_t * parent_type;
103 oberon_scope_t * scope; // for proc
104 int has_return; // for proc
106 oberon_type_t * type;
107 oberon_item_t * value;
108 oberon_object_t * next;
110 oberon_module_t * module;
112 gen_var_t * gen_var;
113 gen_proc_t * gen_proc;
114 };
116 struct oberon_module_t
118 char * name;
119 int ready;
121 oberon_scope_t * decl;
123 oberon_module_t * next;
125 gen_module_t * gen_mod;
126 };
128 typedef const char * (*ModuleImportCallback)(const char * name);
130 struct oberon_context_t
132 /*** SCANER DATA ***/
133 const char * code;
134 int code_index;
136 char c;
137 int token;
138 char * string;
139 int64_t integer;
140 double real;
141 bool longmode;
142 /*** END SCANER DATA ***/
144 /*** PARSER DATA ***/
145 oberon_scope_t * decl;
146 oberon_module_t * mod;
147 /*** END PARSER DATA ***/
149 oberon_type_t * notype_type;
150 oberon_type_t * nil_type;
151 oberon_type_t * bool_type;
152 oberon_type_t * byte_type;
153 oberon_type_t * shortint_type;
154 oberon_type_t * int_type;
155 oberon_type_t * longint_type;
156 oberon_type_t * real_type;
157 oberon_type_t * longreal_type;
158 oberon_type_t * char_type;
159 oberon_type_t * string_type;
160 oberon_type_t * set_type;
162 oberon_scope_t * world_scope;
163 oberon_module_t * module_list;
164 ModuleImportCallback import_module;
165 gen_context_t * gen_context;
166 };
168 enum oberon_mode_kind
170 MODE_VAR,
171 MODE_INTEGER,
172 MODE_BOOLEAN,
173 MODE_CALL,
174 MODE_INDEX,
175 MODE_FIELD,
176 MODE_DEREF,
177 MODE_NIL,
178 MODE_NEW,
179 MODE_REAL,
180 MODE_CHAR,
181 MODE_STRING,
182 MODE_TYPE,
183 MODE_SET
184 };
186 enum oberon_operator_kind
188 OP_UNARY_MINUS,
189 OP_LOGIC_NOT,
190 OP_ABS,
191 OP_CAP,
193 OP_ADD,
194 OP_SUB,
195 OP_MUL,
196 OP_DIV,
197 OP_MOD,
198 OP_LOGIC_AND,
199 OP_LOGIC_OR,
201 OP_EQ,
202 OP_NEQ,
203 OP_LSS,
204 OP_LEQ,
205 OP_GRT,
206 OP_GEQ,
208 OP_CAST,
209 OP_IS,
211 OP_RANGE,
212 OP_UNION,
213 OP_INTERSECTION,
214 OP_DIFFERENCE,
215 OP_SYM_DIFFERENCE,
216 OP_COMPLEMENTATION,
217 OP_IN,
219 OP_ASH
220 };
222 struct oberon_item_t
224 bool is_item; // == 1
225 oberon_type_t * result;
226 oberon_expr_t * next;
227 bool read_only;
229 enum oberon_mode_kind mode;
230 long integer;
231 double real;
232 char * string;
233 oberon_object_t * var;
235 oberon_item_t * parent;
237 int num_args;
238 oberon_expr_t * args;
239 };
241 struct oberon_oper_t
243 bool is_item; // == 0
244 oberon_type_t * result;
245 oberon_expr_t * next;
246 bool read_only;
248 enum oberon_operator_kind op;
249 oberon_expr_t * left;
250 oberon_expr_t * right;
251 };
253 union oberon_expr_t
255 struct {
256 bool is_item;
257 oberon_type_t * result;
258 oberon_expr_t * next;
259 bool read_only;
260 };
262 oberon_item_t item;
263 oberon_oper_t oper;
264 };
266 #endif // OBERON_INTERNALS_H